/** * Get the snapshot of the pre-flush collection state */ public Serializable getSnapshot(PersistentCollection coll) { return getCollectionEntry(coll).getSnapshot(); }
public LockMode getLockMode(Object entity) { return getEntry(entity).getLockMode(); }
private final void performReplication( Object entity, Serializable id, Object version, EntityPersister persister, ReplicationMode replicationMode, SessionImplementor source) throws HibernateException { if ( log.isTraceEnabled() ) { log.trace( "replicating changes to " + MessageHelper.infoString( persister, id, source.getFactory() ) ); } new OnReplicateVisitor(source, id, true).process( entity, persister ); source.getPersistenceContext().addEntity( entity, Status.MANAGED, null, id, version, LockMode.NONE, true, persister, true ); source.getPersistenceContext().incrementCascadeLevel(); try { Cascades.cascade( source, persister, entity, Cascades.ACTION_REPLICATE, Cascades.CASCADE_AFTER_UPDATE, replicationMode ); } finally { source.getPersistenceContext().decrementCascadeLevel(); } }
private Session openTemporarySessionForLoading(PersistentCollection coll) { final SessionFactory sf = _sessionFactory; final Session session = sf.openSession(); PersistenceContext persistenceContext = ((SessionImplementor) session).getPersistenceContext(); persistenceContext.setDefaultReadOnly(true); session.setFlushMode(FlushMode.MANUAL); persistenceContext.addUninitializedDetachedCollection( ((SessionFactoryImplementor) _sessionFactory).getCollectionPersister(coll.getRole()), coll ); return session; }
/** * Get the collection entry for a collection passed to filter, * which might be a collection wrapper, an array, or an unwrapped * collection. Return null if there is no entry. */ public CollectionEntry getCollectionEntryOrNull(Object collection) { PersistentCollection coll; if ( collection instanceof PersistentCollection ) { coll = (PersistentCollection) collection; //if (collection==null) throw new TransientObjectException("Collection was not yet persistent"); } else { coll = getCollectionHolder(collection); if ( coll == null ) { //it might be an unwrapped collection reference! //try to find a wrapper (slowish) Iterator wrappers = IdentityMap.keyIterator(collectionEntries); while ( wrappers.hasNext() ) { PersistentCollection pc = (PersistentCollection) wrappers.next(); if ( pc.isWrapper(collection) ) { coll = pc; break; } } } } return (coll == null) ? null : getCollectionEntry(coll); }
/** * Return the existing proxy associated with the given <tt>EntityKey</tt>, or the * argument (the entity associated with the key) if no proxy exists. * (slower than the form above) */ public Object proxyFor(Object impl) throws HibernateException { EntityEntry e = getEntry(impl); EntityPersister p = e.getPersister(); return proxyFor( p, new EntityKey( e.getId(), p, session.getEntityMode() ), impl ); }
Object entity = persistenceContext.unproxyAndReassociate( event.getObject() ); EntityEntry entityEntry = persistenceContext.getEntry( entity ); final EntityPersister persister; final Serializable id; persistenceContext.checkUniqueness(key, entity); entityEntry = persistenceContext.addEntity( entity, Status.MANAGED,
source.getPersistenceContext().addEntry( entity, Status.SAVING, source.getPersistenceContext().checkUniqueness(key, entity); source.getPersistenceContext().addEntity( entity, (persister.isMutable() ? Status.MANAGED : Status.READ_ONLY),
session.getInterceptor().preFlush( persistenceContext.getEntitiesByKey().values().iterator() ); persistenceContext.setFlushing(true); try { flushEntities(event); persistenceContext.setFlushing(false); session.getActionQueue().numberOfUpdates() + " updates, " + session.getActionQueue().numberOfDeletions() + " deletions to " + persistenceContext.getEntityEntries().size() + " objects" ); log.debug( "Flushed: " + session.getActionQueue().numberOfCollectionUpdates() + " updates, " + session.getActionQueue().numberOfCollectionRemovals() + " removals to " + persistenceContext.getCollectionEntries().size() + " collections" ); new Printer( session.getFactory() ).toString( persistenceContext.getEntitiesByKey().values().iterator(), session.getEntityMode() );
/** * 1. Recreate the collection key -> collection map * 2. rebuild the collection entries * 3. call Interceptor.postFlush() */ protected void postFlush(SessionImplementor session) throws HibernateException { log.trace( "post flush" ); final PersistenceContext persistenceContext = session.getPersistenceContext(); persistenceContext.getCollectionsByKey().clear(); persistenceContext.getBatchFetchQueue().clearSubselects(); //the database has changed now, so the subselect results need to be invalidated Iterator iter = persistenceContext.getCollectionEntries().entrySet().iterator(); while ( iter.hasNext() ) { Map.Entry me = (Map.Entry) iter.next(); CollectionEntry ce = (CollectionEntry) me.getValue(); PersistentCollection pc = (PersistentCollection) me.getKey(); if ( ce.postFlush(pc) ) { //if the collection is dereferenced, remove from the session cache iter.remove(); } else if ( ce.isReached() ) { //otherwise recreate the mapping between the collection and its key persistenceContext.getCollectionsByKey().put( new CollectionKey( ce.getCurrentPersister(), ce.getCurrentKey(), session.getEntityMode() ), pc ); } } session.getInterceptor().postFlush( persistenceContext.getEntitiesByKey().values().iterator() ); }
source.getPersistenceContext().checkUniqueness(id, persister, object); Object version = Versioning.getVersion(values, persister); EntityEntry newEntry = source.getPersistenceContext().addEntity( object, Status.MANAGED,
context.addCollectionHolder(lce.collection); CollectionEntry ce = context.getCollectionEntry(lce.collection); if ( ce==null ) { ce = context.addInitializedCollection(lce.collection, persister, lce.key, em); final SessionImplementor session = context.getSession(); log.debug( "collection fully initialized: " + MessageHelper.collectionInfoString(persister, lce.key, context.getSession().getFactory()) );
public int getCollectionCount() { return session.getPersistenceContext().getCollectionEntries().keySet().size(); }
if ( source.getPersistenceContext().reassociateIfUninitializedProxy( event.getObject() ) ) { log.trace("uninitialized proxy passed to replicate()"); return; Object entity = source.getPersistenceContext().unproxyAndReassociate( event.getObject() ); if ( source.getPersistenceContext().isEntryFor(entity) ) { log.trace("ignoring persistent instance passed to replicate()");
public int getEntityCount() { return session.getPersistenceContext().getEntityEntries().keySet().size(); }
public String getEntityName(Object object) { if (object instanceof HibernateProxy) { if ( !persistenceContext.containsProxy( object ) ) { throw new TransientObjectException("proxy was not associated with the session"); } object = ( (HibernateProxy) object ).getHibernateLazyInitializer().getImplementation(); } EntityEntry entry = persistenceContext.getEntry(object); if (entry==null) throwTransientObjectException(object); return entry.getPersister().getEntityName(); }
/** * Is this instance persistent or detached? * If <tt>assumed</tt> is non-null, don't hit the database to make the * determination, instead assume that value; the client code must be * prepared to "recover" in the case that this assumed result is incorrect. */ public static boolean isNotTransient(String entityName, Object entity, Boolean assumed, SessionImplementor session) throws HibernateException { if (entity instanceof HibernateProxy) return true; if ( session.getPersistenceContext().isEntryFor(entity) ) return true; return !isTransient(entityName, entity, assumed, session); }
/** * Add an uninitialized instance of an entity class, as a placeholder to ensure object * identity. Must be called before <tt>postHydrate()</tt>. * * Create a "temporary" entry for a newly instantiated entity. The entity is uninitialized, * but we need the mapping from id to instance in order to guarantee uniqueness. */ public static void addUninitializedEntity( Serializable id, Object object, EntityPersister persister, LockMode lockMode, SessionImplementor session ) { session.getPersistenceContext().addEntity(object, Status.LOADING, null, id, null, lockMode, true, persister, false); }
private void evictCollection(PersistentCollection collection) { CollectionEntry ce = (CollectionEntry) getSession().getPersistenceContext().getCollectionEntries().remove(collection); if ( log.isDebugEnabled() ) log.debug( "evicting collection: " + MessageHelper.collectionInfoString( ce.getLoadedPersister(), ce.getLoadedKey(), getSession().getFactory() ) ); if ( ce.getLoadedPersister() != null && ce.getLoadedKey() != null ) { //TODO: is this 100% correct? getSession().getPersistenceContext().getCollectionsByKey().remove( new CollectionKey( ce.getLoadedPersister(), ce.getLoadedKey(), getSession().getEntityMode() ) ); } }