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


Java DateTimeType类代码示例

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


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

示例1: generateSql

import liquibase.datatype.core.DateTimeType; //导入依赖的package包/类
/**
 * @see liquibase.sqlgenerator.core.AddDefaultValueGenerator#generateSql(liquibase.statement.core.AddDefaultValueStatement, liquibase.database.Database, liquibase.sqlgenerator.SqlGeneratorChain)
 */
@Override
public Sql[] generateSql(AddDefaultValueStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
	Object defaultValue = statement.getDefaultValue();
       LiquibaseDataType defaultValueType = DataTypeFactory.getInstance().fromObject(defaultValue, database);
	return new Sql[]{
			new UnparsedSql("ALTER TABLE " + database.escapeTableName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName())
					+ " ADD  "
                       + database.escapeColumnName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName(), statement.getColumnName())
                       + " DEFAULT "
					+ (defaultValueType instanceof DateTimeType ?" TIMESTAMP ":(defaultValueType instanceof DateType ?" DATE ":(defaultValueType instanceof TimeType ?" TIME ":"")))
					+ defaultValueType.objectToSql(defaultValue, database),
					new Column().setRelation(new Table().setName(statement.getTableName()).setSchema(new Schema(statement.getCatalogName(), statement.getSchemaName())).setName(statement.getColumnName())))
	};
}
 
开发者ID:liquibase,项目名称:liquibase-teradata,代码行数:18,代码来源:AddDefaultValueGeneratorTeradata.java

示例2: generateSql

import liquibase.datatype.core.DateTimeType; //导入依赖的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.datatype.core.DateTimeType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。