本文整理汇总了Java中liquibase.statement.AutoIncrementConstraint类的典型用法代码示例。如果您正苦于以下问题:Java AutoIncrementConstraint类的具体用法?Java AutoIncrementConstraint怎么用?Java AutoIncrementConstraint使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AutoIncrementConstraint类属于liquibase.statement包,在下文中一共展示了AutoIncrementConstraint类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateSql
import liquibase.statement.AutoIncrementConstraint; //导入依赖的package包/类
public Sql[] generateSql(AddColumnStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
String alterTable = "ALTER TABLE " + database.escapeTableName(statement.getSchemaName(), statement.getTableName()) + " ADD " + database.escapeColumnName(statement.getSchemaName(), statement.getTableName(), statement.getColumnName()) + " " + TypeConverterFactory.getInstance().findTypeConverter(database).getDataType(statement.getColumnType(), statement.isAutoIncrement());
if (statement.isAutoIncrement() && database.supportsAutoIncrement()) {
AutoIncrementConstraint autoIncrementConstraint = statement.getAutoIncrementConstraint();
alterTable += " " + database.getAutoIncrementClause(autoIncrementConstraint.getStartWith(), autoIncrementConstraint.getIncrementBy());
}
if (!statement.isNullable()) {
alterTable += " NOT NULL";
} else {
if (database instanceof SybaseDatabase || database instanceof SybaseASADatabase) {
alterTable += " NULL";
}
}
if (statement.isPrimaryKey()) {
alterTable += " PRIMARY KEY";
}
if (statement.isUnique()) {
alterTable += " UNIQUE ";
}
alterTable += getDefaultClause(statement, database);
List<Sql> returnSql = new ArrayList<Sql>();
returnSql.add(new UnparsedSql(alterTable, new Column()
.setTable(new Table(statement.getTableName()).setSchema(statement.getSchemaName()))
.setName(statement.getColumnName())));
addForeignKeyStatements(statement, database, returnSql);
return returnSql.toArray(new Sql[returnSql.size()]);
}
示例2: isValid
import liquibase.statement.AutoIncrementConstraint; //导入依赖的package包/类
@Override
public void isValid() throws Exception {
super.isValid();
AddColumnStatement addPKColumn = new AddColumnStatement(null, null, "table_name", "column_name", "column_type", null, new PrimaryKeyConstraint("pk_name"));
assertFalse(generatorUnderTest.validate(addPKColumn, new HanaDBDatabase(), new MockSqlGeneratorChain()).hasErrors());
assertTrue(generatorUnderTest.validate(addPKColumn, new H2Database(), new MockSqlGeneratorChain()).getErrorMessages().contains("Cannot add a primary key column"));
// "catalog_name", "schema_name", "table_name", "column_name", "column_type" ...
assertTrue(generatorUnderTest.validate(new AddColumnStatement(null, null, null, null, null, null, new AutoIncrementConstraint()), new MySQLDatabase(), new MockSqlGeneratorChain()).getErrorMessages().contains("Cannot add a non-primary key identity column"));
}
示例3: generateSql
import liquibase.statement.AutoIncrementConstraint; //导入依赖的package包/类
@Override
public Sql[] generateSql(AddColumnStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
String alterTable = "ALTER TABLE " + database.escapeTableName(statement.getSchemaName(), statement.getTableName()) + " ADD " + database.escapeColumnName(statement.getSchemaName(), statement.getTableName(), statement.getColumnName()) + " " + TypeConverterFactory.getInstance().findTypeConverter(database).getDataType(statement.getColumnType(), statement.isAutoIncrement());
alterTable += getDefaultClause(statement, database);
if (primaryKeyBeforeNotNull(database)) {
if (statement.isPrimaryKey()) {
alterTable += " PRIMARY KEY";
}
}
if (statement.isAutoIncrement()) {
AutoIncrementConstraint autoIncrementConstraint = statement.getAutoIncrementConstraint();
alterTable += " " + database.getAutoIncrementClause(autoIncrementConstraint.getStartWith(), autoIncrementConstraint.getIncrementBy());
}
if (!statement.isNullable()) {
alterTable += " NOT NULL";
} else if (database instanceof SybaseDatabase || database instanceof SybaseASADatabase) {
alterTable += " NULL";
}
if (!primaryKeyBeforeNotNull(database)) {
if (statement.isPrimaryKey()) {
alterTable += " PRIMARY KEY";
}
}
if (statement.isUnique()) {
alterTable += " UNIQUE ";
}
List<Sql> returnSql = new ArrayList<Sql>();
returnSql.add(new UnparsedSql(alterTable, new Column()
.setTable(new Table(statement.getTableName()).setSchema(statement.getSchemaName()))
.setName(statement.getColumnName())));
addForeignKeyStatements(statement, database, returnSql);
return returnSql.toArray(new Sql[returnSql.size()]);
}
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:42,代码来源:AddColumnGeneratorDefaultClauseBeforeNotNull.java
示例4: generateSql
import liquibase.statement.AutoIncrementConstraint; //导入依赖的package包/类
@Override
public Sql[] generateSql(AddColumnStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
if (!supports(statement, database)) {
return sqlGeneratorChain.generateSql(statement, database);
}
String catalogName = statement.getCatalogName();
String schemaName = statement.getSchemaName();
if (schemaName == null) {
schemaName = database.getDefaultSchemaName();
}
String tableName = statement.getTableName();
String columnName = statement.getColumnName();
String columnType = statement.getColumnType();
String alterTable = "ALTER TABLE " + database.escapeTableName(catalogName, schemaName, tableName) +
" ADD (" + database.escapeColumnName(catalogName, schemaName, tableName, columnName) +
" " + DataTypeFactory.getInstance().fromDescription(columnType +
(statement.isAutoIncrement() ? "{autoIncrement:true}" : ""), database).toDatabaseDataType(database);
if (statement.isAutoIncrement() && database.supportsAutoIncrement()) {
AutoIncrementConstraint autoIncrementConstraint = statement.getAutoIncrementConstraint();
alterTable += " " + database.getAutoIncrementClause(autoIncrementConstraint.getStartWith(), autoIncrementConstraint.getIncrementBy());
}
if (!statement.isNullable()) {
alterTable += " NOT NULL";
}
if (statement.isPrimaryKey()) {
alterTable += " PRIMARY KEY";
}
// "ALTER TABLE ADD COLUMN ..." does not support unique constraints in Hana
// if (statement.isUnique()) {
// alterTable += " UNIQUE ";
// }
alterTable += getDefaultClause(statement, database);
if ( database instanceof HanaDBDatabase ) {
alterTable += ")";
}
List<Sql> returnSql = new ArrayList<Sql>();
// drop both incoming and outgoing foreign key constraints before adding column
Set<ForeignKeyConstraintMetaData> constraints = SqlGeneratorHelperHanaDB.getAllForeignKeyConstraints(database, schemaName, tableName);
SqlGeneratorHelperHanaDB.addDropForeignKeyConstraintsStatements(returnSql, database, constraints);
returnSql.add(new UnparsedSql(alterTable, getAffectedColumn(statement)));
// recreate foreign key constraints
SqlGeneratorHelperHanaDB.addCreateForeignKeyConstraintsStatements(returnSql, database, constraints);
addForeignKeyStatements(statement, database, returnSql);
return returnSql.toArray(new Sql[returnSql.size()]);
}