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

Java LiquibaseDataType类代码示例

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

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



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

示例1: generateSql

import liquibase.datatype.LiquibaseDataType; //导入依赖的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


示例2: validate

import liquibase.datatype.LiquibaseDataType; //导入依赖的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


示例3: timestampAliases

import liquibase.datatype.LiquibaseDataType; //导入依赖的package包/类
@Test
public void timestampAliases() throws Exception {
    LiquibaseDataType liquibaseDataType = DataTypeFactory.getInstance().fromDescription("datetime", snowflakeDatabase);
    String[] aliases = liquibaseDataType.getAliases();
    assertEquals(2, aliases.length);
    assertThat(aliases, hasItemInArray("datetime"));
    assertThat(aliases, hasItemInArray("java.sql.Types.DATETIME"));
}
 
开发者ID:CDKGlobal,项目名称:liquibase-snowflake,代码行数:9,代码来源:TimestampNTZTypeTest.java


示例4: validate

import liquibase.datatype.LiquibaseDataType; //导入依赖的package包/类
@Override
public ValidationErrors validate(final CreateTableStatement statement, final Database database,
      final SqlGeneratorChain sqlGeneratorChain) {
   final ValidationErrors validationErrors = new ValidationErrors();
   for (final Entry<String, LiquibaseDataType> entry : statement.getColumnTypes().entrySet()) {
      if (entry.getValue() instanceof GeometryType) {
         final GeometryType geometryType = (GeometryType) entry.getValue();
         if (geometryType.getSRID() == null) {
            validationErrors.addError("The SRID parameter is required on the geometry type");
         }
      }
   }
   validationErrors.addAll(sqlGeneratorChain.validate(statement, database));
   return validationErrors;
}
 
开发者ID:lonnyj,项目名称:liquibase-spatial,代码行数:16,代码来源:CreateSpatialTableGeneratorGeoDB.java


示例5: generateSql

import liquibase.datatype.LiquibaseDataType; //导入依赖的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


示例6: isAutoIncrement

import liquibase.datatype.LiquibaseDataType; //导入依赖的package包/类
/**
 * has <code>dataType</code> auto increment property ?
 */
   //FIXME remove if will be accepted  https://github.com/liquibase/liquibase/pull/247
private boolean isAutoIncrement(LiquibaseDataType dataType) {
	boolean retVal = false;
	String methodName = "isAutoIncrement";
	Method[] methods = dataType.getClass().getMethods();
	for (Method method : methods) {
		if (method.getName().equals(methodName)
				&& method.getParameterTypes().length == 0) {
			retVal = true;
			break;
		}
	}
	return retVal;
}
 
开发者ID:exteso,项目名称:parkingfriends,代码行数:18,代码来源:JHipsterTableSnapshotGenerator.java


示例7: datetimeConvertsToTimestamp

import liquibase.datatype.LiquibaseDataType; //导入依赖的package包/类
@Test
public void datetimeConvertsToTimestamp() throws Exception {
    LiquibaseDataType liquibaseDataType = DataTypeFactory.getInstance().fromDescription("datetime", snowflakeDatabase);
    assertEquals("liquibase.ext.snowflake.datatype.TimestampNTZType", liquibaseDataType.getClass().getName());
}
 
开发者ID:CDKGlobal,项目名称:liquibase-snowflake,代码行数:6,代码来源:TimestampNTZTypeTest.java


示例8: generateSql

import liquibase.datatype.LiquibaseDataType; //导入依赖的package包/类
@Override
public Sql[] generateSql(final AddColumnStatement statement,
      final Database database, final SqlGeneratorChain sqlGeneratorChain) {

   GeometryType geometryType = null;
   final LiquibaseDataType dataType = DataTypeFactory.getInstance()
         .fromDescription(statement.getColumnType(), database);
   if (dataType instanceof GeometryType) {
      geometryType = (GeometryType) dataType;
   }

   final boolean isGeometryColumn = geometryType != null;

   // The AddGeometryColumn procedure handles the column already being
   // present, so let a
   // downstream SQL generator handle the typical column addition logic (e.g.
   // placement in the
   // table) then invoke the procedure.
   final List<Sql> list = new ArrayList<Sql>();
   list.addAll(Arrays.asList(sqlGeneratorChain.generateSql(statement,
         database)));
   if (isGeometryColumn) {
      String schemaName = statement.getSchemaName();
      if (schemaName == null) {
         schemaName = database.getDefaultSchemaName();
      }
      final String tableName = statement.getTableName();
      final String columnName = statement.getColumnName();

      final int srid = geometryType.getSRID();
      final String geomType = StringUtils.trimToNull(geometryType
            .getGeometryType()) == null ? "'Geometry'" : "'"
            + database.escapeStringForDatabase(geometryType
                  .getGeometryType()) + "'";
      final String sql = "CALL AddGeometryColumn('" + schemaName + "', '"
            + tableName + "', '" + columnName + "', " + srid + ", "
            + geomType + ", 2)";
      final Sql addGeometryColumn = new UnparsedSql(sql);
      list.add(addGeometryColumn);
   }
   return list.toArray(new Sql[list.size()]);
}
 
开发者ID:lonnyj,项目名称:liquibase-spatial,代码行数:43,代码来源:AddGeometryColumnGeneratorGeoDB.java


示例9: generateSql

import liquibase.datatype.LiquibaseDataType; //导入依赖的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


示例10: snapshotObject

import liquibase.datatype.LiquibaseDataType; //导入依赖的package包/类
@Override
protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot snapshot) throws DatabaseException, InvalidExampleException {
    HibernateDatabase database = (HibernateDatabase) snapshot.getDatabase();
    Configuration cfg = database.getConfiguration();

    Dialect dialect = database.getDialect();
    Mapping mapping = cfg.buildMapping();

    org.hibernate.mapping.Table hibernateTable = findHibernateTable(example, snapshot);
    if (hibernateTable == null) {
        return null;
    }

    Table table = new Table().setName(hibernateTable.getName());
    PrimaryKey primaryKey = null;
    int pkColumnPosition = 0;
    LOG.info("Found table " + table.getName());

    table.setSchema(example.getSchema());

    Iterator columnIterator = hibernateTable.getColumnIterator();
    while (columnIterator.hasNext()) {
        org.hibernate.mapping.Column hibernateColumn = (org.hibernate.mapping.Column) columnIterator.next();
        Column column = new Column();
        column.setName(hibernateColumn.getName());

        String hibernateType = hibernateColumn.getSqlType(dialect, mapping);
        DataType dataType = toDataType(hibernateType, hibernateColumn.getSqlTypeCode());
        if (dataType == null) {
            throw new DatabaseException("Unable to find column data type for column " + hibernateColumn.getName());
        }

        column.setType(dataType);
        LOG.info("Found column " + column.getName() + " " + column.getType().toString());

        column.setRemarks(hibernateColumn.getComment());
        column.setDefaultValue(hibernateColumn.getDefaultValue());
        column.setNullable(hibernateColumn.isNullable());
        column.setCertainDataType(false);

        org.hibernate.mapping.PrimaryKey hibernatePrimaryKey = hibernateTable.getPrimaryKey();
        if (hibernatePrimaryKey != null) {
            boolean isPrimaryKeyColumn = false;
            //noinspection unchecked
            for (org.hibernate.mapping.Column pkColumn : (List<org.hibernate.mapping.Column>) hibernatePrimaryKey.getColumns()) {
                if (pkColumn.getName().equals(hibernateColumn.getName())) {
                    isPrimaryKeyColumn = true;
                    break;
                }
            }

            if (isPrimaryKeyColumn) {
                if (primaryKey == null) {
                    primaryKey = new PrimaryKey();
                    primaryKey.setName(hibernatePrimaryKey.getName());
                }
                primaryKey.addColumnName(pkColumnPosition++, column.getName());

                LiquibaseDataType liquibaseDataType = DataTypeFactory
			.getInstance().from(column.getType());
	// only columns types supporting auto increment -
	// DataTypeFactory
	if (isAutoIncrement(liquibaseDataType)) {

		if (dialect.getNativeIdentifierGeneratorClass().equals(
				IdentityGenerator.class)) {
			column.setAutoIncrementInformation(new Column.AutoIncrementInformation());
		}
	}
            }
        }
        column.setRelation(table);

        table.setPrimaryKey(primaryKey);
        table.getColumns().add(column);

    }

    return table;
}
 
开发者ID:exteso,项目名称:parkingfriends,代码行数:81,代码来源:JHipsterTableSnapshotGenerator.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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