本文整理汇总了Java中liquibase.statement.UniqueConstraint类的典型用法代码示例。如果您正苦于以下问题:Java UniqueConstraint类的具体用法?Java UniqueConstraint怎么用?Java UniqueConstraint使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UniqueConstraint类属于liquibase.statement包,在下文中一共展示了UniqueConstraint类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAddBooleanColumnWithDefaultValueAndUniqueConstraint
import liquibase.statement.UniqueConstraint; //导入依赖的package包/类
@Test
public void testAddBooleanColumnWithDefaultValueAndUniqueConstraint() throws Exception {
super.isValid();
UniqueConstraint uniqueConstraint = new UniqueConstraint();
uniqueConstraint.setConstraintName("COLUMN1_UNIQUE");
uniqueConstraint.addColumns("column_name");
AddColumnStatement addDefaultColumn =
new AddColumnStatement(null, null, "table_name", "column_name", "BOOLEAN", new Boolean(false), uniqueConstraint);
SqlGeneratorChain sqlGeneratorChain = new MockSqlGeneratorChain();
assertFalse(generatorUnderTest.validate(addDefaultColumn, hanadb, new MockSqlGeneratorChain()).hasErrors());
Sql[] generatedSql = generatorUnderTest.generateSql(addDefaultColumn, hanadb, sqlGeneratorChain);
assertTrue(generatedSql.length == 1);
assertEquals("ALTER TABLE \"table_name\" ADD (\"column_name\" SMALLINT DEFAULT 0)", generatedSql[0].toSql());
}
示例2: testWithColumnUniqueConstraint
import liquibase.statement.UniqueConstraint; //导入依赖的package包/类
@Test
public void testWithColumnUniqueConstraint() {
Database database = new HanaDBDatabase();
CreateTableStatement statement = new CreateTableStatement(null, null, "TABLE_NAME");
UniqueConstraint uniqueConstraint = new UniqueConstraint();
uniqueConstraint.setConstraintName("COLUMN1_UNIQUE");
uniqueConstraint.addColumns("COLUMN1_NAME");
statement.addColumn("COLUMN1_NAME",
DataTypeFactory.getInstance().fromDescription("int",database));
statement.addColumnConstraint(uniqueConstraint);
assertEquals("CREATE TABLE \"TABLE_NAME\" (\"COLUMN1_NAME\" INTEGER, UNIQUE (\"COLUMN1_NAME\"))",
this.generatorUnderTest.generateSql(statement, database, null)[0].toSql());
}
示例3: testWith2ColumnsUniqueConstraint
import liquibase.statement.UniqueConstraint; //导入依赖的package包/类
@Test
public void testWith2ColumnsUniqueConstraint() {
Database database = new HanaDBDatabase();
CreateTableStatement statement = new CreateTableStatement(null, null, "TABLE_NAME");
UniqueConstraint uniqueConstraint = new UniqueConstraint();
uniqueConstraint.setConstraintName("COLUMN1_UNIQUE");
uniqueConstraint.addColumns("COLUMN1_NAME", "COLUMN2_NAME");
statement.addColumn("COLUMN1_NAME",
DataTypeFactory.getInstance().fromDescription("int",database));
statement.addColumn("COLUMN2_NAME",
DataTypeFactory.getInstance().fromDescription("varchar(100)",database));
statement.addColumnConstraint(uniqueConstraint);
assertEquals("CREATE TABLE \"TABLE_NAME\" (\"COLUMN1_NAME\" INTEGER, \"COLUMN2_NAME\" NVARCHAR(100), UNIQUE (\"COLUMN1_NAME\", \"COLUMN2_NAME\"))",
this.generatorUnderTest.generateSql(statement, database, null)[0].toSql());
}