/** * @deprecated (since 5.2) Use {@link MetamodelImplementor#collectionPersister(String)} instead. */ @Deprecated default CollectionPersister getCollectionPersister(String role) throws MappingException { return getMetamodel().collectionPersister( role ); }
void afterDeserialize(SessionFactoryImplementor factory) { loadedPersister = ( factory == null ? null : factory.getMetamodel().collectionPersister( role ) ); }
private CollectionPersister getPersister(SessionFactoryImplementor factory) { return factory.getMetamodel().collectionPersister( role ); }
public CollectionMetadata getCollectionMetadata(String roleName) throws HibernateException { return (CollectionMetadata) getMetamodel().collectionPersister( roleName ); }
@Override public CollectionStatisticsImpl getCollectionStatistics(String role) { if ( sessionFactory == null ) { return null; } return collectionStatsMap.computeIfAbsent( role, s -> new CollectionStatisticsImpl( sessionFactory.getMetamodel().collectionPersister( role ) ) ); }
/** * Reconnect to session after deserialization... * * @param session The session being deserialized */ public void afterDeserialize(SharedSessionContractImplementor session) { if ( this.session != null || this.persister != null ) { throw new IllegalStateException( "already attached to a session." ); } // IMPL NOTE: non-flushed changes code calls this method with session == null... // guard against NullPointerException if ( session != null ) { this.session = session; this.persister = session.getFactory().getMetamodel().collectionPersister( collectionRole ); } }
@Override public void evictCollectionData(String role) { final CollectionPersister collectionDescriptor = sessionFactory.getMetamodel() .collectionPersister( role ); evictCollectionData( collectionDescriptor ); }
@Override public Object replaceElements( final Object original, final Object target, final Object owner, final java.util.Map copyCache, final SharedSessionContractImplementor session) throws HibernateException { CollectionPersister cp = session.getFactory().getMetamodel().collectionPersister( getRole() ); java.util.Map result = (java.util.Map) target; result.clear(); for ( Object o : ( (Map) original ).entrySet() ) { Map.Entry me = (Map.Entry) o; Object key = cp.getIndexType().replace( me.getKey(), null, session, owner, copyCache ); Object value = cp.getElementType().replace( me.getValue(), null, session, owner, copyCache ); result.put( key, value ); } return result; }
QueryableCollection getCollectionPersister(String role) throws QueryException { try { return (QueryableCollection) getFactory().getMetamodel().collectionPersister( role ); } catch (ClassCastException cce) { throw new QueryException( "collection role is not queryable: " + role ); } catch (Exception e) { throw new QueryException( "collection role not found: " + role ); } }
/** * Locate the collection persister by the collection role. * * @param role The collection role name. * * @return The defined CollectionPersister for this collection role, or null. */ public QueryableCollection getCollectionPersister(String role) { try { return (QueryableCollection) sfi.getMetamodel().collectionPersister( role ); } catch ( ClassCastException cce ) { throw new QueryException( "collection is not queryable: " + role ); } catch ( Exception e ) { throw new QueryException( "collection not found: " + role ); } }
@Override public boolean containsCollection(String role, Serializable ownerIdentifier) { final CollectionPersister collectionDescriptor = sessionFactory.getMetamodel() .collectionPersister( role ); final CollectionDataAccess cacheAccess = collectionDescriptor.getCacheAccessStrategy(); if ( cacheAccess == null ) { return false; } final Object key = cacheAccess.generateCacheKey( ownerIdentifier, collectionDescriptor, sessionFactory, null ); return cacheAccess.contains( key ); }
@Override public Object replaceElements(Object original, Object target, Object owner, Map copyCache, SharedSessionContractImplementor session) throws HibernateException { CollectionPersister cp = session.getFactory().getMetamodel().collectionPersister( getRole() ); return userType.replaceElements(original, target, cp, owner, copyCache, session); }
/** * Locate the collection persister by the collection role, requiring that * such a persister exist. * * @param role The collection role name. * * @return The defined CollectionPersister for this collection role. * * @throws QueryException Indicates that the collection persister could not be found. */ public QueryableCollection requireQueryableCollection(String role) throws QueryException { try { QueryableCollection queryableCollection = (QueryableCollection) sfi.getMetamodel().collectionPersister( role ); if ( queryableCollection != null ) { collectionPropertyMappingByRole.put( role, new CollectionPropertyMapping( queryableCollection ) ); } return queryableCollection; } catch ( ClassCastException cce ) { throw new QueryException( "collection role is not queryable: " + role ); } catch ( Exception e ) { throw new QueryException( "collection role not found: " + role ); } }
/** * For initialized detached collections */ public CollectionEntry(PersistentCollection collection, SessionFactoryImplementor factory) throws MappingException { // detached collections that get found + reattached // during flush shouldn't be ignored ignore = false; loadedKey = collection.getKey(); setLoadedPersister( factory.getMetamodel().collectionPersister( collection.getRole() ) ); snapshot = collection.getStoredSnapshot(); }
/** * Compile a filter. This method may be called multiple * times. Subsequent invocations are no-ops. */ public synchronized void compile( String collectionRole, Map replacements, boolean scalar) throws QueryException, MappingException { if ( !isCompiled() ) { addFromAssociation( "this", collectionRole ); paramValueBinders.add( new CollectionFilterKeyParameterSpecification( collectionRole, getFactory().getMetamodel().collectionPersister( collectionRole ).getKeyType() ) ); compile( replacements, scalar ); } }
@Override public void evictCollectionData(String role, Serializable ownerIdentifier) { final CollectionPersister collectionDescriptor = sessionFactory.getMetamodel() .collectionPersister( role ); final CollectionDataAccess cacheAccess = collectionDescriptor.getCacheAccessStrategy(); if ( cacheAccess == null ) { return; } if ( LOG.isDebugEnabled() ) { LOG.debugf( "Evicting second-level cache: %s", MessageHelper.collectionInfoString( collectionDescriptor, ownerIdentifier, sessionFactory ) ); } final Object key = cacheAccess.generateCacheKey( ownerIdentifier, collectionDescriptor, sessionFactory, null ); cacheAccess.evict( key ); }
protected CollectionPersister resolveCollectionPersister( SessionImplementor session, PersistentCollection collection) { // First attempt to resolve the persister from the collection entry if ( collection != null ) { CollectionEntry collectionEntry = session.getPersistenceContext().getCollectionEntry( collection ); if ( collectionEntry != null ) { CollectionPersister collectionPersister = collectionEntry.getCurrentPersister(); if ( collectionPersister != null ) { return collectionPersister; } } } // Fallback to resolving the persister from the collection role final CollectionPersister collectionPersister = session.getFactory() .getMetamodel() .collectionPersister( commonCollectionMapperData.getRole() ); if ( collectionPersister == null ) { throw new AuditException( String.format( Locale.ROOT, "Failed to locate CollectionPersister for collection [%s]", commonCollectionMapperData.getRole() ) ); } return collectionPersister; }
@Override public Object processCollection(Object collection, CollectionType type) throws HibernateException { if ( collection == CollectionType.UNFETCHED_COLLECTION ) { return null; } final EventSource session = getSession(); final CollectionPersister persister = session.getFactory().getMetamodel().collectionPersister( type.getRole() ); if ( isUpdate ) { removeCollection( persister, extractCollectionKeyFromOwner( persister ), session ); } if ( collection != null && collection instanceof PersistentCollection ) { final PersistentCollection wrapper = (PersistentCollection) collection; wrapper.setCurrentSession( (SessionImplementor) session ); if ( wrapper.wasInitialized() ) { session.getPersistenceContext().addNewCollection( persister, wrapper ); } else { reattachCollection( wrapper, type ); } } else { // otherwise a null or brand new collection // this will also (inefficiently) handle arrays, which // have no snapshot, so we can't do any better //processArrayOrNewCollection(collection, type); } return null; }
.collectionPersister( Event.class.getName() + ".participants" ) .getCacheAccessStrategy() .getAccessType(),
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 ); } } } }