use of org.hibernate.dialect.Dialect in project hibernate-orm by hibernate.
the class IdentNode method resolveAsAlias.
private boolean resolveAsAlias() {
final String alias = getText();
// This is not actually a constant, but a reference to FROM element.
final FromElement element = getWalker().getCurrentFromClause().getFromElement(alias);
if (element == null) {
return false;
}
element.applyTreatAsDeclarations(getWalker().getTreatAsDeclarationsByPath(alias));
setType(SqlTokenTypes.ALIAS_REF);
setFromElement(element);
String[] columnExpressions = element.getIdentityColumns();
// determine whether to apply qualification (table alias) to the column(s)...
if (!isFromElementUpdateOrDeleteRoot(element)) {
if (StringHelper.isNotEmpty(element.getTableAlias())) {
// apparently we also need to check that they are not already qualified. Ugh!
columnExpressions = StringHelper.qualifyIfNot(element.getTableAlias(), columnExpressions);
}
}
final Dialect dialect = getWalker().getSessionFactoryHelper().getFactory().getDialect();
final boolean isInCount = getWalker().isInCount();
final boolean isInDistinctCount = isInCount && getWalker().isInCountDistinct();
final boolean isInNonDistinctCount = isInCount && !getWalker().isInCountDistinct();
final boolean isCompositeValue = columnExpressions.length > 1;
if (isCompositeValue) {
if (isInNonDistinctCount && !dialect.supportsTupleCounts()) {
// TODO: #supportsTupleCounts currently false for all Dialects -- could this be cleaned up?
setText(columnExpressions[0]);
} else {
String joinedFragment = String.join(", ", columnExpressions);
// avoid wrapping in parenthesis (explicit tuple treatment) if possible due to varied support for
// tuple syntax across databases..
final boolean shouldSkipWrappingInParenthesis = (isInDistinctCount && !dialect.requiresParensForTupleDistinctCounts()) || isInNonDistinctCount || getWalker().getCurrentTopLevelClauseType() == HqlSqlTokenTypes.ORDER || getWalker().getCurrentTopLevelClauseType() == HqlSqlTokenTypes.GROUP;
if (!shouldSkipWrappingInParenthesis) {
joinedFragment = "(" + joinedFragment + ")";
}
setText(joinedFragment);
}
return true;
} else if (columnExpressions.length > 0) {
setText(columnExpressions[0]);
return true;
}
return false;
}
use of org.hibernate.dialect.Dialect in project hibernate-orm by hibernate.
the class SchemaDropperImpl method generateDropCommands.
/**
* For testing...
*
* @param metadata The metadata for which to generate the creation commands.
*
* @return The generation commands
*/
public List<String> generateDropCommands(Metadata metadata, final boolean manageNamespaces) {
final JournalingGenerationTarget target = new JournalingGenerationTarget();
final ServiceRegistry serviceRegistry = ((MetadataImplementor) metadata).getMetadataBuildingOptions().getServiceRegistry();
final Dialect dialect = serviceRegistry.getService(JdbcEnvironment.class).getDialect();
final ExecutionOptions options = new ExecutionOptions() {
@Override
public boolean shouldManageNamespaces() {
return manageNamespaces;
}
@Override
public Map getConfigurationValues() {
return Collections.emptyMap();
}
@Override
public ExceptionHandler getExceptionHandler() {
return ExceptionHandlerHaltImpl.INSTANCE;
}
};
dropFromMetadata(metadata, options, dialect, FormatStyle.NONE.getFormatter(), target);
return target.commands;
}
use of org.hibernate.dialect.Dialect in project hibernate-orm by hibernate.
the class AbstractLoadPlanBasedLoader method prepareQueryStatement.
/**
* Obtain a <tt>PreparedStatement</tt> with all parameters pre-bound.
* Bind JDBC-style <tt>?</tt> parameters, named parameters, and
* limit parameters.
*/
protected final PreparedStatement prepareQueryStatement(final String sql, final QueryParameters queryParameters, final LimitHandler limitHandler, final boolean scroll, final SharedSessionContractImplementor session) throws SQLException, HibernateException {
final Dialect dialect = session.getJdbcServices().getJdbcEnvironment().getDialect();
final RowSelection selection = queryParameters.getRowSelection();
final boolean useLimit = LimitHelper.useLimit(limitHandler, selection);
final boolean hasFirstRow = LimitHelper.hasFirstRow(selection);
final boolean useLimitOffset = hasFirstRow && useLimit && limitHandler.supportsLimitOffset();
final boolean callable = queryParameters.isCallable();
final ScrollMode scrollMode = getScrollMode(scroll, hasFirstRow, useLimitOffset, queryParameters);
final PreparedStatement st = session.getJdbcCoordinator().getStatementPreparer().prepareQueryStatement(sql, callable, scrollMode);
try {
int col = 1;
// TODO: can we limit stored procedures ?!
col += limitHandler.bindLimitParametersAtStartOfQuery(selection, st, col);
if (callable) {
col = dialect.registerResultSetOutParameter((CallableStatement) st, col);
}
col += bindParameterValues(st, queryParameters, col, session);
col += limitHandler.bindLimitParametersAtEndOfQuery(selection, st, col);
limitHandler.setMaxRows(selection, st);
if (selection != null) {
if (selection.getTimeout() != null) {
st.setQueryTimeout(selection.getTimeout());
}
if (selection.getFetchSize() != null) {
st.setFetchSize(selection.getFetchSize());
}
}
// handle lock timeout...
final LockOptions lockOptions = queryParameters.getLockOptions();
if (lockOptions != null) {
if (lockOptions.getTimeOut() != LockOptions.WAIT_FOREVER) {
if (!dialect.supportsLockTimeouts()) {
if (log.isDebugEnabled()) {
log.debugf("Lock timeout [%s] requested but dialect reported to not support lock timeouts", lockOptions.getTimeOut());
}
} else if (dialect.isLockTimeoutParameterized()) {
st.setInt(col++, lockOptions.getTimeOut());
}
}
}
if (log.isTraceEnabled()) {
log.tracev("Bound [{0}] parameters total", col);
}
} catch (SQLException sqle) {
session.getJdbcCoordinator().getResourceRegistry().release(st);
session.getJdbcCoordinator().afterStatementExecution();
throw sqle;
} catch (HibernateException he) {
session.getJdbcCoordinator().getResourceRegistry().release(st);
session.getJdbcCoordinator().afterStatementExecution();
throw he;
}
return st;
}
use of org.hibernate.dialect.Dialect in project hibernate-orm by hibernate.
the class EntityLoadQueryDetails method applyRootReturnTableFragments.
/**
* Applies "table fragments" to the FROM-CLAUSE of the given SelectStatementBuilder for the given Loadable
*
* @param select The SELECT statement builder
*
* @see org.hibernate.persister.entity.OuterJoinLoadable#fromTableFragment(java.lang.String)
* @see org.hibernate.persister.entity.Joinable#fromJoinFragment(java.lang.String, boolean, boolean)
*/
protected void applyRootReturnTableFragments(SelectStatementBuilder select) {
final String fromTableFragment;
final String rootAlias = entityReferenceAliases.getTableAlias();
final OuterJoinLoadable outerJoinLoadable = (OuterJoinLoadable) getRootEntityReturn().getEntityPersister();
final Dialect dialect = getSessionFactory().getJdbcServices().getJdbcEnvironment().getDialect();
if (getQueryBuildingParameters().getLockOptions() != null) {
fromTableFragment = dialect.appendLockHint(getQueryBuildingParameters().getLockOptions(), outerJoinLoadable.fromTableFragment(rootAlias));
select.setLockOptions(getQueryBuildingParameters().getLockOptions());
} else if (getQueryBuildingParameters().getLockMode() != null) {
fromTableFragment = dialect.appendLockHint(getQueryBuildingParameters().getLockMode(), outerJoinLoadable.fromTableFragment(rootAlias));
select.setLockMode(getQueryBuildingParameters().getLockMode());
} else {
fromTableFragment = outerJoinLoadable.fromTableFragment(rootAlias);
}
select.appendFromClauseFragment(fromTableFragment + outerJoinLoadable.fromJoinFragment(rootAlias, true, true));
}
use of org.hibernate.dialect.Dialect in project jbosstools-hibernate by jbosstools.
the class DummyMetadataImplementorTest method testInstance.
@Test
public void testInstance() {
assertNotNull(DummyMetadataImplementor.INSTANCE);
StandardServiceRegistry serviceRegistry = DummyMetadataImplementor.INSTANCE.getMetadataBuildingOptions().getServiceRegistry();
JdbcServices jdbcServices = serviceRegistry.getService(JdbcServices.class);
Dialect dialect = jdbcServices.getDialect();
assertTrue(dialect instanceof DummyMetadataImplementor.DummyDialect);
}
Aggregations