Package liquibase.statement

Examples of liquibase.statement.AutoIncrementConstraint


        if (database instanceof SybaseASADatabase) {
          CreateTableStatement statement = new CreateTableStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
          statement.addColumn(
            COLUMN_NAME1,
            DataTypeFactory.getInstance().fromDescription("BIGINT{autoIncrement:true}", database),
            new AutoIncrementConstraint(COLUMN_NAME1)
          );

          Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);

          assertEquals("CREATE TABLE SCHEMA_NAME.TABLE_NAME (COLUMN1_NAME BIGINT DEFAULT AUTOINCREMENT NULL)", generatedSql[0].toSql());
View Full Code Here


        if (database instanceof SybaseASADatabase) {
          CreateTableStatement statement = new CreateTableStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
          statement.addColumn(
            COLUMN_NAME1,
            DataTypeFactory.getInstance().fromDescription("BIGINT{autoIncrement:true}", database),
            new AutoIncrementConstraint(COLUMN_NAME1, BigInteger.valueOf(2), null)
          );

          Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);

          // start with not supported by SybaseASA
View Full Code Here

        if (database instanceof SybaseASADatabase) {
          CreateTableStatement statement = new CreateTableStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
          statement.addColumn(
            COLUMN_NAME1,
            DataTypeFactory.getInstance().fromDescription("BIGINT{autoIncrement:true}", database),
            new AutoIncrementConstraint(COLUMN_NAME1, BigInteger.valueOf(2), BigInteger.TEN)
          );

          Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);

          // start with and increment by not supported by SybaseASA
View Full Code Here

        if (database instanceof SybaseDatabase) {
          CreateTableStatement statement = new CreateTableStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
          statement.addColumn(
            COLUMN_NAME1,
            DataTypeFactory.getInstance().fromDescription("BIGINT{autoIncrement:true}", database),
            new AutoIncrementConstraint(COLUMN_NAME1)
          );

          Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);

          assertEquals("Error with "+database, "CREATE TABLE [SCHEMA_NAME].[TABLE_NAME] ([COLUMN1_NAME] BIGINT IDENTITY NULL)", generatedSql[0].toSql());
View Full Code Here

        if (database instanceof SybaseDatabase) {
          CreateTableStatement statement = new CreateTableStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
          statement.addColumn(
            COLUMN_NAME1,
            DataTypeFactory.getInstance().fromDescription("BIGINT{autoIncrement:true}", database),
            new AutoIncrementConstraint(COLUMN_NAME1, BigInteger.valueOf(2), null)
          );

          Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);

          // start with not supported by Sybase
View Full Code Here

        if (database instanceof SybaseDatabase) {
          CreateTableStatement statement = new CreateTableStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
          statement.addColumn(
            COLUMN_NAME1,
            DataTypeFactory.getInstance().fromDescription("BIGINT{autoIncrement:true}", database),
            new AutoIncrementConstraint(COLUMN_NAME1, BigInteger.valueOf(2), BigInteger.TEN)
          );

          Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);

          // start with and increment by not supported by Sybase
View Full Code Here

            DatabaseDataType columnType = statement.getColumnTypes().get(column).toDatabaseDataType(database);
            buffer.append(database.escapeColumnName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName(), column));

            buffer.append(" ").append(columnType);

            AutoIncrementConstraint autoIncrementConstraint = null;
           
            for (AutoIncrementConstraint currentAutoIncrementConstraint : statement.getAutoIncrementConstraints()) {
                if (column.equals(currentAutoIncrementConstraint.getColumnName())) {
                    autoIncrementConstraint = currentAutoIncrementConstraint;
                    break;
                }
            }

            boolean isAutoIncrementColumn = autoIncrementConstraint != null;
            boolean isPrimaryKeyColumn = statement.getPrimaryKeyConstraint() != null
                    && statement.getPrimaryKeyConstraint().getColumns().contains(column);
            isPrimaryKeyAutoIncrement = isPrimaryKeyAutoIncrement
                    || isPrimaryKeyColumn && isAutoIncrementColumn;
           
            if (isPrimaryKeyColumn) {
              primaryKeyColumns.add(column);
            }
           
            if ((database instanceof SQLiteDatabase) &&
                    isSinglePrimaryKeyColumn &&
                    isPrimaryKeyColumn &&
                    isAutoIncrementColumn) {
                String pkName = StringUtils.trimToNull(statement.getPrimaryKeyConstraint().getConstraintName());
                if (pkName == null) {
                    pkName = database.generatePrimaryKeyName(statement.getTableName());
                }
                if (pkName != null) {
                    buffer.append(" CONSTRAINT ");
                    buffer.append(database.escapeConstraintName(pkName));
                }
                buffer.append(" PRIMARY KEY");
            }

            // for the serial data type in postgres, there should be no default value
            if (!columnType.isAutoIncrement() && statement.getDefaultValue(column) != null) {
                Object defaultValue = statement.getDefaultValue(column);
                if (database instanceof MSSQLDatabase) {
                    buffer.append(" CONSTRAINT ").append(((MSSQLDatabase) database).generateDefaultConstraintName(statement.getTableName(), column));
                }
                if (database instanceof OracleDatabase && statement.getDefaultValue(column).toString().startsWith("GENERATED ALWAYS ")) {
                    buffer.append(" ");
                } else {
                    buffer.append(" DEFAULT ");
                }
                if (defaultValue instanceof SequenceNextValueFunction) {
                    buffer.append(database.generateDatabaseFunctionValue((SequenceNextValueFunction) defaultValue));
                } else {
                    buffer.append(statement.getColumnTypes().get(column).objectToSql(defaultValue, database));
                }
            }

            if (isAutoIncrementColumn) {
                // TODO: check if database supports auto increment on non primary key column
                if (database.supportsAutoIncrement()) {
                    String autoIncrementClause = database.getAutoIncrementClause(autoIncrementConstraint.getStartWith(), autoIncrementConstraint.getIncrementBy());
               
                    if (!"".equals(autoIncrementClause)) {
                        buffer.append(" ").append(autoIncrementClause);
                    }

                    if( autoIncrementConstraint.getStartWith() != null ){
                      if (database instanceof PostgresDatabase) {
                          String sequenceName = statement.getTableName()+"_"+column+"_seq";
                          additionalSql.add(new UnparsedSql("alter sequence "+database.escapeSequenceName(statement.getCatalogName(), statement.getSchemaName(), sequenceName)+" start with "+autoIncrementConstraint.getStartWith(), new Sequence().setName(sequenceName).setSchema(statement.getCatalogName(), statement.getSchemaName())));
                      }else if(database instanceof MySQLDatabase){
                        mysqlTableOptionStartWith = autoIncrementConstraint.getStartWith();
                      }
                    }
                } else {
                    LogFactory.getLogger().warning(database.getShortName()+" does not support autoincrement columns as requested for "+(database.escapeTableName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName())));
                }
View Full Code Here

TOP

Related Classes of liquibase.statement.AutoIncrementConstraint

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.