Author: steve.ebersole(a)jboss.com
Date: 2007-01-23 08:54:33 -0500 (Tue, 23 Jan 2007)
New Revision: 11078
Modified:
trunk/Hibernate3/src/org/hibernate/engine/StatefulPersistenceContext.java
Log:
HHH-2112 : persistence-context cached db snapshot;
javadocs
Modified: trunk/Hibernate3/src/org/hibernate/engine/StatefulPersistenceContext.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/engine/StatefulPersistenceContext.java 2007-01-23
12:54:42 UTC (rev 11077)
+++ trunk/Hibernate3/src/org/hibernate/engine/StatefulPersistenceContext.java 2007-01-23
13:54:33 UTC (rev 11078)
@@ -24,6 +24,7 @@
import org.hibernate.NonUniqueObjectException;
import org.hibernate.PersistentObjectException;
import org.hibernate.TransientObjectException;
+import org.hibernate.pretty.MessageHelper;
import org.hibernate.collection.PersistentCollection;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityPersister;
@@ -272,9 +273,23 @@
}
}
+ /**
+ * Retrieve the cached database snapshot for the requested entity key.
+ * <p/>
+ * This differs from {@link #getDatabaseSnapshot} is two important respects:<ol>
+ * <li>no snapshot is obtained from the database if not already cached</li>
+ * <li>an entry of {@link #NO_ROW} here is interpretet as an exception</li>
+ * </ol>
+ * @param key The entity key for which to retrieve the cached snapshot
+ * @return The cached snapshot
+ * @throws IllegalStateException if the cached snapshot was == {@link #NO_ROW}.
+ */
public Object[] getCachedDatabaseSnapshot(EntityKey key) {
- //TODO: assertion failure if NO_ROW
- return (Object[]) entitySnapshotsByKey.get(key);
+ Object snapshot = entitySnapshotsByKey.get( key );
+ if ( snapshot == NO_ROW ) {
+ throw new IllegalStateException( "persistence context reported no row snapshot
for " + MessageHelper.infoString( key.getEntityName(), key.getIdentifier() ) );
+ }
+ return ( Object[] ) snapshot;
}
/*public void removeDatabaseSnapshot(EntityKey key) {
@@ -482,13 +497,19 @@
/**
* Associate a proxy that was instantiated by another session with this session
+ *
+ * @param li The proxy initializer.
+ * @param proxy The proxy to reassociate.
*/
- private void reassociateProxy(LazyInitializer li, HibernateProxy proxy) throws
HibernateException {
- if ( li.getSession() != this ) {
+ private void reassociateProxy(LazyInitializer li, HibernateProxy proxy) {
+ if ( li.getSession() != this.getSession() ) {
EntityPersister persister = session.getFactory().getEntityPersister(
li.getEntityName() );
EntityKey key = new EntityKey( li.getIdentifier(), persister, session.getEntityMode()
);
- if ( !proxiesByKey.containsKey(key) ) proxiesByKey.put(key, proxy); // any earlier
proxy takes precedence
- proxy.getHibernateLazyInitializer().setSession(session);
+ // any earlier proxy takes precedence
+ if ( !proxiesByKey.containsKey( key ) ) {
+ proxiesByKey.put( key, proxy );
+ }
+ proxy.getHibernateLazyInitializer().setSession( session );
}
}
@@ -669,19 +690,25 @@
throws HibernateException {
addCollection(collection, persister);
}
-
+
/**
- * Add an collection to the cache, with a given collection entry
+ * Add an collection to the cache, with a given collection entry.
+ *
+ * @param coll The collection for which we are adding an entry.
+ * @param entry The entry representing the collection.
+ * @param key The key of the collection's entry.
*/
private void addCollection(PersistentCollection coll, CollectionEntry entry,
Serializable key) {
- collectionEntries.put(coll, entry);
+ collectionEntries.put( coll, entry );
CollectionKey collectionKey = new CollectionKey( entry.getLoadedPersister(), key,
session.getEntityMode() );
- PersistentCollection old = (PersistentCollection) collectionsByKey.put(collectionKey,
coll);
+ PersistentCollection old = ( PersistentCollection ) collectionsByKey.put(
collectionKey, coll );
if ( old != null ) {
- if (old==coll) throw new AssertionFailure("bug adding collection twice");
+ if ( old == coll ) {
+ throw new AssertionFailure("bug adding collection twice");
+ }
// or should it actually throw an exception?
- old.unsetSession(session);
- collectionEntries.remove(old);
+ old.unsetSession( session );
+ collectionEntries.remove( old );
// watch out for a case where old is still referenced
// somewhere in the object graph! (which is a user error)
}
@@ -689,11 +716,13 @@
/**
* Add a collection to the cache, creating a new collection entry for it
+ *
+ * @param collection The collection for which we are adding an entry.
+ * @param persister The collection persister
*/
- private void addCollection(PersistentCollection collection, CollectionPersister
persister)
- throws HibernateException {
- CollectionEntry ce = new CollectionEntry(persister, collection);
- collectionEntries.put(collection, ce);
+ private void addCollection(PersistentCollection collection, CollectionPersister
persister) {
+ CollectionEntry ce = new CollectionEntry( persister, collection );
+ collectionEntries.put( collection, ce );
}
/**
@@ -1134,7 +1163,7 @@
* persistence context.
*
* @param oos The stream to which the persistence context should get written
- * @throws IOException
+ * @throws IOException serialization errors.
*/
public void serialize(ObjectOutputStream oos) throws IOException {
log.trace( "serializing persistent-context" );