public boolean isCollectionValued() throws QueryException { //TODO: is there a better way? return collectionName != null && !getPropertyType().isCollectionType(); }
public boolean isPlural() { return propertyMapping.getType().isCollectionType(); }
private boolean indicatesCollection(Type type) { if ( type.isCollectionType() ) { return true; } else if ( type.isComponentType() ) { Type[] subtypes = ( (CompositeType) type ).getSubtypes(); for ( int i = 0; i < subtypes.length; i++ ) { if ( indicatesCollection( subtypes[i] ) ) { return true; } } } return false; }
private static NonIdentifierAttributeNature decode(Type type) { if ( type.isAssociationType() ) { AssociationType associationType = (AssociationType) type; if ( type.isComponentType() ) { // an any type is both an association and a composite... return NonIdentifierAttributeNature.ANY; } return type.isCollectionType() ? NonIdentifierAttributeNature.COLLECTION : NonIdentifierAttributeNature.ENTITY; } else { if ( type.isComponentType() ) { return NonIdentifierAttributeNature.COMPOSITE; } return NonIdentifierAttributeNature.BASIC; } }
@Override public void resolveInFunctionCall(boolean generateJoin, boolean implicitJoin) throws SemanticException { if ( isResolved() ) { return; } Type propertyType = prepareLhs(); // Prepare the left hand side and get the data type. if ( propertyType != null && propertyType.isCollectionType() ) { resolveIndex( null ); } else { resolveFirstChild(); super.resolve( generateJoin, implicitJoin ); } }
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 void checkLhsIsNotCollection() throws SemanticException { if ( getLhs().getDataType() != null && getLhs().getDataType().isCollectionType() ) { throw ILLEGAL_COLL_DEREF_EXCP_BUILDER.buildIllegalCollectionDereferenceException( propertyName, getLhs() ); } }
private static void cascadeAssociation( final CascadingAction action, final CascadePoint cascadePoint, final EventSource eventSource, final int componentPathStackDepth, final Object parent, final Object child, final Type type, final CascadeStyle style, final Object anything, final boolean isCascadeDeleteEnabled) { if ( type.isEntityType() || type.isAnyType() ) { cascadeToOne( action, eventSource, parent, child, type, style, anything, isCascadeDeleteEnabled ); } else if ( type.isCollectionType() ) { cascadeCollection( action, cascadePoint, eventSource, componentPathStackDepth, parent, child, style, anything, (CollectionType) type ); } }
/** * Check if eager of the association is overriden by anything. * * @param session session * @param entityName entity name * @param associationName association name * * @return null if there is no overriding, true if it is overridden to eager and false if it is overridden to lazy */ private static Boolean getOverridingEager( SharedSessionContractImplementor session, String entityName, String associationName, Type type) { if ( type.isAssociationType() || type.isCollectionType() ) { Boolean overridingEager = isEagerFetchProfile( session, entityName + "." + associationName ); if ( LOG.isDebugEnabled() ) { if ( overridingEager != null ) { LOG.debugf( "Overriding eager fetching using active fetch profile. EntityName: %s, associationName: %s, eager fetching: %s", entityName, associationName, overridingEager ); } } return overridingEager; } return null; }
/** * Visit a property value. Dispatch to the * correct handler for the property type. * @param value * @param type * @throws HibernateException */ final Object processValue(Object value, Type type) throws HibernateException { if ( type.isCollectionType() ) { //even process null collections return processCollection( value, (CollectionType) type ); } else if ( type.isEntityType() ) { return processEntity( value, (EntityType) type ); } else if ( type.isComponentType() ) { return processComponent( value, (CompositeType) type ); } else { return null; } }
public void end(QueryTranslatorImpl q) throws QueryException { ignoreInitialJoin = false; Type propertyType = getPropertyType(); if ( propertyType != null && propertyType.isCollectionType() ) { collectionRole = ( ( CollectionType ) propertyType ).getRole(); collectionName = q.createNameForCollection( collectionRole ); prepareForIndex( q ); } else { columns = currentColumns(); setType(); } //important!! continuation = false; }
public CascadeStyle getCascadeStyle() throws MappingException { Type type = value.getType(); if ( type.isComponentType() ) { return getCompositeCascadeStyle( (CompositeType) type, cascade ); } else if ( type.isCollectionType() ) { return getCollectionCascadeStyle( ( (Collection) value ).getElement().getType(), cascade ); } else { return getCascadeStyle( cascade ); } }
Type returnType = ownerPersister.getPropertyType( fetchReturn.getOwnerProperty() ); if ( returnType.isCollectionType() ) { String role = ownerPersister.getEntityName() + '.' + fetchReturn.getOwnerProperty(); addCollection( role, alias, fetchReturn.getPropertyResultsMap() );
private boolean isNonIdentifierWhereConditionsRequired(String entityName, String propertyName, SessionImplementor session) { final Type propertyType = session.getSessionFactory().getMetamodel().entityPersister( entityName ).getPropertyType( propertyName ); if ( propertyType.isCollectionType() ) { final CollectionType collectionType = (CollectionType) propertyType; final Type collectionElementType = collectionType.getElementType( session.getSessionFactory() ); if ( collectionElementType instanceof ComponentType ) { // required for Embeddables return true; } else if ( collectionElementType instanceof MaterializedClobType || collectionElementType instanceof MaterializedNClobType ) { // for Map<> using @Lob annotations return collectionType instanceof MapType; } } return false; } }
public static LazyAttributeDescriptor from( Property property, int attributeIndex, int lazyIndex) { String fetchGroupName = property.getLazyGroup(); if ( fetchGroupName == null ) { fetchGroupName = property.getType().isCollectionType() ? property.getName() : "DEFAULT"; } return new LazyAttributeDescriptor( attributeIndex, lazyIndex, property.getName(), property.getType(), fetchGroupName ); }
protected QueryableCollection getQueryableCollection( String entityName, String propertyName, SessionFactoryImplementor factory) throws HibernateException { final PropertyMapping ownerMapping = (PropertyMapping) factory.getEntityPersister( entityName ); final Type type = ownerMapping.toType( propertyName ); if ( !type.isCollectionType() ) { throw new MappingException( "Property path [" + entityName + "." + propertyName + "] does not reference a collection" ); } final String role = ( (CollectionType) type ).getRole(); try { return (QueryableCollection) factory.getCollectionPersister( role ); } catch ( ClassCastException cce ) { throw new QueryException( "collection role is not queryable: " + role ); } catch ( Exception e ) { throw new QueryException( "collection role not found: " + 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 validateLhs(FromReferenceNode lhs) { // make sure the lhs is "assignable"... if ( !lhs.isResolved() ) { throw new UnsupportedOperationException( "cannot validate assignablity of unresolved node" ); } if ( lhs.getDataType().isCollectionType() ) { throw new QueryException( "collections not assignable in update statements" ); } else if ( lhs.getDataType().isComponentType() ) { throw new QueryException( "Components currently not assignable in update statements" ); } else if ( lhs.getDataType().isEntityType() ) { // currently allowed... } // TODO : why aren't these the same? if ( lhs.getImpliedJoin() != null || lhs.getFromElement().isImplied() ) { throw new QueryException( "Implied join paths are not assignable in update statements" ); } } }
private void evictCachedCollections(Type[] types, Serializable id, EventSource source) throws HibernateException { for ( Type type : types ) { if ( type.isCollectionType() ) { CollectionPersister collectionPersister = source.getFactory().getMetamodel().collectionPersister( ( (CollectionType) type ).getRole() ); if ( collectionPersister.hasCache() ) { final CollectionDataAccess cache = collectionPersister.getCacheAccessStrategy(); final Object ck = cache.generateCacheKey( id, collectionPersister, source.getFactory(), source.getTenantIdentifier() ); final SoftLock lock = cache.lockItem( source, ck, null ); cache.remove( source, ck ); source.getActionQueue().registerProcess( (success, session) -> cache.unlockItem( session, ck, lock ) ); } } else if ( type.isComponentType() ) { CompositeType actype = (CompositeType) type; evictCachedCollections( actype.getSubtypes(), id, source ); } } } }
private FromElement createCollectionJoin(JoinSequence collectionJoinSequence, String tableAlias) throws SemanticException { String text = queryableCollection.getTableName(); AST ast = createFromElement( text ); FromElement destination = (FromElement) ast; Type elementType = queryableCollection.getElementType(); if ( elementType.isCollectionType() ) { throw new SemanticException( "Collections of collections are not supported!" ); } destination.initializeCollection( fromClause, classAlias, tableAlias ); destination.setType( JOIN_FRAGMENT ); // Tag this node as a JOIN. destination.setIncludeSubclasses( false ); // Don't include subclasses in the join. destination.setCollectionJoin( true ); // This is a clollection join. destination.setJoinSequence( collectionJoinSequence ); destination.setOrigin( origin, false ); destination.setCollectionTableAlias( tableAlias ); // origin.addDestination( destination ); // This was the cause of HHH-242 // origin.setType( FROM_FRAGMENT ); // Set the parent node type so that the AST is properly formed. origin.setText( "" ); // The destination node will have all the FROM text. origin.setCollectionJoin( true ); // The parent node is a collection join too (voodoo - see JoinProcessor) fromClause.addCollectionJoinFromElementByPath( path, destination ); fromClause.getWalker().addQuerySpaces( queryableCollection.getCollectionSpaces() ); return destination; }