Search in sources :

Example 1 with ExportableColumn

use of org.hibernate.id.ExportableColumn in project hibernate-orm by hibernate.

the class TableGenerator method registerExportables.

@Override
public void registerExportables(Database database) {
    final Dialect dialect = database.getJdbcEnvironment().getDialect();
    final Namespace namespace = database.locateNamespace(qualifiedTableName.getCatalogName(), qualifiedTableName.getSchemaName());
    Table table = namespace.locateTable(qualifiedTableName.getObjectName());
    if (table == null) {
        table = namespace.createTable(qualifiedTableName.getObjectName(), false);
        // todo : note sure the best solution here.  do we add the columns if missing?  other?
        final Column segmentColumn = new ExportableColumn(database, table, segmentColumnName, StringType.INSTANCE, dialect.getTypeName(Types.VARCHAR, segmentValueLength, 0, 0));
        segmentColumn.setNullable(false);
        table.addColumn(segmentColumn);
        // lol
        table.setPrimaryKey(new PrimaryKey(table));
        table.getPrimaryKey().addColumn(segmentColumn);
        final Column valueColumn = new ExportableColumn(database, table, valueColumnName, LongType.INSTANCE);
        table.addColumn(valueColumn);
    }
    // allow physical naming strategies a chance to kick in
    this.renderedTableName = database.getJdbcEnvironment().getQualifiedObjectNameFormatter().format(table.getQualifiedTableName(), dialect);
    this.selectQuery = buildSelectQuery(dialect);
    this.updateQuery = buildUpdateQuery();
    this.insertQuery = buildInsertQuery();
}
Also used : Table(org.hibernate.mapping.Table) Column(org.hibernate.mapping.Column) ExportableColumn(org.hibernate.id.ExportableColumn) Dialect(org.hibernate.dialect.Dialect) ExportableColumn(org.hibernate.id.ExportableColumn) PrimaryKey(org.hibernate.mapping.PrimaryKey) Namespace(org.hibernate.boot.model.relational.Namespace)

Example 2 with ExportableColumn

use of org.hibernate.id.ExportableColumn in project hibernate-orm by hibernate.

the class TableStructure method registerExportables.

@Override
public void registerExportables(Database database) {
    final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment();
    final Dialect dialect = jdbcEnvironment.getDialect();
    final Namespace namespace = database.locateNamespace(logicalQualifiedTableName.getCatalogName(), logicalQualifiedTableName.getSchemaName());
    Table table = namespace.locateTable(logicalQualifiedTableName.getObjectName());
    if (table == null) {
        table = namespace.createTable(logicalQualifiedTableName.getObjectName(), false);
    }
    this.tableNameText = jdbcEnvironment.getQualifiedObjectNameFormatter().format(table.getQualifiedTableName(), dialect);
    this.valueColumnNameText = logicalValueColumnNameIdentifier.render(dialect);
    this.selectQuery = "select " + valueColumnNameText + " as id_val" + " from " + dialect.appendLockHint(LockMode.PESSIMISTIC_WRITE, tableNameText) + dialect.getForUpdateString();
    this.updateQuery = "update " + tableNameText + " set " + valueColumnNameText + "= ?" + " where " + valueColumnNameText + "=?";
    ExportableColumn valueColumn = new ExportableColumn(database, table, valueColumnNameText, LongType.INSTANCE);
    table.addColumn(valueColumn);
    table.addInitCommand(new InitCommand("insert into " + tableNameText + " values ( " + initialValue + " )"));
}
Also used : Table(org.hibernate.mapping.Table) InitCommand(org.hibernate.boot.model.relational.InitCommand) Dialect(org.hibernate.dialect.Dialect) ExportableColumn(org.hibernate.id.ExportableColumn) JdbcEnvironment(org.hibernate.engine.jdbc.env.spi.JdbcEnvironment) Namespace(org.hibernate.boot.model.relational.Namespace)

Aggregations

Namespace (org.hibernate.boot.model.relational.Namespace)2 Dialect (org.hibernate.dialect.Dialect)2 ExportableColumn (org.hibernate.id.ExportableColumn)2 Table (org.hibernate.mapping.Table)2 InitCommand (org.hibernate.boot.model.relational.InitCommand)1 JdbcEnvironment (org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)1 Column (org.hibernate.mapping.Column)1 PrimaryKey (org.hibernate.mapping.PrimaryKey)1