use of org.hibernate.sql.SelectFragment in project hibernate-orm by hibernate.
the class BasicCollectionPersister method manyToManySelectFragment.
private String manyToManySelectFragment(Joinable rhs, String rhsAlias, String lhsAlias, String collectionSuffix) {
SelectFragment frag = generateSelectFragment(lhsAlias, collectionSuffix);
String[] elementColumnNames = rhs.getKeyColumnNames();
frag.addColumns(rhsAlias, elementColumnNames, elementColumnAliases);
appendIndexColumns(frag, lhsAlias);
appendIdentifierColumns(frag, lhsAlias);
return frag.toFragmentString().substring(//strip leading ','
2);
}
use of org.hibernate.sql.SelectFragment in project hibernate-orm by hibernate.
the class AbstractCollectionPersister method selectFragment.
/**
* Generate a list of collection index, key and element columns
*/
@Override
public String selectFragment(String alias, String columnSuffix) {
SelectFragment frag = generateSelectFragment(alias, columnSuffix);
appendElementColumns(frag, alias);
appendIndexColumns(frag, alias);
appendIdentifierColumns(frag, alias);
return frag.toFragmentString().substring(// strip leading ','
2);
}
use of org.hibernate.sql.SelectFragment 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.SelectFragment in project hibernate-orm by hibernate.
the class AbstractEntityPersister method generateIdByUniqueKeySelectString.
protected String generateIdByUniqueKeySelectString(String uniquePropertyName) {
Select select = new Select(getFactory().getDialect());
if (getFactory().getSessionFactoryOptions().isCommentsEnabled()) {
select.setComment("resolve id by unique property [" + getEntityName() + "." + uniquePropertyName + "]");
}
final String rooAlias = getRootAlias();
select.setFromClause(fromTableFragment(rooAlias) + fromJoinFragment(rooAlias, true, false));
SelectFragment selectFragment = new SelectFragment();
selectFragment.addColumns(rooAlias, getIdentifierColumnNames(), getIdentifierAliases());
select.setSelectClause(selectFragment);
StringBuilder whereClauseBuffer = new StringBuilder();
final int uniquePropertyIndex = getSubclassPropertyIndex(uniquePropertyName);
final String uniquePropertyTableAlias = generateTableAlias(rooAlias, getSubclassPropertyTableNumber(uniquePropertyIndex));
String sep = "";
for (String columnTemplate : getSubclassPropertyColumnReaderTemplateClosure()[uniquePropertyIndex]) {
if (columnTemplate == null) {
continue;
}
final String columnReference = StringHelper.replace(columnTemplate, Template.TEMPLATE, uniquePropertyTableAlias);
whereClauseBuffer.append(sep).append(columnReference).append("=?");
sep = " and ";
}
for (String formulaTemplate : getSubclassPropertyFormulaTemplateClosure()[uniquePropertyIndex]) {
if (formulaTemplate == null) {
continue;
}
final String formulaReference = StringHelper.replace(formulaTemplate, Template.TEMPLATE, uniquePropertyTableAlias);
whereClauseBuffer.append(sep).append(formulaReference).append("=?");
sep = " and ";
}
whereClauseBuffer.append(whereJoinFragment(rooAlias, true, false));
select.setWhereClause(whereClauseBuffer.toString());
return select.setOuterJoins("", "").toStatementString();
}
use of org.hibernate.sql.SelectFragment in project hibernate-orm by hibernate.
the class AbstractEntityPersister method concretePropertySelectFragment.
protected String concretePropertySelectFragment(String alias, InclusionChecker inclusionChecker) {
int propertyCount = getPropertyNames().length;
int[] propertyTableNumbers = getPropertyTableNumbersInSelect();
SelectFragment frag = new SelectFragment();
for (int i = 0; i < propertyCount; i++) {
if (inclusionChecker.includeProperty(i)) {
frag.addColumnTemplates(generateTableAlias(alias, propertyTableNumbers[i]), propertyColumnReaderTemplates[i], propertyColumnAliases[i]);
frag.addFormulas(generateTableAlias(alias, propertyTableNumbers[i]), propertyColumnFormulaTemplates[i], propertyColumnAliases[i]);
}
}
return frag.toFragmentString();
}
Aggregations