use of org.hibernate.persister.entity.Queryable in project hibernate-orm by hibernate.
the class MapEntryNode method determineKeySelectExpressions.
private void determineKeySelectExpressions(QueryableCollection collectionPersister, List selections) {
AliasGenerator aliasGenerator = new LocalAliasGenerator(0);
appendSelectExpressions(collectionPersister.getIndexColumnNames(), selections, aliasGenerator);
Type keyType = collectionPersister.getIndexType();
if (keyType.isEntityType()) {
MapKeyEntityFromElement mapKeyEntityFromElement = findOrAddMapKeyEntityFromElement(collectionPersister);
Queryable keyEntityPersister = mapKeyEntityFromElement.getQueryable();
SelectFragment fragment = keyEntityPersister.propertySelectFragmentFragment(mapKeyEntityFromElement.getTableAlias(), null, false);
appendSelectExpressions(fragment, selections, aliasGenerator);
}
}
use of org.hibernate.persister.entity.Queryable in project hibernate-orm by hibernate.
the class HqlSqlWalker method prepareVersioned.
@Override
protected void prepareVersioned(AST updateNode, AST versioned) throws SemanticException {
UpdateStatement updateStatement = (UpdateStatement) updateNode;
FromClause fromClause = updateStatement.getFromClause();
if (versioned != null) {
// Make sure that the persister is versioned
Queryable persister = fromClause.getFromElement().getQueryable();
if (!persister.isVersioned()) {
throw new SemanticException("increment option specified for update of non-versioned entity");
}
VersionType versionType = persister.getVersionType();
if (versionType instanceof UserVersionType) {
throw new SemanticException("user-defined version types not supported for increment option");
}
AST eq = getASTFactory().create(HqlSqlTokenTypes.EQ, "=");
AST versionPropertyNode = generateVersionPropertyNode(persister);
eq.setFirstChild(versionPropertyNode);
AST versionIncrementNode = null;
if (isTimestampBasedVersion(versionType)) {
versionIncrementNode = getASTFactory().create(HqlSqlTokenTypes.PARAM, "?");
ParameterSpecification paramSpec = new VersionTypeSeedParameterSpecification(versionType);
((ParameterNode) versionIncrementNode).setHqlParameterSpecification(paramSpec);
parameters.add(0, paramSpec);
} else {
// Not possible to simply re-use the versionPropertyNode here as it causes
// OOM errors due to circularity :(
versionIncrementNode = getASTFactory().create(HqlSqlTokenTypes.PLUS, "+");
versionIncrementNode.setFirstChild(generateVersionPropertyNode(persister));
versionIncrementNode.addChild(getASTFactory().create(HqlSqlTokenTypes.IDENT, "1"));
}
eq.addChild(versionIncrementNode);
evaluateAssignment(eq, persister, 0);
AST setClause = updateStatement.getSetClause();
AST currentFirstSetElement = setClause.getFirstChild();
setClause.setFirstChild(eq);
eq.setNextSibling(currentFirstSetElement);
}
}
use of org.hibernate.persister.entity.Queryable in project hibernate-orm by hibernate.
the class HqlSqlWalker method evaluateAssignment.
@Override
protected void evaluateAssignment(AST eq) throws SemanticException {
prepareLogicOperator(eq);
Queryable persister = getCurrentFromClause().getFromElement().getQueryable();
evaluateAssignment(eq, persister, -1);
}
use of org.hibernate.persister.entity.Queryable in project hibernate-orm by hibernate.
the class FromElementFactory method createEntityAssociation.
private FromElement createEntityAssociation(String role, String roleAlias, JoinType joinType) throws SemanticException {
FromElement elem;
Queryable entityPersister = (Queryable) queryableCollection.getElementPersister();
String associatedEntityName = entityPersister.getEntityName();
// Get the class name of the associated entity.
if (queryableCollection.isOneToMany()) {
LOG.debugf("createEntityAssociation() : One to many - path = %s role = %s associatedEntityName = %s", path, role, associatedEntityName);
JoinSequence joinSequence = createJoinSequence(roleAlias, joinType);
elem = createJoin(associatedEntityName, roleAlias, joinSequence, (EntityType) queryableCollection.getElementType(), false);
} else {
LOG.debugf("createManyToMany() : path = %s role = %s associatedEntityName = %s", path, role, associatedEntityName);
elem = createManyToMany(role, associatedEntityName, roleAlias, entityPersister, (EntityType) queryableCollection.getElementType(), joinType);
fromClause.getWalker().addQuerySpaces(queryableCollection.getCollectionSpaces());
}
elem.setCollectionTableAlias(roleAlias);
return elem;
}
use of org.hibernate.persister.entity.Queryable in project hibernate-orm by hibernate.
the class CustomLoader method determineAppropriateOwnerPersister.
private Queryable determineAppropriateOwnerPersister(NonScalarReturn ownerDescriptor) {
String entityName = null;
if (ownerDescriptor instanceof RootReturn) {
entityName = ((RootReturn) ownerDescriptor).getEntityName();
} else if (ownerDescriptor instanceof CollectionReturn) {
CollectionReturn collRtn = (CollectionReturn) ownerDescriptor;
String role = collRtn.getOwnerEntityName() + "." + collRtn.getOwnerProperty();
CollectionPersister persister = getFactory().getMetamodel().collectionPersister(role);
EntityType ownerType = (EntityType) persister.getElementType();
entityName = ownerType.getAssociatedEntityName(getFactory());
} else if (ownerDescriptor instanceof FetchReturn) {
FetchReturn fetchRtn = (FetchReturn) ownerDescriptor;
Queryable persister = determineAppropriateOwnerPersister(fetchRtn.getOwner());
Type ownerType = persister.getPropertyType(fetchRtn.getOwnerProperty());
if (ownerType.isEntityType()) {
entityName = ((EntityType) ownerType).getAssociatedEntityName(getFactory());
} else if (ownerType.isCollectionType()) {
Type ownerCollectionElementType = ((CollectionType) ownerType).getElementType(getFactory());
if (ownerCollectionElementType.isEntityType()) {
entityName = ((EntityType) ownerCollectionElementType).getAssociatedEntityName(getFactory());
}
}
}
if (entityName == null) {
throw new HibernateException("Could not determine fetch owner : " + ownerDescriptor);
}
return (Queryable) getFactory().getMetamodel().entityPersister(entityName);
}
Aggregations