use of org.hibernate.persister.entity.Queryable in project hibernate-orm by hibernate.
the class EntityLoadQueryDetails method applyRootReturnFilterRestrictions.
protected void applyRootReturnFilterRestrictions(SelectStatementBuilder selectStatementBuilder) {
final Queryable rootQueryable = (Queryable) getRootEntityReturn().getEntityPersister();
selectStatementBuilder.appendRestrictions(rootQueryable.filterFragment(entityReferenceAliases.getTableAlias(), Collections.emptyMap()));
}
use of org.hibernate.persister.entity.Queryable in project hibernate-orm by hibernate.
the class QueryTranslatorImpl method buildAppropriateStatementExecutor.
private StatementExecutor buildAppropriateStatementExecutor(HqlSqlWalker walker) {
final Statement statement = (Statement) walker.getAST();
if (walker.getStatementType() == HqlSqlTokenTypes.DELETE) {
final FromElement fromElement = walker.getFinalFromClause().getFromElement();
final Queryable persister = fromElement.getQueryable();
if (persister.isMultiTable()) {
return new MultiTableDeleteExecutor(walker);
} else {
return new DeleteExecutor(walker, persister);
}
} else if (walker.getStatementType() == HqlSqlTokenTypes.UPDATE) {
final FromElement fromElement = walker.getFinalFromClause().getFromElement();
final Queryable persister = fromElement.getQueryable();
if (persister.isMultiTable()) {
// TODO : decide if it is better performance-wise to doAfterTransactionCompletion that check, or to simply use the MultiTableUpdateDelegate
return new MultiTableUpdateExecutor(walker);
} else {
return new BasicExecutor(walker, persister);
}
} else if (walker.getStatementType() == HqlSqlTokenTypes.INSERT) {
return new BasicExecutor(walker, ((InsertStatement) statement).getIntoClause().getQueryable());
} else {
throw new QueryException("Unexpected statement type");
}
}
use of org.hibernate.persister.entity.Queryable in project hibernate-orm by hibernate.
the class DotNode method dereferenceCollection.
private void dereferenceCollection(CollectionType collectionType, boolean implicitJoin, boolean indexed, String classAlias, AST parent) throws SemanticException {
dereferenceType = DereferenceType.COLLECTION;
String role = collectionType.getRole();
//foo.bars.size (also handles deprecated stuff like foo.bars.maxelement for backwardness)
boolean isSizeProperty = getNextSibling() != null && CollectionProperties.isAnyCollectionProperty(getNextSibling().getText());
if (isSizeProperty) {
//yuck!
indexed = true;
}
QueryableCollection queryableCollection = getSessionFactoryHelper().requireQueryableCollection(role);
String propName = getPath();
FromClause currentFromClause = getWalker().getCurrentFromClause();
// If the lhs of the join is a "component join", we need to go back to the
// first non-component-join as the origin to properly link aliases and
// join columns
FromElement lhsFromElement = getLhs().getFromElement();
while (lhsFromElement != null && ComponentJoin.class.isInstance(lhsFromElement)) {
lhsFromElement = lhsFromElement.getOrigin();
}
if (lhsFromElement == null) {
throw new QueryException("Unable to locate appropriate lhs");
}
// in all other cases, we should use the table alias
if (getWalker().getStatementType() != SqlTokenTypes.SELECT) {
if (isFromElementUpdateOrDeleteRoot(lhsFromElement)) {
// at this point we know we have the 2 conditions above,
// lets see if we have the mentioned "multi-table" caveat...
boolean useAlias = false;
if (getWalker().getStatementType() != SqlTokenTypes.INSERT) {
final Queryable persister = lhsFromElement.getQueryable();
if (persister.isMultiTable()) {
useAlias = true;
}
}
if (!useAlias) {
final String lhsTableName = lhsFromElement.getQueryable().getTableName();
columns = getFromElement().toColumns(lhsTableName, propertyPath, false, true);
}
}
}
// We do not look for an existing join on the same path, because
// it makes sense to join twice on the same collection role
FromElementFactory factory = new FromElementFactory(currentFromClause, lhsFromElement, propName, classAlias, getColumns(), implicitJoin);
FromElement elem = factory.createCollection(queryableCollection, role, joinType, fetch, indexed);
LOG.debugf("dereferenceCollection() : Created new FROM element for %s : %s", propName, elem);
setImpliedJoin(elem);
// This 'dot' expression now refers to the resulting from element.
setFromElement(elem);
if (isSizeProperty) {
elem.setText("");
elem.setUseWhereFragment(false);
}
if (!implicitJoin) {
EntityPersister entityPersister = elem.getEntityPersister();
if (entityPersister != null) {
getWalker().addQuerySpaces(entityPersister.getQuerySpaces());
}
}
// Always add the collection's query spaces.
getWalker().addQuerySpaces(queryableCollection.getCollectionSpaces());
}
use of org.hibernate.persister.entity.Queryable in project hibernate-orm by hibernate.
the class FromElement method buildTypeDiscriminatorMetadata.
private TypeDiscriminatorMetadata buildTypeDiscriminatorMetadata() {
final String aliasToUse = getTableAlias();
Queryable queryable = getQueryable();
if (queryable == null) {
QueryableCollection collection = getQueryableCollection();
if (!collection.getElementType().isEntityType()) {
throw new QueryException("type discrimination cannot be applied to value collection [" + collection.getRole() + "]");
}
queryable = (Queryable) collection.getElementPersister();
}
handlePropertyBeingDereferenced(getDataType(), DISCRIMINATOR_PROPERTY_NAME);
return new TypeDiscriminatorMetadataImpl(queryable.getTypeDiscriminatorMetadata(), aliasToUse);
}
use of org.hibernate.persister.entity.Queryable in project hibernate-orm by hibernate.
the class MapEntryNode method determineValueSelectExpressions.
private void determineValueSelectExpressions(QueryableCollection collectionPersister, List selections) {
AliasGenerator aliasGenerator = new LocalAliasGenerator(1);
appendSelectExpressions(collectionPersister.getElementColumnNames(), selections, aliasGenerator);
Type valueType = collectionPersister.getElementType();
if (valueType.isAssociationType()) {
EntityType valueEntityType = (EntityType) valueType;
Queryable valueEntityPersister = (Queryable) sfi().getEntityPersister(valueEntityType.getAssociatedEntityName(sfi()));
SelectFragment fragment = valueEntityPersister.propertySelectFragmentFragment(elementTableAlias(), null, false);
appendSelectExpressions(fragment, selections, aliasGenerator);
}
}
Aggregations