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 + " )"));
}
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;
}
}
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);
}
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();
}
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);
}
Aggregations