use of org.hibernate.dialect.Dialect in project hibernate-orm by hibernate.
the class BasicDialectResolver method resolveDialect.
@Override
public final Dialect resolveDialect(DialectResolutionInfo info) {
final String databaseName = info.getDatabaseName();
final int databaseMajorVersion = info.getDatabaseMajorVersion();
final int databaseMinorVersion = info.getDatabaseMinorVersion();
if (nameToMatch.equalsIgnoreCase(databaseName) && (majorVersionToMatch == NO_VERSION || majorVersionToMatch == databaseMajorVersion) && (minorVersionToMatch == NO_VERSION || majorVersionToMatch == databaseMinorVersion)) {
try {
return (Dialect) dialectClass.newInstance();
} catch (HibernateException e) {
// conceivable that the dialect ctor could throw HibernateExceptions, so don't re-wrap
throw e;
} catch (Throwable t) {
throw new HibernateException("Could not instantiate specified Dialect class [" + dialectClass.getName() + "]", t);
}
}
return null;
}
use of org.hibernate.dialect.Dialect in project hibernate-orm by hibernate.
the class JoinProcessor method processDynamicFilterParameters.
public static void processDynamicFilterParameters(final String sqlFragment, final ParameterContainer container, final HqlSqlWalker walker) {
if (walker.getEnabledFilters().isEmpty() && (!hasDynamicFilterParam(sqlFragment)) && (!(hasCollectionFilterParam(sqlFragment)))) {
return;
}
Dialect dialect = walker.getSessionFactoryHelper().getFactory().getDialect();
String symbols = ParserHelper.HQL_SEPARATORS + dialect.openQuote() + dialect.closeQuote();
StringTokenizer tokens = new StringTokenizer(sqlFragment, symbols, true);
StringBuilder result = new StringBuilder();
while (tokens.hasMoreTokens()) {
final String token = tokens.nextToken();
if (token.startsWith(ParserHelper.HQL_VARIABLE_PREFIX)) {
final String filterParameterName = token.substring(1);
final String[] parts = LoadQueryInfluencers.parseFilterParameterName(filterParameterName);
final FilterImpl filter = (FilterImpl) walker.getEnabledFilters().get(parts[0]);
final Object value = filter.getParameter(parts[1]);
final Type type = filter.getFilterDefinition().getParameterType(parts[1]);
final String typeBindFragment = StringHelper.join(",", ArrayHelper.fillArray("?", type.getColumnSpan(walker.getSessionFactoryHelper().getFactory())));
final String bindFragment;
if (value != null && Collection.class.isInstance(value)) {
bindFragment = StringHelper.join(",", ArrayHelper.fillArray(typeBindFragment, ((Collection) value).size()));
} else {
bindFragment = typeBindFragment;
}
result.append(bindFragment);
container.addEmbeddedParameter(new DynamicFilterParameterSpecification(parts[0], parts[1], type));
} else {
result.append(token);
}
}
container.setText(result.toString());
}
use of org.hibernate.dialect.Dialect in project hibernate-orm by hibernate.
the class AbstractMultiTableBulkIdStrategyImpl method buildIdTableCreateStatement.
protected String buildIdTableCreateStatement(Table idTable, JdbcServices jdbcServices, MetadataImplementor metadata) {
final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
final Dialect dialect = jdbcEnvironment.getDialect();
StringBuilder buffer = new StringBuilder(getIdTableSupport().getCreateIdTableCommand()).append(' ').append(jdbcEnvironment.getQualifiedObjectNameFormatter().format(idTable.getQualifiedTableName(), dialect)).append(" (");
Iterator itr = idTable.getColumnIterator();
while (itr.hasNext()) {
final Column column = (Column) itr.next();
buffer.append(column.getQuotedName(dialect)).append(' ');
buffer.append(column.getSqlType(dialect, metadata));
if (column.isNullable()) {
buffer.append(dialect.getNullColumnString());
} else {
buffer.append(" not null");
}
if (itr.hasNext()) {
buffer.append(", ");
}
}
buffer.append(") ");
if (getIdTableSupport().getCreateIdTableStatementOptions() != null) {
buffer.append(getIdTableSupport().getCreateIdTableStatementOptions());
}
return buffer.toString();
}
use of org.hibernate.dialect.Dialect in project hibernate-orm by hibernate.
the class AbstractTableBasedBulkIdHandler method generateIdSelect.
protected Select generateIdSelect(String tableAlias, ProcessedWhereClause whereClause) {
final Dialect dialect = sessionFactory.getJdbcServices().getJdbcEnvironment().getDialect();
final Select select = new Select(dialect);
final SelectValues selectClause = new SelectValues(dialect).addColumns(tableAlias, getTargetedQueryable().getIdentifierColumnNames(), getTargetedQueryable().getIdentifierColumnNames());
addAnyExtraIdSelectValues(selectClause);
select.setSelectClause(selectClause.render());
String rootTableName = getTargetedQueryable().getTableName();
String fromJoinFragment = getTargetedQueryable().fromJoinFragment(tableAlias, true, false);
String whereJoinFragment = getTargetedQueryable().whereJoinFragment(tableAlias, true, false);
select.setFromClause(rootTableName + ' ' + tableAlias + fromJoinFragment);
if (whereJoinFragment == null) {
whereJoinFragment = "";
} else {
whereJoinFragment = whereJoinFragment.trim();
if (whereJoinFragment.startsWith("and")) {
whereJoinFragment = whereJoinFragment.substring(4);
}
}
if (whereClause.getUserWhereClauseFragment().length() > 0) {
if (whereJoinFragment.length() > 0) {
whereJoinFragment += " and ";
}
}
select.setWhereClause(whereJoinFragment + whereClause.getUserWhereClauseFragment());
return select;
}
use of org.hibernate.dialect.Dialect in project hibernate-orm by hibernate.
the class SequenceGenerator method registerExportables.
@Override
public void registerExportables(Database database) {
final Namespace namespace = database.locateNamespace(logicalQualifiedSequenceName.getCatalogName(), logicalQualifiedSequenceName.getSchemaName());
Sequence sequence = namespace.locateSequence(logicalQualifiedSequenceName.getObjectName());
if (sequence != null) {
sequence.validate(1, 1);
} else {
sequence = namespace.createSequence(logicalQualifiedSequenceName.getObjectName(), 1, 1);
}
final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment();
final Dialect dialect = jdbcEnvironment.getDialect();
this.sequenceName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(sequence.getName(), dialect);
this.sql = jdbcEnvironment.getDialect().getSequenceNextValString(sequenceName);
}
Aggregations