Search in sources :

Example 36 with Dialect

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

Example 37 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 38 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 39 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 40 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)

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