Search in sources :

Example 21 with Namespace

use of org.hibernate.boot.model.relational.Namespace in project hibernate-orm by hibernate.

the class SequenceStructure method buildSequence.

protected void buildSequence(Database database) {
    final int sourceIncrementSize = getSourceIncrementSize();
    final Namespace namespace = database.locateNamespace(logicalQualifiedSequenceName.getCatalogName(), logicalQualifiedSequenceName.getSchemaName());
    Sequence sequence = namespace.locateSequence(logicalQualifiedSequenceName.getObjectName());
    if (sequence != null) {
        sequence.validate(initialValue, sourceIncrementSize);
    } else {
        sequence = namespace.createSequence(logicalQualifiedSequenceName.getObjectName(), initialValue, sourceIncrementSize);
    }
    this.sequenceName = database.getJdbcEnvironment().getQualifiedObjectNameFormatter().format(sequence.getName(), database.getJdbcEnvironment().getDialect());
}
Also used : Sequence(org.hibernate.boot.model.relational.Sequence) Namespace(org.hibernate.boot.model.relational.Namespace)

Example 22 with Namespace

use of org.hibernate.boot.model.relational.Namespace 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)22 Sequence (org.hibernate.boot.model.relational.Sequence)10 Table (org.hibernate.mapping.Table)10 Identifier (org.hibernate.boot.model.naming.Identifier)7 Test (org.junit.Test)7 MetadataSources (org.hibernate.boot.MetadataSources)5 JdbcEnvironment (org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)5 TestForIssue (org.hibernate.testing.TestForIssue)5 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)4 Column (org.hibernate.mapping.Column)4 DenormalizedTable (org.hibernate.mapping.DenormalizedTable)4 HashSet (java.util.HashSet)3 AuxiliaryDatabaseObject (org.hibernate.boot.model.relational.AuxiliaryDatabaseObject)3 Database (org.hibernate.boot.model.relational.Database)3 Dialect (org.hibernate.dialect.Dialect)3 Iterator (java.util.Iterator)2 LinkedHashSet (java.util.LinkedHashSet)2 ForeignKey (javax.persistence.ForeignKey)2 InitCommand (org.hibernate.boot.model.relational.InitCommand)2 InLineViewSource (org.hibernate.boot.model.source.spi.InLineViewSource)2