当前位置: 首页>>代码示例>>Java>>正文


Java UniqueConstraint类代码示例

本文整理汇总了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());
}
 
开发者ID:lbitonti,项目名称:liquibase-hana,代码行数:18,代码来源:AddColumnGeneratorHanaDBTest.java

示例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());
}
 
开发者ID:lbitonti,项目名称:liquibase-hana,代码行数:18,代码来源:CreateTableGeneratorHanaDBTest.java

示例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());
}
 
开发者ID:lbitonti,项目名称:liquibase-hana,代码行数:20,代码来源:CreateTableGeneratorHanaDBTest.java


注:本文中的liquibase.statement.UniqueConstraint类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。