Search in sources :

Example 26 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 27 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 28 with Dialect

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

the class AbstractTableBasedBulkIdHandler method generateIdInsertSelect.

/**
	 * Generate the {@code INSERT}-{@code SELECT} statement for holding matching ids.  This is the
	 * {@code INSERT} used to populate the bulk-id table with ids matching the restrictions defined in the
	 * original {@code WHERE} clause
	 *
	 * @param tableAlias The table alias to use for the entity
	 * @param whereClause The processed representation for the user-defined {@code WHERE} clause.
	 *
	 * @return The {@code INSERT}-{@code SELECT} for populating the bulk-id table.
	 */
protected String generateIdInsertSelect(String tableAlias, IdTableInfo idTableInfo, ProcessedWhereClause whereClause) {
    final Dialect dialect = sessionFactory.getJdbcServices().getJdbcEnvironment().getDialect();
    final Select select = generateIdSelect(tableAlias, whereClause);
    InsertSelect insert = new InsertSelect(dialect);
    if (sessionFactory.getSessionFactoryOptions().isCommentsEnabled()) {
        insert.setComment("insert-select for " + getTargetedQueryable().getEntityName() + " ids");
    }
    insert.setTableName(idTableInfo.getQualifiedIdTableName());
    insert.setSelect(select);
    return insert.toStatementString();
}
Also used : InsertSelect(org.hibernate.sql.InsertSelect) Dialect(org.hibernate.dialect.Dialect) Select(org.hibernate.sql.Select) InsertSelect(org.hibernate.sql.InsertSelect)

Example 29 with Dialect

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

the class LiteralProcessor method setConstantValue.

private void setConstantValue(DotNode node, String text, Object value) {
    if (LOG.isDebugEnabled()) {
        LOG.debugf("setConstantValue() %s -> %s %s", text, value, value.getClass().getName());
    }
    // Chop off the rest of the tree.
    node.setFirstChild(null);
    if (value instanceof String) {
        node.setType(SqlTokenTypes.QUOTED_STRING);
    } else if (value instanceof Character) {
        node.setType(SqlTokenTypes.QUOTED_STRING);
    } else if (value instanceof Byte) {
        node.setType(SqlTokenTypes.NUM_INT);
    } else if (value instanceof Short) {
        node.setType(SqlTokenTypes.NUM_INT);
    } else if (value instanceof Integer) {
        node.setType(SqlTokenTypes.NUM_INT);
    } else if (value instanceof Long) {
        node.setType(SqlTokenTypes.NUM_LONG);
    } else if (value instanceof Double) {
        node.setType(SqlTokenTypes.NUM_DOUBLE);
    } else if (value instanceof Float) {
        node.setType(SqlTokenTypes.NUM_FLOAT);
    } else {
        node.setType(SqlTokenTypes.CONSTANT);
    }
    Type type;
    try {
        type = walker.getSessionFactoryHelper().getFactory().getTypeResolver().heuristicType(value.getClass().getName());
    } catch (MappingException me) {
        throw new QueryException(me);
    }
    if (type == null) {
        throw new QueryException(QueryTranslator.ERROR_CANNOT_DETERMINE_TYPE + node.getText());
    }
    try {
        LiteralType literalType = (LiteralType) type;
        Dialect dialect = walker.getSessionFactoryHelper().getFactory().getDialect();
        //noinspection unchecked
        node.setText(literalType.objectToSQLString(value, dialect));
    } catch (Exception e) {
        throw new QueryException(QueryTranslator.ERROR_CANNOT_FORMAT_LITERAL + node.getText(), e);
    }
    node.setDataType(type);
    node.setResolvedConstant(text);
}
Also used : LiteralType(org.hibernate.type.LiteralType) SemanticException(antlr.SemanticException) InvalidPathException(org.hibernate.hql.internal.ast.InvalidPathException) MappingException(org.hibernate.MappingException) HibernateException(org.hibernate.HibernateException) QueryException(org.hibernate.QueryException) MappingException(org.hibernate.MappingException) BigInteger(java.math.BigInteger) LiteralType(org.hibernate.type.LiteralType) Type(org.hibernate.type.Type) QueryException(org.hibernate.QueryException) Dialect(org.hibernate.dialect.Dialect)

Example 30 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)

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