Example usage for org.hibernate.tool.hbm2ddl ColumnMetadata getTypeName

List of usage examples for org.hibernate.tool.hbm2ddl ColumnMetadata getTypeName

Introduction

In this page you can find the example usage for org.hibernate.tool.hbm2ddl ColumnMetadata getTypeName.

Prototype

public String getTypeName() 

Source Link

Usage

From source file:com.amalto.core.storage.hibernate.mapping.MDMTableUtils.java

License:Open Source License

public static boolean isVarcharField(Column newColumn, ColumnMetadata oldColumnInfo, Dialect dialect) {
    boolean isVarcharType = oldColumnInfo.getTypeCode() == java.sql.Types.VARCHAR;
    if (dialect instanceof SQLServerDialect) {
        isVarcharType |= oldColumnInfo.getTypeCode() == java.sql.Types.NVARCHAR
                && oldColumnInfo.getTypeName().equalsIgnoreCase("nvarchar");
    }//from   w ww . j  a v a  2s  .co m
    return isVarcharType;
}

From source file:org.beangle.commons.orm.hibernate.internal.SchemaValidator.java

License:Open Source License

private void validateColumns(Table table, Dialect dialect, Mapping mapping, TableMetadata tableInfo) {
    Iterator<?> iter = table.getColumnIterator();
    Set<ColumnMetadata> processed = CollectUtils.newHashSet();
    String tableName = Table.qualify(tableInfo.getCatalog(), tableInfo.getSchema(), tableInfo.getName());
    while (iter.hasNext()) {
        Column col = (Column) iter.next();
        ColumnMetadata columnInfo = tableInfo.getColumnMetadata(col.getName());
        if (columnInfo == null) {
            reporter.append("Missing column: " + col.getName() + " in " + tableName);
        } else {//from  w w w . j a  va2s  .c  o  m
            final boolean typesMatch = col.getSqlType(dialect, mapping).toLowerCase()
                    .startsWith(columnInfo.getTypeName().toLowerCase())
                    || columnInfo.getTypeCode() == col.getSqlTypeCode(mapping);
            if (!typesMatch) {
                reporter.append("Wrong column type in " + tableName + " for column " + col.getName()
                        + ". Found: " + columnInfo.getTypeName().toLowerCase() + ", expected: "
                        + col.getSqlType(dialect, mapping));
            }
            processed.add(columnInfo);
        }
    }
    // 
    try {
        Field field = tableInfo.getClass().getField("columns");
        @SuppressWarnings("unchecked")
        Set<ColumnMetadata> allColumns = CollectUtils
                .newHashSet(((Map<String, ColumnMetadata>) field.get(tableInfo)).values());
        allColumns.removeAll(processed);
        if (!allColumns.isEmpty()) {
            for (ColumnMetadata col : allColumns) {
                reporter.append("Extra column " + col.getName() + " in " + tableName);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}