Example usage for org.hibernate.mapping Column getSqlTypeCode

List of usage examples for org.hibernate.mapping Column getSqlTypeCode

Introduction

In this page you can find the example usage for org.hibernate.mapping Column getSqlTypeCode.

Prototype

public Integer getSqlTypeCode() 

Source Link

Document

Returns the underlying columns sqltypecode.

Usage

From source file:com.zutubi.pulse.master.transfer.jdbc.HibernateTransferSource.java

License:Apache License

public void transferTo(TransferTarget target) throws TransferException {
    try {//w w  w . ja v  a 2s. co  m
        // ensure that the mappings are built.
        configuration.buildMappings();
        Mapping mapping = new HibernateMapping(configuration);

        target.start();

        Connection con = null;
        try {
            con = dataSource.getConnection();

            Iterator tables = configuration.getTableMappings();
            while (tables.hasNext()) {
                Table table = (Table) tables.next();

                List<Column> columns = MappingUtils.getColumns(table);
                for (Column column : columns) {
                    if (column.getSqlTypeCode() == null) {
                        column.setSqlTypeCode(column.getSqlTypeCode(mapping));
                    }
                }

                exportTable(target, table, con, columns);
            }

            // handle the special case.
            Table table = HibernateUniqueKeyTable.getMapping();
            exportTable(target, table, con, MappingUtils.getColumns(table));

        } finally {
            JDBCUtils.close(con);
        }

        target.end();
    } catch (SQLException e) {
        throw new HibernateTransferException(e);
    }
}

From source file:net.lshift.hibernate.migrations.SQLStringHelpers.java

License:Apache License

/**
 * Generates an identity column string//from   w  w  w.  j  a  v  a  2  s .c  o m
 * @throws UnsupportedOperationException If the underlying dialect does not support identity columns*
*/
public static String generateIdentityColumnString(Dialect dialect, Column col) {

    if (!dialect.supportsIdentityColumns()) {
        String dialectName = Environment.getProperties().getProperty(Environment.DIALECT);
        throw new UnsupportedOperationException(dialectName + " does not support identity columns");
    }

    StringBuilder buffer = new StringBuilder();

    buffer.append(col.getQuotedName(dialect)).append(" ");

    // to support dialects that have their own identity data type
    if (dialect.hasDataTypeInIdentityColumn()) {
        buffer.append(getTypeName(dialect, col));
    }
    buffer.append(' ').append(dialect.getIdentityColumnString(col.getSqlTypeCode()));

    return buffer.toString();
}

From source file:net.lshift.hibernate.migrations.SQLStringHelpers.java

License:Apache License

public static String generateColumnString(Dialect dialect, Column col, boolean newTable) {
    StringBuilder buffer = new StringBuilder();

    buffer.append(col.getQuotedName(dialect)).append(" ");
    buffer.append(getTypeName(dialect, col));

    if (!newTable && col.getDefaultValue() == null && !col.isNullable()) {
        throw new IllegalArgumentException(
                "Cannot have a null default value for a non-nullable column when altering a table: " + col);
    }//from   w ww  .  j a v a  2s. co  m
    if (col.getDefaultValue() != null) {
        String defaultQuote;

        buffer.append(" default ");
        if (col.getSqlTypeCode() == Types.VARCHAR)
            defaultQuote = "'";
        else
            defaultQuote = "";

        buffer.append(defaultQuote);
        buffer.append(col.getDefaultValue());
        buffer.append(defaultQuote);
    }
    if (col instanceof VirtualColumn) {
        buffer.append(String.format(" GENERATED ALWAYS AS (%s) VIRTUAL", ((VirtualColumn) col).getGenerator()));
    }

    // HSQL Doesn't like the not null coming before the default stanza
    if (!col.isNullable()) {
        buffer.append(" not null");
    }

    return buffer.toString();
}

From source file:net.lshift.hibernate.migrations.SQLStringHelpers.java

License:Apache License

/**
 * Note to the unassuming maintenance developer:
 *
 * What happens with Oracle a dialect is when a varchar2 is larger than 4000,
 * the type name returned for java.sql.Type.VARCHAR is a long, which can be very confusing.
 *
 * I'm not sure that this is significant enough to warrant patching.
 *
 *//*ww  w  .j av a 2  s.c  o m*/
private static String getTypeName(Dialect dialect, Column col) {
    return dialect.getTypeName(col.getSqlTypeCode(), col.getLength(), col.getPrecision(), col.getScale());
}