@Override public boolean isManyToMany() { return elementType.isEntityType(); //instanceof AssociationType; }
@Override public boolean isAssociation() { return mapKeyType.isEntityType(); }
/** * Check if the association is a one to one in the logical model (either a shared-pk * or unique fk). * * @param type The type representing the attribute metadata * * @return True if the attribute represents a logical one to one association */ private static boolean isLogicalOneToOne(Type type) { return type.isEntityType() && ( (EntityType) type ).isLogicalOneToOne(); }
public boolean isCollectionOfValuesOrComponents() { return persister == null && queryableCollection != null && !queryableCollection.getElementType().isEntityType(); }
@Override public EntityDefinition toEntityDefinition() { if ( !getType().isEntityType() ) { throw new IllegalStateException( "Cannot treat collection element type as entity" ); } return getElementPersister(); }
/** * Returns whether we believe the map element should be included as part of the middle table's primary key. * * @return {@code true} if the element should be included as part of the key, otherwise {@code false}. */ private boolean isMapElementInPrimaryKey() { if ( propertyValue instanceof IndexedCollection ) { final Value index = ( (IndexedCollection) propertyValue ).getIndex(); return !index.getType().isEntityType(); } return true; } }
public void collectQuerySpaces(Collection<String> spaces) { for ( EntityPersister persister : alias2Persister.values() ) { Collections.addAll( spaces, (String[]) persister.getQuerySpaces() ); } for ( CollectionPersister persister : alias2CollectionPersister.values() ) { final Type elementType = persister.getElementType(); if ( elementType.isEntityType() && ! elementType.isAnyType() ) { final Joinable joinable = ( (EntityType) elementType ).getAssociatedJoinable( factory ); Collections.addAll( spaces, (String[]) ( (EntityPersister) joinable ).getQuerySpaces() ); } } } }
void setCollectionToFetch(String role, String name, String ownerName, String entityName) throws QueryException { fetchName = name; collectionPersister = getCollectionPersister( role ); collectionOwnerName = ownerName; if ( collectionPersister.getElementType().isEntityType() ) { addEntityToFetch( entityName ); } }
@Override public EntityDefinition toEntityDefinition() { if ( !getType().isEntityType() ) { throw new IllegalStateException( "Cannot treat collection index type as entity" ); } return (EntityPersister) ( (AssociationType) getIndexType() ).getAssociatedJoinable( getFactory() ); }
private boolean hasAssociation(CompositeType componentType) { for ( Type subType : componentType.getSubtypes() ) { if ( subType.isEntityType() ) { return true; } else if ( subType.isComponentType() && hasAssociation( ( (CompositeType) subType ) ) ) { return true; } } return false; }
private String getElementName(PathExpressionParser.CollectionElement element, QueryTranslatorImpl q) throws QueryException { String name; if ( element.isOneToMany ) { name = element.alias; } else { Type type = element.elementType; if ( type.isEntityType() ) { //ie. a many-to-many String entityName = ( ( EntityType ) type ).getAssociatedEntityName(); name = pathExpressionParser.continueFromManyToMany( entityName, element.elementColumns, q ); } else { throw new QueryException( "illegally dereferenced collection element" ); } } return name; }
protected MapKeyEntityFromElement findOrAddMapKeyEntityFromElement(QueryableCollection collectionPersister) { if ( !collectionPersister.getIndexType().isEntityType() ) { return null; } for ( FromElement destination : getFromElement().getDestinations() ) { if ( destination instanceof MapKeyEntityFromElement ) { return (MapKeyEntityFromElement) destination; } } return MapKeyEntityFromElement.buildKeyJoin( getFromElement() ); } }
private EntityReferenceAliases createCollectionElementAliases( CollectionPersister collectionPersister, String tableAlias, String elementQuerySpaceUid) { if ( !collectionPersister.getElementType().isEntityType() ) { return null; } else { final EntityType entityElementType = (EntityType) collectionPersister.getElementType(); return generateEntityReferenceAliases( elementQuerySpaceUid, tableAlias, (EntityPersister) entityElementType.getAssociatedJoinable( sessionFactory() ) ); } }
private void addAssociationsToTheSetForOneProperty(String name, Type type, String prefix, SessionFactoryImplementor factory) { if ( type.isCollectionType() ) { CollectionType collType = (CollectionType) type; Type assocType = collType.getElementType( factory ); addAssociationsToTheSetForOneProperty(name, assocType, prefix, factory); } //ToOne association else if ( type.isEntityType() || type.isAnyType() ) { associations.add( prefix + name ); } else if ( type.isComponentType() ) { CompositeType componentType = (CompositeType) type; addAssociationsToTheSetForAllProperties( componentType.getPropertyNames(), componentType.getSubtypes(), (prefix.equals( "" ) ? name : prefix + name) + ".", factory); } }
private EntityLoader createUniqueKeyLoader( Type uniqueKeyType, String[] columns, LoadQueryInfluencers loadQueryInfluencers) { if ( uniqueKeyType.isEntityType() ) { String className = ( (EntityType) uniqueKeyType ).getAssociatedEntityName(); uniqueKeyType = getFactory().getMetamodel().entityPersister( className ).getIdentifierType(); } return new EntityLoader( this, columns, uniqueKeyType, 1, LockMode.NONE, getFactory(), loadQueryInfluencers ); }
@Override public String getAssociatedEntityName(SessionFactoryImplementor factory) throws MappingException { try { QueryableCollection collectionPersister = (QueryableCollection) factory .getCollectionPersister( role ); if ( !collectionPersister.getElementType().isEntityType() ) { throw new MappingException( "collection was not an association: " + collectionPersister.getRole() ); } return collectionPersister.getElementPersister().getEntityName(); } catch (ClassCastException cce) { throw new MappingException( "collection role is not queryable " + role ); } }
public void end(QueryTranslatorImpl q) throws QueryException { if ( !isCollectionValued() ) { Type type = getPropertyType(); if ( type.isEntityType() ) { // "finish off" the join token( ".", q ); token( null, q ); } else if ( type.isCollectionType() ) { // default to element set if no elements() specified token( ".", q ); token( CollectionPropertyNames.COLLECTION_ELEMENTS, q ); } } super.end( q ); }
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 ); } }
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 ); }
@Override protected void applyRootReturnSelectFragments(SelectStatementBuilder selectStatementBuilder) { if ( getRootCollectionReturn().allowIndexJoin() && getQueryableCollection().getIndexType().isEntityType() ) { final EntityReference indexEntityReference = getRootCollectionReturn().getIndexGraph().resolveEntityReference(); final EntityReferenceAliases indexEntityReferenceAliases = getAliasResolutionContext().resolveEntityReferenceAliases( indexEntityReference.getQuerySpaceUid() ); selectStatementBuilder.appendSelectClauseFragment( ( (OuterJoinLoadable) indexEntityReference.getEntityPersister() ).selectFragment( indexEntityReferenceAliases.getTableAlias(), indexEntityReferenceAliases.getColumnAliases().getSuffix() ) ); } }