Search in sources :

Example 6 with Dialect

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

the class BasicDialectResolver method resolveDialect.

@Override
public final Dialect resolveDialect(DialectResolutionInfo info) {
    final String databaseName = info.getDatabaseName();
    final int databaseMajorVersion = info.getDatabaseMajorVersion();
    final int databaseMinorVersion = info.getDatabaseMinorVersion();
    if (nameToMatch.equalsIgnoreCase(databaseName) && (majorVersionToMatch == NO_VERSION || majorVersionToMatch == databaseMajorVersion) && (minorVersionToMatch == NO_VERSION || majorVersionToMatch == databaseMinorVersion)) {
        try {
            return (Dialect) dialectClass.newInstance();
        } catch (HibernateException e) {
            // conceivable that the dialect ctor could throw HibernateExceptions, so don't re-wrap
            throw e;
        } catch (Throwable t) {
            throw new HibernateException("Could not instantiate specified Dialect class [" + dialectClass.getName() + "]", t);
        }
    }
    return null;
}
Also used : HibernateException(org.hibernate.HibernateException) Dialect(org.hibernate.dialect.Dialect)

Example 7 with Dialect

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

the class JoinProcessor method processDynamicFilterParameters.

public static void processDynamicFilterParameters(final String sqlFragment, final ParameterContainer container, final HqlSqlWalker walker) {
    if (walker.getEnabledFilters().isEmpty() && (!hasDynamicFilterParam(sqlFragment)) && (!(hasCollectionFilterParam(sqlFragment)))) {
        return;
    }
    Dialect dialect = walker.getSessionFactoryHelper().getFactory().getDialect();
    String symbols = ParserHelper.HQL_SEPARATORS + dialect.openQuote() + dialect.closeQuote();
    StringTokenizer tokens = new StringTokenizer(sqlFragment, symbols, true);
    StringBuilder result = new StringBuilder();
    while (tokens.hasMoreTokens()) {
        final String token = tokens.nextToken();
        if (token.startsWith(ParserHelper.HQL_VARIABLE_PREFIX)) {
            final String filterParameterName = token.substring(1);
            final String[] parts = LoadQueryInfluencers.parseFilterParameterName(filterParameterName);
            final FilterImpl filter = (FilterImpl) walker.getEnabledFilters().get(parts[0]);
            final Object value = filter.getParameter(parts[1]);
            final Type type = filter.getFilterDefinition().getParameterType(parts[1]);
            final String typeBindFragment = StringHelper.join(",", ArrayHelper.fillArray("?", type.getColumnSpan(walker.getSessionFactoryHelper().getFactory())));
            final String bindFragment;
            if (value != null && Collection.class.isInstance(value)) {
                bindFragment = StringHelper.join(",", ArrayHelper.fillArray(typeBindFragment, ((Collection) value).size()));
            } else {
                bindFragment = typeBindFragment;
            }
            result.append(bindFragment);
            container.addEmbeddedParameter(new DynamicFilterParameterSpecification(parts[0], parts[1], type));
        } else {
            result.append(token);
        }
    }
    container.setText(result.toString());
}
Also used : StringTokenizer(java.util.StringTokenizer) JoinType(org.hibernate.sql.JoinType) Type(org.hibernate.type.Type) FilterImpl(org.hibernate.internal.FilterImpl) Dialect(org.hibernate.dialect.Dialect) Collection(java.util.Collection) DynamicFilterParameterSpecification(org.hibernate.param.DynamicFilterParameterSpecification)

Example 8 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 9 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 10 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)

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