[jOOQ/jOOQ#11269] Add CreateTableConstraintStep.primaryKey(), unique(), check() convenience methods
This commit is contained in:
parent
c5d026ce2c
commit
4fa4e13807
@ -37,8 +37,32 @@
|
||||
*/
|
||||
package org.jooq;
|
||||
|
||||
import org.jooq.impl.DSL;
|
||||
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
// ...
|
||||
// ...
|
||||
// ...
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.CUBRID;
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.DERBY;
|
||||
import static org.jooq.SQLDialect.FIREBIRD;
|
||||
import static org.jooq.SQLDialect.H2;
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.HSQLDB;
|
||||
// ...
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.MARIADB;
|
||||
import static org.jooq.SQLDialect.MYSQL;
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.POSTGRES;
|
||||
import static org.jooq.SQLDialect.SQLITE;
|
||||
// ...
|
||||
// ...
|
||||
// ...
|
||||
// ...
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@ -87,4 +111,81 @@ public interface CreateTableConstraintStep extends CreateTableIndexStep {
|
||||
@NotNull
|
||||
@Support
|
||||
CreateTableConstraintStep constraints(Collection<? extends Constraint> constraints);
|
||||
|
||||
/**
|
||||
* Convenience method to add an unnamed (system named)
|
||||
* <code>PRIMARY KEY</code> constraint to the table.
|
||||
* <p>
|
||||
* This does the same as adding {@link DSL#primaryKey(String...)} via
|
||||
* {@link #constraint(Constraint)} explicitly.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
CreateTableConstraintStep primaryKey(String... fields);
|
||||
|
||||
/**
|
||||
* Convenience method to add an unnamed (system named)
|
||||
* <code>PRIMARY KEY</code> constraint to the table.
|
||||
* <p>
|
||||
* This does the same as adding {@link DSL#primaryKey(Name...)} via
|
||||
* {@link #constraint(Constraint)} explicitly.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
CreateTableConstraintStep primaryKey(Name... fields);
|
||||
|
||||
/**
|
||||
* Convenience method to add an unnamed (system named)
|
||||
* <code>PRIMARY KEY</code> constraint to the table.
|
||||
* <p>
|
||||
* This does the same as adding {@link DSL#primaryKey(Field...)} via
|
||||
* {@link #constraint(Constraint)} explicitly.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
CreateTableConstraintStep primaryKey(Field<?>... fields);
|
||||
|
||||
/**
|
||||
* Convenience method to add an unnamed (system named) <code>UNIQUE</code>
|
||||
* constraint to the table.
|
||||
* <p>
|
||||
* This does the same as adding {@link DSL#unique(String...)} via
|
||||
* {@link #constraint(Constraint)} explicitly.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
CreateTableConstraintStep unique(String... fields);
|
||||
|
||||
/**
|
||||
* Convenience method to add an unnamed (system named) <code>UNIQUE</code>
|
||||
* constraint to the table.
|
||||
* <p>
|
||||
* This does the same as adding {@link DSL#unique(Name...)} via
|
||||
* {@link #constraint(Constraint)} explicitly.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
CreateTableConstraintStep unique(Name... fields);
|
||||
|
||||
/**
|
||||
* Convenience method to add an unnamed (system named) <code>UNIQUE</code>
|
||||
* constraint to the table.
|
||||
* <p>
|
||||
* This does the same as adding {@link DSL#unique(Field...)} via
|
||||
* {@link #constraint(Constraint)} explicitly.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
CreateTableConstraintStep unique(Field<?>... fields);
|
||||
|
||||
/**
|
||||
* Convenience method to add an unnamed (system named) <code>CHECK</code>
|
||||
* constraint to the table.
|
||||
* <p>
|
||||
* This does the same as adding {@link DSL#check(Condition)} via
|
||||
* {@link #constraint(Constraint)} explicitly.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
CreateTableConstraintStep check(Condition condition);
|
||||
}
|
||||
|
||||
@ -931,12 +931,10 @@ abstract class AbstractDMLQuery<R extends Record> extends AbstractRowCountQuery
|
||||
if (returning.isEmpty()) {
|
||||
return super.execute(ctx, listener);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Column stores don't seem support fetching generated keys
|
||||
else if (NO_SUPPORT_FETCHING_KEYS.contains(ctx.dialect())) {
|
||||
return super.execute(ctx, listener);
|
||||
}
|
||||
else {
|
||||
int result = 1;
|
||||
ResultSet rs;
|
||||
|
||||
@ -114,10 +114,12 @@ import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.jooq.Comment;
|
||||
import org.jooq.Condition;
|
||||
import org.jooq.Configuration;
|
||||
import org.jooq.Constraint;
|
||||
import org.jooq.Context;
|
||||
import org.jooq.CreateTableColumnStep;
|
||||
import org.jooq.CreateTableConstraintStep;
|
||||
import org.jooq.CreateTableWithDataStep;
|
||||
import org.jooq.DataType;
|
||||
import org.jooq.EnumType;
|
||||
@ -134,6 +136,8 @@ import org.jooq.Select;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableOptions.OnCommit;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
@ -286,6 +290,41 @@ final class CreateTableImpl extends AbstractRowCountQuery implements
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final CreateTableConstraintStep primaryKey(String... fields) {
|
||||
return constraint(DSL.primaryKey(fields));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final CreateTableConstraintStep primaryKey(Name... fields) {
|
||||
return constraint(DSL.primaryKey(fields));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final CreateTableConstraintStep primaryKey(Field<?>... fields) {
|
||||
return constraint(DSL.primaryKey(fields));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final CreateTableConstraintStep unique(String... fields) {
|
||||
return constraint(DSL.unique(fields));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final CreateTableConstraintStep unique(Name... fields) {
|
||||
return constraint(DSL.unique(fields));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final CreateTableConstraintStep unique(Field<?>... fields) {
|
||||
return constraint(DSL.unique(fields));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final CreateTableConstraintStep check(Condition condition) {
|
||||
return constraint(DSL.check(condition));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final CreateTableImpl index(Index i) {
|
||||
return indexes(Arrays.asList(i));
|
||||
|
||||
@ -103,13 +103,13 @@ extends
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
case CUBRID:
|
||||
case DERBY:
|
||||
case FIREBIRD:
|
||||
case H2:
|
||||
case HSQLDB:
|
||||
case IGNITE:
|
||||
case MARIADB:
|
||||
case MYSQL:
|
||||
case POSTGRES:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user