use of org.hibernate.sql.JoinFragment in project hibernate-orm by hibernate.
the class AbstractEntityPersister method renderSelect.
protected String renderSelect(final int[] tableNumbers, final int[] columnNumbers, final int[] formulaNumbers) {
//get 'em in the right order (not that it really matters)
Arrays.sort(tableNumbers);
//render the where and from parts
int drivingTable = tableNumbers[0];
final String drivingAlias = generateTableAlias(getRootAlias(), drivingTable);
//we *could* regerate this inside each called method!
final String where = createWhereByKey(drivingTable, drivingAlias);
final String from = createFrom(drivingTable, drivingAlias);
//now render the joins
JoinFragment jf = createJoin(tableNumbers, drivingAlias);
//now render the select clause
SelectFragment selectFragment = createSelect(columnNumbers, formulaNumbers);
//now tie it all together
Select select = new Select(getFactory().getDialect());
select.setSelectClause(selectFragment.toFragmentString().substring(2));
select.setFromClause(from);
select.setWhereClause(where);
select.setOuterJoins(jf.toFromFragmentString(), jf.toWhereFragmentString());
if (getFactory().getSessionFactoryOptions().isCommentsEnabled()) {
select.setComment("sequential select " + getEntityName());
}
return select.toStatementString();
}
use of org.hibernate.sql.JoinFragment in project hibernate-orm by hibernate.
the class OneToManyJoinWalker method initStatementString.
private void initStatementString(final OuterJoinLoadable elementPersister, final String alias, final int batchSize, final String subquery) throws MappingException {
final int joins = countEntityPersisters(associations);
suffixes = BasicLoader.generateSuffixes(joins + 1);
final int collectionJoins = countCollectionPersisters(associations) + 1;
collectionSuffixes = BasicLoader.generateSuffixes(joins + 1, collectionJoins);
StringBuilder whereString = whereString(alias, oneToManyPersister.getKeyColumnNames(), subquery, batchSize);
String filter = oneToManyPersister.filterFragment(alias, getLoadQueryInfluencers().getEnabledFilters());
whereString.insert(0, StringHelper.moveAndToBeginning(filter));
JoinFragment ojf = mergeOuterJoins(associations);
Select select = new Select(getDialect()).setSelectClause(oneToManyPersister.selectFragment(null, null, alias, suffixes[joins], collectionSuffixes[0], true) + selectString(associations)).setFromClause(elementPersister.fromTableFragment(alias) + elementPersister.fromJoinFragment(alias, true, true)).setWhereClause(whereString.toString()).setOuterJoins(ojf.toFromFragmentString(), ojf.toWhereFragmentString() + elementPersister.whereJoinFragment(alias, true, true));
select.setOrderByClause(orderBy(associations, oneToManyPersister.getSQLOrderByString(alias)));
if (getFactory().getSessionFactoryOptions().isCommentsEnabled()) {
select.setComment("load one-to-many " + oneToManyPersister.getRole());
}
sql = select.toStatementString();
}
use of org.hibernate.sql.JoinFragment in project hibernate-orm by hibernate.
the class JoinProcessor method addJoinNodes.
private void addJoinNodes(QueryNode query, JoinSequence join, FromElement fromElement) {
JoinFragment joinFragment = join.toJoinFragment(walker.getEnabledFilters(), fromElement.useFromFragment() || fromElement.isDereferencedBySuperclassOrSubclassProperty(), fromElement.getWithClauseFragment());
String frag = joinFragment.toFromFragmentString();
String whereFrag = joinFragment.toWhereFragmentString();
// to FROM_FRAGMENT
if (fromElement.getType() == JOIN_FRAGMENT && (join.isThetaStyle() || StringHelper.isNotEmpty(whereFrag))) {
fromElement.setType(FROM_FRAGMENT);
// this is used during SqlGenerator processing
fromElement.getJoinSequence().setUseThetaStyle(true);
}
// If there is a FROM fragment and the FROM element is an explicit, then add the from part.
if (fromElement.useFromFragment() || (fromElement.getFromClause().isSubQuery() && fromElement.isDereferencedBySuperclassOrSubclassProperty())) /*&& StringHelper.isNotEmpty( frag )*/
{
String fromFragment = processFromFragment(frag, join).trim();
LOG.debugf("Using FROM fragment [%s]", fromFragment);
processDynamicFilterParameters(fromFragment, fromElement, walker);
}
syntheticAndFactory.addWhereFragment(joinFragment, whereFrag, query, fromElement, walker);
}
use of org.hibernate.sql.JoinFragment in project hibernate-orm by hibernate.
the class AbstractEntityPersister method createJoin.
protected JoinFragment createJoin(int[] tableNumbers, String drivingAlias) {
final String[] keyCols = StringHelper.qualify(drivingAlias, getSubclassTableKeyColumns(tableNumbers[0]));
final JoinFragment jf = getFactory().getDialect().createOuterJoinFragment();
// IMPL NOTE : notice that we skip the first table; it is the driving table!
for (int i = 1; i < tableNumbers.length; i++) {
final int j = tableNumbers[i];
jf.addJoin(getSubclassTableName(j), generateTableAlias(getRootAlias(), j), keyCols, getSubclassTableKeyColumns(j), isInverseSubclassTable(j) || isNullableSubclassTable(j) ? JoinType.LEFT_OUTER_JOIN : JoinType.INNER_JOIN);
}
return jf;
}
Aggregations