use of org.hibernate.metamodel.model.domain.EntityDomainType in project hibernate-orm by hibernate.
the class StandardEntityGraphTraversalStateImpl method appliesTo.
private boolean appliesTo(FetchParent fetchParent) {
if (currentGraphContext == null || !(fetchParent instanceof EntityResultGraphNode)) {
return false;
}
final EntityResultGraphNode entityFetchParent = (EntityResultGraphNode) fetchParent;
final EntityMappingType entityFetchParentMappingType = entityFetchParent.getEntityValuedModelPart().getEntityMappingType();
assert currentGraphContext.getGraphedType() instanceof EntityDomainType;
final EntityDomainType entityDomainType = (EntityDomainType) currentGraphContext.getGraphedType();
return entityDomainType.getHibernateEntityName().equals(entityFetchParentMappingType.getEntityName());
}
use of org.hibernate.metamodel.model.domain.EntityDomainType in project hibernate-orm by hibernate.
the class MappingMetamodelImpl method resolveMappingExpressible.
@Override
public MappingModelExpressible<?> resolveMappingExpressible(SqmExpressible<?> sqmExpressible, Function<NavigablePath, TableGroup> tableGroupLocator) {
if (sqmExpressible instanceof SqmPath) {
final SqmPath<?> sqmPath = (SqmPath<?>) sqmExpressible;
final NavigablePath navigablePath = sqmPath.getNavigablePath();
if (navigablePath.getParent() != null) {
final TableGroup parentTableGroup = tableGroupLocator.apply(navigablePath.getParent());
return parentTableGroup.getModelPart().findSubPart(navigablePath.getLocalName(), null);
}
return tableGroupLocator.apply(navigablePath.getParent()).getModelPart();
}
if (sqmExpressible instanceof BasicType<?>) {
return (BasicType<?>) sqmExpressible;
}
if (sqmExpressible instanceof BasicSqmPathSource<?>) {
return getTypeConfiguration().getBasicTypeForJavaType(((BasicSqmPathSource<?>) sqmExpressible).getJavaType());
}
if (sqmExpressible instanceof SqmFieldLiteral) {
return getTypeConfiguration().getBasicTypeForJavaType(((SqmFieldLiteral<?>) sqmExpressible).getJavaType());
}
if (sqmExpressible instanceof CompositeSqmPathSource) {
throw new NotYetImplementedFor6Exception("Resolution of embedded-valued SqmExpressible nodes not yet implemented");
}
if (sqmExpressible instanceof EmbeddableTypeImpl) {
return (MappingModelExpressible<?>) sqmExpressible;
}
if (sqmExpressible instanceof EntityDomainType<?>) {
return getEntityDescriptor(((EntityDomainType<?>) sqmExpressible).getHibernateEntityName());
}
if (sqmExpressible instanceof TupleType<?>) {
final MappingModelExpressible<?> mappingModelExpressible = tupleTypeCache.get(sqmExpressible);
if (mappingModelExpressible != null) {
return mappingModelExpressible;
}
final TupleType<?> tupleType = (TupleType<?>) sqmExpressible;
final MappingModelExpressible<?>[] components = new MappingModelExpressible<?>[tupleType.componentCount()];
for (int i = 0; i < components.length; i++) {
components[i] = resolveMappingExpressible(tupleType.get(i), tableGroupLocator);
}
final MappingModelExpressible<?> createdMappingModelExpressible = new TupleMappingModelExpressible(components);
final MappingModelExpressible<?> existingMappingModelExpressible = tupleTypeCache.putIfAbsent(tupleType, createdMappingModelExpressible);
return existingMappingModelExpressible == null ? createdMappingModelExpressible : existingMappingModelExpressible;
}
return null;
}
use of org.hibernate.metamodel.model.domain.EntityDomainType in project hibernate-orm by hibernate.
the class SqmMappingModelHelper method resolveSqmPath.
private static ModelPart resolveSqmPath(SqmPath<?> sqmPath, MappingMetamodel domainModel, Function<NavigablePath, TableGroup> tableGroupLocator) {
if (sqmPath instanceof SqmTreatedPath) {
final SqmTreatedPath treatedPath = (SqmTreatedPath) sqmPath;
final EntityDomainType treatTargetType = treatedPath.getTreatTarget();
return domainModel.findEntityDescriptor(treatTargetType.getHibernateEntityName());
}
// see if the LHS is treated
if (sqmPath.getLhs() instanceof SqmTreatedPath) {
final SqmTreatedPath treatedPath = (SqmTreatedPath) sqmPath.getLhs();
final EntityDomainType treatTargetType = treatedPath.getTreatTarget();
final EntityPersister container = domainModel.findEntityDescriptor(treatTargetType.getHibernateEntityName());
return container.findSubPart(sqmPath.getNavigablePath().getLocalName(), container);
}
// Plural path parts are not joined and thus also have no table group
if (sqmPath instanceof AbstractSqmSpecificPluralPartPath<?>) {
final TableGroup lhsTableGroup = tableGroupLocator.apply(sqmPath.getLhs().getLhs().getNavigablePath());
final ModelPartContainer pluralPart = (ModelPartContainer) lhsTableGroup.getModelPart().findSubPart(sqmPath.getLhs().getReferencedPathSource().getPathName(), null);
final CollectionPart collectionPart = (CollectionPart) pluralPart.findSubPart(sqmPath.getReferencedPathSource().getPathName(), null);
// as that is the mapping type of the expression
if (collectionPart instanceof EntityCollectionPart) {
return ((EntityCollectionPart) collectionPart).getEntityMappingType();
}
return collectionPart;
}
if (sqmPath.getLhs() == null) {
final EntityDomainType<?> entityDomainType = (EntityDomainType<?>) sqmPath.getReferencedPathSource();
return domainModel.findEntityDescriptor(entityDomainType.getHibernateEntityName());
}
final TableGroup lhsTableGroup = tableGroupLocator.apply(sqmPath.getLhs().getNavigablePath());
final ModelPartContainer modelPart;
if (lhsTableGroup == null) {
modelPart = (ModelPartContainer) resolveSqmPath(sqmPath.getLhs(), domainModel, tableGroupLocator);
} else {
modelPart = lhsTableGroup.getModelPart();
}
return modelPart.findSubPart(sqmPath.getReferencedPathSource().getPathName(), null);
}
use of org.hibernate.metamodel.model.domain.EntityDomainType in project hibernate-orm by hibernate.
the class MatchingIdSelectionHelper method generateMatchingIdSelectQuery.
/**
* @asciidoc
*
* Generates a query-spec for selecting all ids matching the restriction defined as part
* of the user's update/delete query. This query-spec is generally used:
*
* * to select all the matching ids via JDBC - see {@link MatchingIdSelectionHelper#selectMatchingIds}
* * as a sub-query restriction to insert rows into an "id table"
*/
public static QuerySpec generateMatchingIdSelectQuery(EntityMappingType targetEntityDescriptor, SqmDeleteOrUpdateStatement sqmStatement, DomainParameterXref domainParameterXref, Predicate restriction, MultiTableSqmMutationConverter sqmConverter, SessionFactoryImplementor sessionFactory) {
final EntityDomainType entityDomainType = sqmStatement.getTarget().getModel();
if (log.isTraceEnabled()) {
log.tracef("Starting generation of entity-id SQM selection - %s", entityDomainType.getHibernateEntityName());
}
final QuerySpec idSelectionQuery = new QuerySpec(true, 1);
final TableGroup mutatingTableGroup = sqmConverter.getMutatingTableGroup();
idSelectionQuery.getFromClause().addRoot(mutatingTableGroup);
targetEntityDescriptor.getIdentifierMapping().forEachSelectable((position, selection) -> {
final TableReference tableReference = mutatingTableGroup.resolveTableReference(mutatingTableGroup.getNavigablePath(), selection.getContainingTableExpression());
final Expression expression = sqmConverter.getSqlExpressionResolver().resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(tableReference, selection.getSelectionExpression()), sqlAstProcessingState -> new ColumnReference(tableReference, selection, sessionFactory));
idSelectionQuery.getSelectClause().addSqlSelection(new SqlSelectionImpl(position, position + 1, expression));
});
idSelectionQuery.applyPredicate(restriction);
return idSelectionQuery;
}
use of org.hibernate.metamodel.model.domain.EntityDomainType in project hibernate-orm by hibernate.
the class ASTParserLoadingTest method verifyAnimalZooSelection.
private static void verifyAnimalZooSelection(Query q) {
final SqmSelectStatement<?> sqmStatement = (SqmSelectStatement<?>) q.unwrap(QuerySqmImpl.class).getSqmStatement();
final SqmSelection<?> sqmSelection = sqmStatement.getQuerySpec().getSelectClause().getSelections().get(0);
assertThat(sqmSelection.getSelectableNode(), instanceOf(SqmPath.class));
final SqmPath<?> selectedPath = (SqmPath<?>) sqmSelection.getSelectableNode();
assertThat(selectedPath.getReferencedPathSource(), instanceOf(EntitySqmPathSource.class));
final EntitySqmPathSource selectedAttr = (EntitySqmPathSource) selectedPath.getReferencedPathSource();
assertThat(selectedAttr.getPathName(), is("zoo"));
assertThat(selectedAttr.getSqmPathType(), instanceOf(EntityDomainType.class));
final EntityDomainType<?> zooType = (EntityDomainType<?>) selectedAttr.getSqmPathType();
assertThat(zooType.getHibernateEntityName(), is(Zoo.class.getName()));
}
Aggregations