Search in sources :

Example 11 with Dialect

use of org.hibernate.dialect.Dialect in project hibernate-orm by hibernate.

the class AbstractMultiTableBulkIdStrategyImpl method buildIdTableCreateStatement.

protected String buildIdTableCreateStatement(Table idTable, JdbcServices jdbcServices, MetadataImplementor metadata) {
    final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
    final Dialect dialect = jdbcEnvironment.getDialect();
    StringBuilder buffer = new StringBuilder(getIdTableSupport().getCreateIdTableCommand()).append(' ').append(jdbcEnvironment.getQualifiedObjectNameFormatter().format(idTable.getQualifiedTableName(), dialect)).append(" (");
    Iterator itr = idTable.getColumnIterator();
    while (itr.hasNext()) {
        final Column column = (Column) itr.next();
        buffer.append(column.getQuotedName(dialect)).append(' ');
        buffer.append(column.getSqlType(dialect, metadata));
        if (column.isNullable()) {
            buffer.append(dialect.getNullColumnString());
        } else {
            buffer.append(" not null");
        }
        if (itr.hasNext()) {
            buffer.append(", ");
        }
    }
    buffer.append(") ");
    if (getIdTableSupport().getCreateIdTableStatementOptions() != null) {
        buffer.append(getIdTableSupport().getCreateIdTableStatementOptions());
    }
    return buffer.toString();
}
Also used : Column(org.hibernate.mapping.Column) Dialect(org.hibernate.dialect.Dialect) Iterator(java.util.Iterator) JdbcEnvironment(org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)

Example 12 with Dialect

use of org.hibernate.dialect.Dialect in project hibernate-orm by hibernate.

the class AbstractTableBasedBulkIdHandler method generateIdSelect.

protected Select generateIdSelect(String tableAlias, ProcessedWhereClause whereClause) {
    final Dialect dialect = sessionFactory.getJdbcServices().getJdbcEnvironment().getDialect();
    final Select select = new Select(dialect);
    final SelectValues selectClause = new SelectValues(dialect).addColumns(tableAlias, getTargetedQueryable().getIdentifierColumnNames(), getTargetedQueryable().getIdentifierColumnNames());
    addAnyExtraIdSelectValues(selectClause);
    select.setSelectClause(selectClause.render());
    String rootTableName = getTargetedQueryable().getTableName();
    String fromJoinFragment = getTargetedQueryable().fromJoinFragment(tableAlias, true, false);
    String whereJoinFragment = getTargetedQueryable().whereJoinFragment(tableAlias, true, false);
    select.setFromClause(rootTableName + ' ' + tableAlias + fromJoinFragment);
    if (whereJoinFragment == null) {
        whereJoinFragment = "";
    } else {
        whereJoinFragment = whereJoinFragment.trim();
        if (whereJoinFragment.startsWith("and")) {
            whereJoinFragment = whereJoinFragment.substring(4);
        }
    }
    if (whereClause.getUserWhereClauseFragment().length() > 0) {
        if (whereJoinFragment.length() > 0) {
            whereJoinFragment += " and ";
        }
    }
    select.setWhereClause(whereJoinFragment + whereClause.getUserWhereClauseFragment());
    return select;
}
Also used : Dialect(org.hibernate.dialect.Dialect) Select(org.hibernate.sql.Select) InsertSelect(org.hibernate.sql.InsertSelect) SelectValues(org.hibernate.sql.SelectValues)

Example 13 with Dialect

use of org.hibernate.dialect.Dialect in project hibernate-orm by hibernate.

the class SequenceGenerator method registerExportables.

@Override
public void registerExportables(Database database) {
    final Namespace namespace = database.locateNamespace(logicalQualifiedSequenceName.getCatalogName(), logicalQualifiedSequenceName.getSchemaName());
    Sequence sequence = namespace.locateSequence(logicalQualifiedSequenceName.getObjectName());
    if (sequence != null) {
        sequence.validate(1, 1);
    } else {
        sequence = namespace.createSequence(logicalQualifiedSequenceName.getObjectName(), 1, 1);
    }
    final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment();
    final Dialect dialect = jdbcEnvironment.getDialect();
    this.sequenceName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(sequence.getName(), dialect);
    this.sql = jdbcEnvironment.getDialect().getSequenceNextValString(sequenceName);
}
Also used : Dialect(org.hibernate.dialect.Dialect) Sequence(org.hibernate.boot.model.relational.Sequence) JdbcEnvironment(org.hibernate.engine.jdbc.env.spi.JdbcEnvironment) Namespace(org.hibernate.boot.model.relational.Namespace)

Example 14 with Dialect

use of org.hibernate.dialect.Dialect in project hibernate-orm by hibernate.

the class SequenceStyleGenerator method configure.

// Configurable implementation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@Override
public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException {
    final JdbcEnvironment jdbcEnvironment = serviceRegistry.getService(JdbcEnvironment.class);
    final Dialect dialect = jdbcEnvironment.getDialect();
    this.identifierType = type;
    boolean forceTableUse = ConfigurationHelper.getBoolean(FORCE_TBL_PARAM, params, false);
    final QualifiedName sequenceName = determineSequenceName(params, dialect, jdbcEnvironment);
    final int initialValue = determineInitialValue(params);
    int incrementSize = determineIncrementSize(params);
    final String optimizationStrategy = determineOptimizationStrategy(params, incrementSize);
    incrementSize = determineAdjustedIncrementSize(optimizationStrategy, incrementSize);
    if (dialect.supportsSequences() && !forceTableUse) {
        if (!dialect.supportsPooledSequences() && OptimizerFactory.isPooledOptimizer(optimizationStrategy)) {
            forceTableUse = true;
            LOG.forcingTableUse();
        }
    }
    this.databaseStructure = buildDatabaseStructure(type, params, jdbcEnvironment, forceTableUse, sequenceName, initialValue, incrementSize);
    this.optimizer = OptimizerFactory.buildOptimizer(optimizationStrategy, identifierType.getReturnedClass(), incrementSize, ConfigurationHelper.getInt(INITIAL_PARAM, params, -1));
    this.databaseStructure.prepare(optimizer);
}
Also used : QualifiedName(org.hibernate.boot.model.relational.QualifiedName) Dialect(org.hibernate.dialect.Dialect) JdbcEnvironment(org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)

Example 15 with Dialect

use of org.hibernate.dialect.Dialect 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)

Aggregations

Dialect (org.hibernate.dialect.Dialect)45 HibernateException (org.hibernate.HibernateException)9 JdbcEnvironment (org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)7 PostgreSQL81Dialect (org.hibernate.dialect.PostgreSQL81Dialect)4 RowSelection (org.hibernate.engine.spi.RowSelection)4 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)4 Connection (java.sql.Connection)3 SQLException (java.sql.SQLException)3 Iterator (java.util.Iterator)3 Map (java.util.Map)3 H2Dialect (org.hibernate.dialect.H2Dialect)3 DialectResolutionInfo (org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo)3 Column (org.hibernate.mapping.Column)3 SpatialDialect (org.hibernate.spatial.SpatialDialect)3 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)2 AuditEventStage (com.evolveum.midpoint.audit.api.AuditEventStage)2 AuditEventType (com.evolveum.midpoint.audit.api.AuditEventType)2 AuditResultHandler (com.evolveum.midpoint.audit.api.AuditResultHandler)2 AuditService (com.evolveum.midpoint.audit.api.AuditService)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2