Example usage for org.hibernate.tool.hbm2ddl TableMetadata getCatalog

List of usage examples for org.hibernate.tool.hbm2ddl TableMetadata getCatalog

Introduction

In this page you can find the example usage for org.hibernate.tool.hbm2ddl TableMetadata getCatalog.

Prototype

public String getCatalog() 

Source Link

Usage

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  v  a  2  s  .  c  om*/
            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();
    }
}