當前位置: 首頁>>代碼示例>>Java>>正文


Java AddUniqueConstraintStatement類代碼示例

本文整理匯總了Java中liquibase.statement.core.AddUniqueConstraintStatement的典型用法代碼示例。如果您正苦於以下問題:Java AddUniqueConstraintStatement類的具體用法?Java AddUniqueConstraintStatement怎麽用?Java AddUniqueConstraintStatement使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AddUniqueConstraintStatement類屬於liquibase.statement.core包,在下文中一共展示了AddUniqueConstraintStatement類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: generateSql

import liquibase.statement.core.AddUniqueConstraintStatement; //導入依賴的package包/類
@Override
public Sql[] generateSql(AddUniqueConstraintStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {

	final String sqlNoContraintNameTemplate = "ALTER TABLE %s ADD CONSTRAINT UNIQUE (%s)";
	final String sqlTemplate = "ALTER TABLE %s ADD CONSTRAINT UNIQUE (%s) CONSTRAint %s";
	if (statement.getConstraintName() == null) {
		return new Sql[] {
			new UnparsedSql(String.format(sqlNoContraintNameTemplate 
					, database.escapeTableName(statement.getSchemaName(), statement.getTableName())
					, database.escapeColumnNameList(statement.getColumnNames())
			))
		};
	} else {
		return new Sql[] {
			new UnparsedSql(String.format(sqlTemplate
					, database.escapeTableName(statement.getSchemaName(), statement.getTableName())
					, database.escapeColumnNameList(statement.getColumnNames())
					, database.escapeConstraintName(statement.getConstraintName())
			))
		};
	}


	
}
 
開發者ID:hongliangpan,項目名稱:manydesigns.cn,代碼行數:26,代碼來源:AddUniqueConstraintGeneratorInformix.java

示例2: generateSql

import liquibase.statement.core.AddUniqueConstraintStatement; //導入依賴的package包/類
@Override
public Sql[] generateSql(AddUniqueConstraintStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {

	final String sqlTemplate = "ALTER TABLE %s ADD CONSTRAINT %s UNIQUE (%s)";
	final String sqlNoContraintNameTemplate = "ALTER TABLE %s ADD UNIQUE (%s)";
	
	if (statement.getConstraintName() == null) {
		return new Sql[] {
			new UnparsedSql(String.format(sqlNoContraintNameTemplate 
					, database.escapeTableName(statement.getSchemaName(), statement.getTableName())
					, database.escapeColumnNameList(statement.getColumnNames())
			))
		};
	} else {
		return new Sql[] {
			new UnparsedSql(String.format(sqlTemplate
					, database.escapeTableName(statement.getSchemaName(), statement.getTableName())
					, database.escapeConstraintName(statement.getConstraintName())
					, database.escapeColumnNameList(statement.getColumnNames())
			))
		};
	}
}
 
開發者ID:hongliangpan,項目名稱:manydesigns.cn,代碼行數:24,代碼來源:AddUniqueConstraintGeneratorTDS.java

示例3: testWithoutPercona

import liquibase.statement.core.AddUniqueConstraintStatement; //導入依賴的package包/類
@Test
public void testWithoutPercona() {
    PTOnlineSchemaChangeStatement.available = false;
    SqlStatement[] statements = generateStatements();
    Assert.assertEquals(1, statements.length);
    Assert.assertEquals(AddUniqueConstraintStatement.class, statements[0].getClass());
}
 
開發者ID:adangel,項目名稱:liquibase-percona,代碼行數:8,代碼來源:PerconaAddUniqueConstraintChangeTest.java

示例4: testUpdateSQL

import liquibase.statement.core.AddUniqueConstraintStatement; //導入依賴的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=\"" + alterText + "\" "
            + "--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(AddUniqueConstraintStatement.class, statements[2].getClass());
}
 
開發者ID:adangel,項目名稱:liquibase-percona,代碼行數:15,代碼來源:PerconaAddUniqueConstraintChangeTest.java

示例5: testSkipAddUniqueConstraintChange

import liquibase.statement.core.AddUniqueConstraintStatement; //導入依賴的package包/類
@Test
public void testSkipAddUniqueConstraintChange() {
    System.setProperty(Configuration.SKIP_CHANGES, "addUniqueConstraint");
    SqlStatement[] statements = generateStatements();
    Assert.assertEquals(1, statements.length);
    Assert.assertEquals(AddUniqueConstraintStatement.class, statements[0].getClass());
}
 
開發者ID:adangel,項目名稱:liquibase-percona,代碼行數:8,代碼來源:PerconaAddUniqueConstraintChangeTest.java

示例6: supports

import liquibase.statement.core.AddUniqueConstraintStatement; //導入依賴的package包/類
@Override
public boolean supports(AddUniqueConstraintStatement statement, Database database) {
    return !(database instanceof SQLiteDatabase)
    		&& !(database instanceof MSSQLDatabase)
    		&& !(database instanceof SybaseDatabase)
    		&& !(database instanceof SybaseASADatabase)
    		&& !(database instanceof InformixDatabase)
    ;
}
 
開發者ID:hongliangpan,項目名稱:manydesigns.cn,代碼行數:10,代碼來源:AddUniqueConstraintGenerator.java

示例7: supports

import liquibase.statement.core.AddUniqueConstraintStatement; //導入依賴的package包/類
@Override
public boolean supports(AddUniqueConstraintStatement statement, Database database) {
       return  (database instanceof MSSQLDatabase)
		|| (database instanceof SybaseDatabase)
		|| (database instanceof SybaseASADatabase)
	;
}
 
開發者ID:hongliangpan,項目名稱:manydesigns.cn,代碼行數:8,代碼來源:AddUniqueConstraintGeneratorTDS.java

示例8: generateStatements

import liquibase.statement.core.AddUniqueConstraintStatement; //導入依賴的package包/類
public SqlStatement[] generateStatements(Database database) {

//todo    	if (database instanceof SQLiteDatabase) {
//    		// return special statements for SQLite databases
//    		return generateStatementsForSQLiteDatabase(database);
//        }

        boolean deferrable = false;
        if (getDeferrable() != null) {
            deferrable = getDeferrable();
        }

        boolean initiallyDeferred = false;
        if (getInitiallyDeferred() != null) {
            initiallyDeferred = getInitiallyDeferred();
        }
        boolean disabled = false;
        if (getDisabled() != null) {
            disabled = getDisabled();
        }

    	AddUniqueConstraintStatement statement = new AddUniqueConstraintStatement(getSchemaName() == null?database.getDefaultSchemaName():getSchemaName(), getTableName(), getColumnNames(), getConstraintName());
        statement.setTablespace(getTablespace())
                        .setDeferrable(deferrable)
                        .setInitiallyDeferred(initiallyDeferred)
                        .setDisabled(disabled);

        return new SqlStatement[] { statement };
    }
 
開發者ID:hongliangpan,項目名稱:manydesigns.cn,代碼行數:30,代碼來源:AddUniqueConstraintChange.java

示例9: supports

import liquibase.statement.core.AddUniqueConstraintStatement; //導入依賴的package包/類
@Override
public boolean supports(AddUniqueConstraintStatement statement, Database database) {
       return (database instanceof InformixDatabase);
}
 
開發者ID:hongliangpan,項目名稱:manydesigns.cn,代碼行數:5,代碼來源:AddUniqueConstraintGeneratorInformix.java

示例10: validate

import liquibase.statement.core.AddUniqueConstraintStatement; //導入依賴的package包/類
public ValidationErrors validate(AddUniqueConstraintStatement addUniqueConstraintStatement, Database database, SqlGeneratorChain sqlGeneratorChain) {
    ValidationErrors validationErrors = new ValidationErrors();
    validationErrors.checkRequiredField("columnNames", addUniqueConstraintStatement.getColumnNames());
    validationErrors.checkRequiredField("tableName", addUniqueConstraintStatement.getTableName());
    return validationErrors;
}
 
開發者ID:hongliangpan,項目名稱:manydesigns.cn,代碼行數:7,代碼來源:AddUniqueConstraintGenerator.java

示例11: generateSql

import liquibase.statement.core.AddUniqueConstraintStatement; //導入依賴的package包/類
public Sql[] generateSql(AddUniqueConstraintStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {

		String sql = null;
		if (statement.getConstraintName() == null) {
			sql = String.format("ALTER TABLE %s ADD UNIQUE (%s)"
					, database.escapeTableName(statement.getSchemaName(), statement.getTableName())
					, database.escapeColumnNameList(statement.getColumnNames())
			);
		} else {
			sql = String.format("ALTER TABLE %s ADD CONSTRAINT %s UNIQUE (%s)"
					, database.escapeTableName(statement.getSchemaName(), statement.getTableName())
					, database.escapeConstraintName(statement.getConstraintName())
					, database.escapeColumnNameList(statement.getColumnNames())
			);
		}
		if(database instanceof OracleDatabase) {
	        if (statement.isDeferrable() || statement.isInitiallyDeferred()) {
	            if (statement.isDeferrable()) {
	            	sql += " DEFERRABLE";
	            }

	            if (statement.isInitiallyDeferred()) {
	            	sql +=" INITIALLY DEFERRED";
	            }
	        }
            if (statement.isDisabled()) {
                sql +=" DISABLE";
            }
		}

        if (StringUtils.trimToNull(statement.getTablespace()) != null && database.supportsTablespaces()) {
            if (database instanceof MSSQLDatabase) {
                sql += " ON " + statement.getTablespace();
            } else if (database instanceof DB2Database
                || database instanceof SybaseASADatabase
                || database instanceof InformixDatabase) {
                ; //not supported
            } else {
                sql += " USING INDEX TABLESPACE " + statement.getTablespace();
            }
        }

        return new Sql[] {
                new UnparsedSql(sql)
        };

    }
 
開發者ID:hongliangpan,項目名稱:manydesigns.cn,代碼行數:48,代碼來源:AddUniqueConstraintGenerator.java

示例12: generateSql

import liquibase.statement.core.AddUniqueConstraintStatement; //導入依賴的package包/類
@Override
public Sql[] generateSql(AddColumnStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
	String alterTable = "ALTER TABLE " + database.escapeTableName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName()) +
               " ADD " +
               database.escapeColumnName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName(), statement.getColumnName())
               + " " + DataTypeFactory.getInstance().fromDescription(statement.getColumnType() + (statement.isAutoIncrement() ? "{autoIncrement:true}" : ""), database).toDatabaseDataType(database);

	if (statement.isAutoIncrement() && database.supportsAutoIncrement()) {
		alterTable += " " + database.getAutoIncrementClause(null, null);
	}

	if (!statement.isNullable()) {
		alterTable += " NOT NULL";
	} else {
		if (database instanceof SybaseDatabase || database instanceof SybaseASADatabase) {
			alterTable += " NULL";
		}
	}

	if (statement.getDefaultValue()!=null){
		alterTable += " DEFAULT ";
		LiquibaseDataType defaultValueType = DataTypeFactory.getInstance().fromDescription(statement.getColumnType() + (statement.isAutoIncrement() ? "{autoIncrement:true}" : ""), database);
		alterTable +=(defaultValueType instanceof DateTimeType ?" TIMESTAMP ":(defaultValueType instanceof DateType ?" DATE ":(defaultValueType instanceof TimeType ?" TIME ":"")));
		alterTable += DataTypeFactory.getInstance().fromObject(statement.getDefaultValue(), database).objectToSql(statement.getDefaultValue(), database);
	}

	List<Sql> returnSql = new ArrayList<Sql>();
	returnSql.add(new UnparsedSql(alterTable, new Column().setRelation(new Table().setName(statement.getTableName()).setSchema(new Schema(statement.getCatalogName(), statement.getSchemaName())).setName(statement.getColumnName()))));

	if (statement.isPrimaryKey()) {
		returnSql.addAll(Arrays.asList(SqlGeneratorFactory.getInstance().generateSql(new AddPrimaryKeyStatement(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName(), statement.getColumnName(), null) , database)));
	}

	if (statement.isUnique()) {
		returnSql.addAll(Arrays.asList(SqlGeneratorFactory.getInstance().generateSql(new AddUniqueConstraintStatement(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName(), new ColumnConfig[] { new ColumnConfig().setName(statement.getColumnName())}, null) , database)));
	}
	//	if (statement.getDefaultValue()!=null)
	//		returnSql.addAll(Arrays.asList(SqlGeneratorFactory.getInstance().generateSql(new AddDefaultValueStatement(statement.getSchemaName(), statement.getTableName(), statement.getColumnName(), statement.getColumnType(), statement.getDefaultValue()) , database)));

	addForeignKeyStatements(statement, database, returnSql);

	return returnSql.toArray(new Sql[returnSql.size()]);
}
 
開發者ID:liquibase,項目名稱:liquibase-teradata,代碼行數:44,代碼來源:AddColumnGeneratorTeradata.java


注:本文中的liquibase.statement.core.AddUniqueConstraintStatement類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。