use of org.hibernate.collection.spi.PersistentCollection in project hibernate-orm by hibernate.
the class OnReplicateVisitor method processCollection.
@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;
}
use of org.hibernate.collection.spi.PersistentCollection in project hibernate-orm by hibernate.
the class OnUpdateVisitor method processCollection.
@Override
Object processCollection(Object collection, CollectionType type) throws HibernateException {
if (collection == CollectionType.UNFETCHED_COLLECTION) {
return null;
}
EventSource session = getSession();
CollectionPersister persister = session.getFactory().getCollectionPersister(type.getRole());
final Serializable collectionKey = extractCollectionKeyFromOwner(persister);
if (collection != null && (collection instanceof PersistentCollection)) {
PersistentCollection wrapper = (PersistentCollection) collection;
if (wrapper.setCurrentSession(session)) {
//a "detached" collection!
if (!isOwnerUnchanged(wrapper, persister, collectionKey)) {
// if the collection belonged to a different entity,
// clean up the existing state of the collection
removeCollection(persister, collectionKey, session);
}
reattachCollection(wrapper, type);
} else {
// a collection loaded in the current session
// can not possibly be the collection belonging
// to the entity passed to update()
removeCollection(persister, collectionKey, session);
}
} else {
// null or brand new collection
// this will also (inefficiently) handle arrays, which have
// no snapshot, so we can't do any better
removeCollection(persister, collectionKey, session);
}
return null;
}
use of org.hibernate.collection.spi.PersistentCollection in project hibernate-orm by hibernate.
the class WrapVisitor method processCollection.
@Override
Object processCollection(Object collection, CollectionType collectionType) throws HibernateException {
if (collection != null && (collection instanceof PersistentCollection)) {
final SessionImplementor session = getSession();
PersistentCollection coll = (PersistentCollection) collection;
if (coll.setCurrentSession(session)) {
reattachCollection(coll, collectionType);
}
return null;
} else {
return processArrayOrNewCollection(collection, collectionType);
}
}
use of org.hibernate.collection.spi.PersistentCollection in project hibernate-orm by hibernate.
the class WrapVisitor method processArrayOrNewCollection.
final Object processArrayOrNewCollection(Object collection, CollectionType collectionType) throws HibernateException {
final SessionImplementor session = getSession();
if (collection == null) {
//do nothing
return null;
} else {
CollectionPersister persister = session.getFactory().getCollectionPersister(collectionType.getRole());
final PersistenceContext persistenceContext = session.getPersistenceContext();
//TODO: move into collection type, so we can use polymorphism!
if (collectionType.hasHolder()) {
if (collection == CollectionType.UNFETCHED_COLLECTION) {
return null;
}
PersistentCollection ah = persistenceContext.getCollectionHolder(collection);
if (ah == null) {
ah = collectionType.wrap(session, collection);
persistenceContext.addNewCollection(persister, ah);
persistenceContext.addCollectionHolder(ah);
}
return null;
} else {
PersistentCollection persistentCollection = collectionType.wrap(session, collection);
persistenceContext.addNewCollection(persister, persistentCollection);
if (LOG.isTraceEnabled()) {
LOG.tracev("Wrapped collection in role: {0}", collectionType.getRole());
}
//Force a substitution!
return persistentCollection;
}
}
}
use of org.hibernate.collection.spi.PersistentCollection in project hibernate-orm by hibernate.
the class EvictVisitor method evictCollection.
public void evictCollection(Object value, CollectionType type) {
final Object pc;
if (type.hasHolder()) {
pc = getSession().getPersistenceContext().removeCollectionHolder(value);
} else if (value instanceof PersistentCollection) {
pc = value;
} else {
//EARLY EXIT!
return;
}
PersistentCollection collection = (PersistentCollection) pc;
if (collection.unsetSession(getSession())) {
evictCollection(collection);
}
}
Aggregations