Example usage for org.hibernate.mapping Table sqlAlterStrings

List of usage examples for org.hibernate.mapping Table sqlAlterStrings

Introduction

In this page you can find the example usage for org.hibernate.mapping Table sqlAlterStrings.

Prototype

public Iterator sqlAlterStrings(Dialect dialect, Metadata metadata, TableInformation tableInfo,
            Identifier defaultCatalog, Identifier defaultSchema) throws HibernateException 

Source Link

Usage

From source file:com.zutubi.pulse.master.hibernate.SchemaRefactor.java

License:Apache License

/**
 * Executes a set of alter table statements to synchronise the underlying database table with the hibernate schema.
 * NOTE: This will only add columns that do not already exist.
 * /*w  ww  .  ja  v a  2s . c om*/
 * @param table         the table to be altered
 * @param connection    the database connection providing access to the table
 * 
 * @throws SQLException is thrown on error
 */
private void updateTableSchema(Table table, Connection connection) throws SQLException {
    DatabaseMetadata meta = new DatabaseMetadata(connection, dialect);
    TableMetadata tableInfo = meta.getTableMetadata(table.getName(), defaultSchema, defaultCatalog, false);

    Iterator alterSqls = table.sqlAlterStrings(dialect, config.getMapping(), tableInfo, defaultCatalog,
            defaultSchema);
    while (alterSqls.hasNext()) {
        String sql = (String) alterSqls.next();
        LOG.info(sql);
        JDBCUtils.execute(connection, sql);
    }
}

From source file:corner.migration.services.impl.fragment.AddColumnFragment.java

License:Apache License

/**
 * @see corner.migration.services.MigrateFragment#generateMigrationFragments(org.hibernate.mapping.Table)
 *//*w  ww .  ja  v  a 2 s .c  o  m*/
@SuppressWarnings("unchecked")
@Override
public List<String> generateMigrationFragments(Table table, TableMetadata tableInfo) {
    List<String> script = new ArrayList<String>();
    Iterator<String> subiter = table.sqlAlterStrings(getDialect(), getSessionFactory(), tableInfo,
            defaultCatalog, defaultSchema);
    while (subiter.hasNext()) {
        script.add(subiter.next());
    }
    return script;
}