Search in sources :

Example 51 with Dialect

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

the class LikeExpression method toSqlString.

@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {
    final Dialect dialect = criteriaQuery.getFactory().getDialect();
    final String[] columns = criteriaQuery.findColumns(propertyName, criteria);
    if (columns.length != 1) {
        throw new HibernateException("Like may only be used with single-column properties");
    }
    final String escape = escapeChar == null ? "" : " escape \'" + escapeChar + "\'";
    final String column = columns[0];
    if (ignoreCase) {
        if (dialect.supportsCaseInsensitiveLike()) {
            return column + " " + dialect.getCaseInsensitiveLike() + " ?" + escape;
        } else {
            return dialect.getLowercaseFunction() + '(' + column + ')' + " like ?" + escape;
        }
    } else {
        return column + " like ?" + escape;
    }
}
Also used : HibernateException(org.hibernate.HibernateException) Dialect(org.hibernate.dialect.Dialect)

Example 52 with Dialect

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

the class AbstractMultiTableBulkIdStrategyImpl method buildIdTableDropStatement.

protected String buildIdTableDropStatement(Table idTable, JdbcServices jdbcServices) {
    final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
    final Dialect dialect = jdbcEnvironment.getDialect();
    return getIdTableSupport().getDropIdTableCommand() + " " + jdbcEnvironment.getQualifiedObjectNameFormatter().format(idTable.getQualifiedTableName(), dialect);
}
Also used : Dialect(org.hibernate.dialect.Dialect) JdbcEnvironment(org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)

Example 53 with Dialect

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

the class HibernateSchemaManagementTool method resolveJdbcContext.

public JdbcContext resolveJdbcContext(Map configurationValues) {
    final JdbcContextBuilder jdbcContextBuilder = new JdbcContextBuilder(serviceRegistry);
    // see if a specific connection has been provided
    final Connection providedConnection = (Connection) configurationValues.get(HBM2DDL_CONNECTION);
    if (providedConnection != null) {
        jdbcContextBuilder.jdbcConnectionAccess = new JdbcConnectionAccessProvidedConnectionImpl(providedConnection);
    }
    // see if a specific Dialect override has been provided...
    final String explicitDbName = (String) configurationValues.get(AvailableSettings.HBM2DDL_DB_NAME);
    if (StringHelper.isNotEmpty(explicitDbName)) {
        final String explicitDbMajor = (String) configurationValues.get(AvailableSettings.HBM2DDL_DB_MAJOR_VERSION);
        final String explicitDbMinor = (String) configurationValues.get(AvailableSettings.HBM2DDL_DB_MINOR_VERSION);
        final Dialect indicatedDialect = serviceRegistry.getService(DialectResolver.class).resolveDialect(new DialectResolutionInfo() {

            @Override
            public String getDatabaseName() {
                return explicitDbName;
            }

            @Override
            public int getDatabaseMajorVersion() {
                return StringHelper.isEmpty(explicitDbMajor) ? NO_VERSION : Integer.parseInt(explicitDbMajor);
            }

            @Override
            public int getDatabaseMinorVersion() {
                return StringHelper.isEmpty(explicitDbMinor) ? NO_VERSION : Integer.parseInt(explicitDbMinor);
            }

            @Override
            public String getDriverName() {
                return null;
            }

            @Override
            public int getDriverMajorVersion() {
                return NO_VERSION;
            }

            @Override
            public int getDriverMinorVersion() {
                return NO_VERSION;
            }
        });
        if (indicatedDialect == null) {
            log.debugf("Unable to resolve indicated Dialect resolution info (%s, %s, %s)", explicitDbName, explicitDbMajor, explicitDbMinor);
        } else {
            jdbcContextBuilder.dialect = indicatedDialect;
        }
    }
    return jdbcContextBuilder.buildJdbcContext();
}
Also used : DialectResolver(org.hibernate.engine.jdbc.dialect.spi.DialectResolver) JdbcConnectionAccessProvidedConnectionImpl(org.hibernate.tool.schema.internal.exec.JdbcConnectionAccessProvidedConnectionImpl) Connection(java.sql.Connection) Dialect(org.hibernate.dialect.Dialect) DialectResolutionInfo(org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo)

Example 54 with Dialect

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

the class SchemaDropperImpl method applyConstraintDropping.

private void applyConstraintDropping(Namespace namespace, Metadata metadata, Formatter formatter, ExecutionOptions options, GenerationTarget... targets) {
    final Dialect dialect = metadata.getDatabase().getJdbcEnvironment().getDialect();
    if (!dialect.dropConstraints()) {
        return;
    }
    for (Table table : namespace.getTables()) {
        if (!table.isPhysicalTable()) {
            continue;
        }
        if (!schemaFilter.includeTable(table)) {
            continue;
        }
        final Iterator fks = table.getForeignKeyIterator();
        while (fks.hasNext()) {
            final ForeignKey foreignKey = (ForeignKey) fks.next();
            applySqlStrings(dialect.getForeignKeyExporter().getSqlDropStrings(foreignKey, metadata), formatter, options, targets);
        }
    }
}
Also used : Table(org.hibernate.mapping.Table) Dialect(org.hibernate.dialect.Dialect) Iterator(java.util.Iterator) ForeignKey(org.hibernate.mapping.ForeignKey)

Example 55 with Dialect

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

the class AbstractSequenceInformationExtractorTest method testSequenceGenerationExtractor.

@Test
public void testSequenceGenerationExtractor() {
    final Dialect dialect = getDialect();
    assertThat(dialect.getQuerySequencesString(), is(expectedQuerySequencesString()));
    assertThat(dialect.getSequenceInformationExtractor(), instanceOf(expectedSequenceInformationExtractor()));
}
Also used : Dialect(org.hibernate.dialect.Dialect) Test(org.junit.Test)

Aggregations

Dialect (org.hibernate.dialect.Dialect)80 DialectFactory (org.hibernate.engine.jdbc.dialect.spi.DialectFactory)19 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)18 Column (org.hibernate.mapping.Column)14 SQLException (java.sql.SQLException)13 DialectResolutionInfo (org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo)12 JdbcServices (org.hibernate.engine.jdbc.spi.JdbcServices)12 Configuration (org.hibernate.cfg.Configuration)11 ServiceRegistry (org.hibernate.service.ServiceRegistry)11 Properties (java.util.Properties)10 HibernateException (org.hibernate.HibernateException)10 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)10 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)9 DatabaseMetaDataDialectResolutionInfoAdapter (org.hibernate.engine.jdbc.dialect.spi.DatabaseMetaDataDialectResolutionInfoAdapter)9 DialectResolutionInfoSource (org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfoSource)9 HibernateException (org.jboss.tools.hibernate.runtime.spi.HibernateException)9 MetaDataDialect (org.hibernate.cfg.reveng.dialect.MetaDataDialect)8 Test (org.junit.jupiter.api.Test)8 JdbcEnvironment (org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)7 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)6