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