• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java AddColumnStatement类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中liquibase.statement.core.AddColumnStatement的典型用法代码示例。如果您正苦于以下问题:Java AddColumnStatement类的具体用法?Java AddColumnStatement怎么用?Java AddColumnStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AddColumnStatement类属于liquibase.statement.core包,在下文中一共展示了AddColumnStatement类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: validate

import liquibase.statement.core.AddColumnStatement; //导入依赖的package包/类
public ValidationErrors validate(AddColumnStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
    ValidationErrors validationErrors = new ValidationErrors();

    validationErrors.checkRequiredField("columnName", statement.getColumnName());
    validationErrors.checkRequiredField("columnType", statement.getColumnType());
    validationErrors.checkRequiredField("tableName", statement.getTableName());

    if (statement.isPrimaryKey() && (database instanceof CacheDatabase
            || database instanceof H2Database
            || database instanceof DB2Database
            || database instanceof DerbyDatabase
            || database instanceof SQLiteDatabase)) {
        validationErrors.addError("Cannot add a primary key column");
    }

    // TODO HsqlDatabase autoincrement on non primary key? other databases?
    if (database instanceof MySQLDatabase && statement.isAutoIncrement() && !statement.isPrimaryKey()) {
        validationErrors.addError("Cannot add a non-primary key identity column");
    }
    return validationErrors;
}
 
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:22,代码来源:AddColumnGenerator.java


示例2: addForeignKeyStatements

import liquibase.statement.core.AddColumnStatement; //导入依赖的package包/类
protected void addForeignKeyStatements(AddColumnStatement statement, Database database, List<Sql> returnSql) {
    for (ColumnConstraint constraint : statement.getConstraints()) {
        if (constraint instanceof ForeignKeyConstraint) {
            ForeignKeyConstraint fkConstraint = (ForeignKeyConstraint) constraint;
            Matcher referencesMatcher = Pattern.compile("([\\w\\._]+)\\(([\\w_]+)\\)").matcher(fkConstraint.getReferences());
            if (!referencesMatcher.matches()) {
                throw new UnexpectedLiquibaseException("Don't know how to find table and column names from " + fkConstraint.getReferences());
            }
            String refSchemaName = null;
            String refTableName = referencesMatcher.group(1);
            if (refTableName.indexOf(".") > 0) {
                refSchemaName = refTableName.split("\\.")[0];
                refTableName = refTableName.split("\\.")[1];
            }
            String refColName = referencesMatcher.group(2);

            AddForeignKeyConstraintStatement addForeignKeyConstraintStatement = new AddForeignKeyConstraintStatement(fkConstraint.getForeignKeyName(), statement.getSchemaName(), statement.getTableName(), statement.getColumnName(), refSchemaName, refTableName, refColName);
            returnSql.addAll(Arrays.asList(SqlGeneratorFactory.getInstance().generateSql(addForeignKeyConstraintStatement, database)));
        }
    }
}
 
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:22,代码来源:AddColumnGenerator.java


示例3: generateSql

import liquibase.statement.core.AddColumnStatement; //导入依赖的package包/类
@Override
public Sql[] generateSql(final CreateTableStatement statement, final Database database,
      final SqlGeneratorChain sqlGeneratorChain) {
   final List<Sql> list = new ArrayList<Sql>(Arrays.asList(sqlGeneratorChain.generateSql(
         statement, database)));
   for (final Entry<String, LiquibaseDataType> entry : statement.getColumnTypes().entrySet()) {
      if (entry.getValue() instanceof GeometryType) {
         final String columnName = entry.getKey();
         final GeometryType geometryType = (GeometryType) entry.getValue();
         final AddGeometryColumnGeneratorGeoDB generator = new AddGeometryColumnGeneratorGeoDB();
         final AddColumnStatement addColumnStatement = new AddColumnStatement(
               statement.getCatalogName(), statement.getSchemaName(), statement.getTableName(),
               columnName, geometryType.toString(), null);
         @SuppressWarnings("rawtypes")
         final SqlGeneratorChain emptyChain = new SqlGeneratorChain(new TreeSet<SqlGenerator>());
         final Sql[] addGeometryColumnSql = generator.generateSql(addColumnStatement, database,
               emptyChain);
         list.addAll(Arrays.asList(addGeometryColumnSql));
      }
   }
   return list.toArray(new Sql[list.size()]);
}
 
开发者ID:lonnyj,项目名称:liquibase-spatial,代码行数:23,代码来源:CreateSpatialTableGeneratorGeoDB.java


示例4: validate

import liquibase.statement.core.AddColumnStatement; //导入依赖的package包/类
@Override
public ValidationErrors validate(final AddColumnStatement statement,
      final Database database, final SqlGeneratorChain sqlGeneratorChain) {
   final ValidationErrors errors = new ValidationErrors();
   final LiquibaseDataType dataType = DataTypeFactory.getInstance()
         .fromDescription(statement.getColumnType(), database);

   // Ensure that the SRID parameter is provided.
   if (dataType instanceof GeometryType) {
      final GeometryType geometryType = (GeometryType) dataType;
      if (geometryType.getSRID() == null) {
         errors.addError("The SRID parameter is required on the geometry type");
      }
   }
   final ValidationErrors chainErrors = sqlGeneratorChain.validate(
         statement, database);
   if (chainErrors != null) {
      errors.addAll(chainErrors);
   }
   return errors;
}
 
开发者ID:lonnyj,项目名称:liquibase-spatial,代码行数:22,代码来源:AddGeometryColumnGeneratorGeoDB.java


示例5: testGenerateSql

import liquibase.statement.core.AddColumnStatement; //导入依赖的package包/类
@Test(dataProvider = "generateSqlTestData")
public void testGenerateSql(final AddColumnStatement statement, final Database database,
      final Sql[] expected) {
   final AddGeometryColumnGeneratorGeoDB generator = new AddGeometryColumnGeneratorGeoDB();
   final SqlGeneratorChain sqlGeneratorChain = mock(SqlGeneratorChain.class);
   when(sqlGeneratorChain.generateSql(statement, database)).thenReturn(new Sql[0]);
   final Sql[] result = generator.generateSql(statement, database, sqlGeneratorChain);
   assertEquals(result.length, expected.length);
   if (result.length > 0) {
      for (int ii = 0; ii < result.length; ii++) {
         final Sql resultSql = result[ii];
         final Sql expectedSql = expected[ii];
         assertEquals(resultSql.toSql(), expectedSql.toSql());
      }
   }
}
 
开发者ID:lonnyj,项目名称:liquibase-spatial,代码行数:17,代码来源:AddGeometryColumnGeneratorGeoDBTest.java


示例6: generateSqlTestData

import liquibase.statement.core.AddColumnStatement; //导入依赖的package包/类
@DataProvider
public Object[][] generateSqlTestData() {
   final Database database = new H2Database();

   final AddColumnStatement notGeometry = new AddColumnStatement(null, null, null, null,
         "BOOLEAN", null);

   final AddColumnStatement nullSchema = new AddColumnStatement(null, null, "TEST", "COLUMN",
         "Geometry(Point, 4327)", null);
   final Sql nullSchemaExpected = new UnparsedSql("CALL AddGeometryColumn('"
         + database.getDefaultSchemaName() + "', 'TEST', 'COLUMN', 4327, 'Point', 2)");

   final AddColumnStatement complete = new AddColumnStatement(null,
         database.getDefaultSchemaName(), "TEST", "COLUMN", "Geometry(Geometry,4326)", null);
   final Sql completeExpected = new UnparsedSql("CALL AddGeometryColumn('"
         + database.getDefaultSchemaName() + "', 'TEST', 'COLUMN', 4326, 'Geometry', 2)");

   return new Object[][] { new Object[] { notGeometry, database, new Sql[0] },
         new Object[] { nullSchema, database, new Sql[] { nullSchemaExpected } },
         new Object[] { complete, database, new Sql[] { completeExpected } }, };
}
 
开发者ID:lonnyj,项目名称:liquibase-spatial,代码行数:22,代码来源:AddGeometryColumnGeneratorGeoDBTest.java


示例7: testAddBooleanColumnWithDefaultValueAndUniqueConstraint

import liquibase.statement.core.AddColumnStatement; //导入依赖的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


示例8: testWithoutPercona

import liquibase.statement.core.AddColumnStatement; //导入依赖的package包/类
@Test
public void testWithoutPercona() {
    PTOnlineSchemaChangeStatement.available = false;
    SqlStatement[] statements = generateStatements();
    Assert.assertEquals(1, statements.length);
    Assert.assertEquals(AddColumnStatement.class, statements[0].getClass());
}
 
开发者ID:adangel,项目名称:liquibase-percona,代码行数:8,代码来源:PerconaAddColumnChangeTest.java


示例9: testUpdateSQL

import liquibase.statement.core.AddColumnStatement; //导入依赖的package包/类
@Test
public void testUpdateSQL() {
    enableLogging();

    SqlStatement[] statements = generateStatements();
    Assert.assertEquals(3, statements.length);
    Assert.assertEquals(CommentStatement.class, statements[0].getClass());
    Assert.assertEquals("pt-online-schema-change --alter=\"ADD COLUMN new_column INT NULL\" "
            + "--alter-foreign-keys-method=auto "
            + "--host=localhost --port=3306 --user=user --password=*** --execute D=testdb,t=person",
            ((CommentStatement)statements[0]).getText());
    Assert.assertEquals(CommentStatement.class, statements[1].getClass());
    Assert.assertEquals(AddColumnStatement.class, statements[2].getClass());
}
 
开发者ID:adangel,项目名称:liquibase-percona,代码行数:15,代码来源:PerconaAddColumnChangeTest.java


示例10: testSkipAddColumnChange

import liquibase.statement.core.AddColumnStatement; //导入依赖的package包/类
@Test
public void testSkipAddColumnChange() {
    System.setProperty(Configuration.SKIP_CHANGES, "addColumn");
    SqlStatement[] statements = generateStatements();
    Assert.assertEquals(1, statements.length);
    Assert.assertEquals(AddColumnStatement.class, statements[0].getClass());
}
 
开发者ID:adangel,项目名称:liquibase-percona,代码行数:8,代码来源:PerconaAddColumnChangeTest.java


示例11: testWithDisabledPercona

import liquibase.statement.core.AddColumnStatement; //导入依赖的package包/类
@Test
public void testWithDisabledPercona() {
    getChange().setUsePercona(false);
    SqlStatement[] statements = generateStatements();
    Assert.assertEquals(1, statements.length);
    Assert.assertEquals(AddColumnStatement.class, statements[0].getClass());
}
 
开发者ID:adangel,项目名称:liquibase-percona,代码行数:8,代码来源:PerconaAddColumnChangeTest.java


示例12: testWithDisabledPerconaViaDefaultOn

import liquibase.statement.core.AddColumnStatement; //导入依赖的package包/类
@Test
public void testWithDisabledPerconaViaDefaultOn() {
    System.setProperty(Configuration.DEFAULT_ON, "false");
    SqlStatement[] statements = generateStatements();
    Assert.assertEquals(1, statements.length);
    Assert.assertEquals(AddColumnStatement.class, statements[0].getClass());
}
 
开发者ID:adangel,项目名称:liquibase-percona,代码行数:8,代码来源:PerconaAddColumnChangeTest.java


示例13: generateSql

import liquibase.statement.core.AddColumnStatement; //导入依赖的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()]);
    }
 
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:37,代码来源:AddColumnGenerator.java


示例14: getDefaultClause

import liquibase.statement.core.AddColumnStatement; //导入依赖的package包/类
private String getDefaultClause(AddColumnStatement statement, Database database) {
    String clause = "";
    Object defaultValue = statement.getDefaultValue();
    if (defaultValue != null) {
        if (database instanceof MSSQLDatabase) {
            clause += " CONSTRAINT " + ((MSSQLDatabase) database).generateDefaultConstraintName(statement.getTableName(), statement.getColumnName());
        }
        clause += " DEFAULT " + TypeConverterFactory.getInstance().findTypeConverter(database).getDataType(defaultValue).convertObjectToString(defaultValue, database);
    }
    return clause;
}
 
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:12,代码来源:AddColumnGenerator.java


示例15: supports

import liquibase.statement.core.AddColumnStatement; //导入依赖的package包/类
@Override
public boolean supports(AddColumnStatement statement, Database database) {
    return database instanceof OracleDatabase
            || database instanceof HsqlDatabase
            || database instanceof H2Database
            || database instanceof DerbyDatabase
            || database instanceof DB2Database
            || database instanceof FirebirdDatabase
            || database instanceof SybaseDatabase
            || database instanceof SybaseASADatabase
            || database instanceof InformixDatabase;
}
 
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:13,代码来源:AddColumnGeneratorDefaultClauseBeforeNotNull.java


示例16: validate

import liquibase.statement.core.AddColumnStatement; //导入依赖的package包/类
@Override
public ValidationErrors validate(AddColumnStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
    ValidationErrors validationErrors = super.validate(statement, database, sqlGeneratorChain);
    if (database instanceof DerbyDatabase && statement.isAutoIncrement()) {
        validationErrors.addError("Cannot add an identity column to a database");
    }
    return validationErrors;
}
 
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:9,代码来源:AddColumnGeneratorDefaultClauseBeforeNotNull.java


示例17: getDefaultClause

import liquibase.statement.core.AddColumnStatement; //导入依赖的package包/类
private String getDefaultClause(AddColumnStatement statement, Database database) {
    String clause = "";
    Object defaultValue = statement.getDefaultValue();
    if (defaultValue != null) {
        clause += " DEFAULT " + TypeConverterFactory.getInstance().findTypeConverter(database).getDataType(defaultValue).convertObjectToString(defaultValue, database);
    }
    return clause;
}
 
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:9,代码来源:AddColumnGeneratorDefaultClauseBeforeNotNull.java


示例18: supports

import liquibase.statement.core.AddColumnStatement; //导入依赖的package包/类
/**
 * @see liquibase.sqlgenerator.core.AbstractSqlGenerator#supports(liquibase.statement.SqlStatement,
 *      liquibase.database.Database)
 */
@Override
public boolean supports(final AddColumnStatement statement,
      final Database database) {
   return database instanceof DerbyDatabase
         || database instanceof H2Database;
}
 
开发者ID:lonnyj,项目名称:liquibase-spatial,代码行数:11,代码来源:AddGeometryColumnGeneratorGeoDB.java


示例19: supportsTestData

import liquibase.statement.core.AddColumnStatement; //导入依赖的package包/类
/**
 * Provides test data to {@link #testSupports(AddColumnStatement, Database, boolean)}.
 *
 * @return the test data.
 */
@DataProvider
public Object[][] supportsTestData() {
   final AddColumnStatement statement = new AddColumnStatement((String) null, null, null, null,
         null, null);
   return new Object[][] { new Object[] { statement, new DerbyDatabase(), true },
         new Object[] { statement, new H2Database(), true },
         new Object[] { statement, new OracleDatabase(), false }, };
}
 
开发者ID:lonnyj,项目名称:liquibase-spatial,代码行数:14,代码来源:AddGeometryColumnGeneratorGeoDBTest.java


示例20: getDefaultClause

import liquibase.statement.core.AddColumnStatement; //导入依赖的package包/类
private String getDefaultClause(AddColumnStatement statement, Database database) {
    String clause = "";
    Object defaultValue = statement.getDefaultValue();
    if (defaultValue != null) {
        clause += " DEFAULT " + DataTypeFactory.getInstance().fromObject(defaultValue, database).objectToSql(defaultValue, database);
    }
    return clause;
}
 
开发者ID:lbitonti,项目名称:liquibase-hana,代码行数:9,代码来源:AddColumnGeneratorHanaDB.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java WrappingTemplateModel类代码示例发布时间:2022-05-23
下一篇:
Java RestAssuredMockMvc类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap