use of org.hibernate.engine.spi.CollectionKey in project hibernate-orm by hibernate.
the class StatefulPersistenceContext method addCollection.
/**
* 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);
final CollectionKey collectionKey = new CollectionKey(entry.getLoadedPersister(), key);
final PersistentCollection old = collectionsByKey.put(collectionKey, coll);
if (old != null) {
if (old == coll) {
throw new AssertionFailure("bug adding collection twice");
}
// or should it actually throw an exception?
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)
}
}
use of org.hibernate.engine.spi.CollectionKey in project hibernate-orm by hibernate.
the class StatefulPersistenceContext method serialize.
/**
* Used by the owning session to explicitly control serialization of the
* persistence context.
*
* @param oos The stream to which the persistence context should get written
* @throws IOException serialization errors.
*/
public void serialize(ObjectOutputStream oos) throws IOException {
final boolean tracing = LOG.isTraceEnabled();
if (tracing) {
LOG.trace("Serializing persisatence-context");
}
oos.writeBoolean(defaultReadOnly);
oos.writeBoolean(hasNonReadOnlyEntities);
oos.writeInt(entitiesByKey.size());
if (tracing) {
LOG.trace("Starting serialization of [" + entitiesByKey.size() + "] entitiesByKey entries");
}
for (Map.Entry<EntityKey, Object> entry : entitiesByKey.entrySet()) {
entry.getKey().serialize(oos);
oos.writeObject(entry.getValue());
}
oos.writeInt(entitiesByUniqueKey.size());
if (tracing) {
LOG.trace("Starting serialization of [" + entitiesByUniqueKey.size() + "] entitiesByUniqueKey entries");
}
for (Map.Entry<EntityUniqueKey, Object> entry : entitiesByUniqueKey.entrySet()) {
entry.getKey().serialize(oos);
oos.writeObject(entry.getValue());
}
oos.writeInt(proxiesByKey.size());
if (tracing) {
LOG.trace("Starting serialization of [" + proxiesByKey.size() + "] proxiesByKey entries");
}
for (Map.Entry<EntityKey, Object> entry : proxiesByKey.entrySet()) {
entry.getKey().serialize(oos);
oos.writeObject(entry.getValue());
}
oos.writeInt(entitySnapshotsByKey.size());
if (tracing) {
LOG.trace("Starting serialization of [" + entitySnapshotsByKey.size() + "] entitySnapshotsByKey entries");
}
for (Map.Entry<EntityKey, Object> entry : entitySnapshotsByKey.entrySet()) {
entry.getKey().serialize(oos);
oos.writeObject(entry.getValue());
}
entityEntryContext.serialize(oos);
oos.writeInt(collectionsByKey.size());
if (tracing) {
LOG.trace("Starting serialization of [" + collectionsByKey.size() + "] collectionsByKey entries");
}
for (Map.Entry<CollectionKey, PersistentCollection> entry : collectionsByKey.entrySet()) {
entry.getKey().serialize(oos);
oos.writeObject(entry.getValue());
}
oos.writeInt(collectionEntries.size());
if (tracing) {
LOG.trace("Starting serialization of [" + collectionEntries.size() + "] collectionEntries entries");
}
for (Map.Entry<PersistentCollection, CollectionEntry> entry : collectionEntries.entrySet()) {
oos.writeObject(entry.getKey());
entry.getValue().serialize(oos);
}
oos.writeInt(arrayHolders.size());
if (tracing) {
LOG.trace("Starting serialization of [" + arrayHolders.size() + "] arrayHolders entries");
}
for (Map.Entry<Object, PersistentCollection> entry : arrayHolders.entrySet()) {
oos.writeObject(entry.getKey());
oos.writeObject(entry.getValue());
}
oos.writeInt(nullifiableEntityKeys.size());
if (tracing) {
LOG.trace("Starting serialization of [" + nullifiableEntityKeys.size() + "] nullifiableEntityKey entries");
}
for (EntityKey entry : nullifiableEntityKeys) {
entry.serialize(oos);
}
}
Aggregations