Java Code Examples for org.hibernate.type.CollectionType#UNFETCHED_COLLECTION
The following examples show how to use
org.hibernate.type.CollectionType#UNFETCHED_COLLECTION .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OnUpdateVisitor.java From lams with GNU General Public License v2.0 | 5 votes |
@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; }
Example 2
Source File: OnReplicateVisitor.java From lams with GNU General Public License v2.0 | 5 votes |
@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; }
Example 3
Source File: OnUpdateVisitor.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * {@inheritDoc} */ 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; }
Example 4
Source File: WrapVisitor.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
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( session.getEntityMode() ) ) { 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.trace( "Wrapped collection in role: " + collectionType.getRole() ); return persistentCollection; //Force a substitution! } } }
Example 5
Source File: OnReplicateVisitor.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
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() ); if ( isUpdate ) { removeCollection( persister, extractCollectionKeyFromOwner( persister ), session ); } if ( collection != null && ( collection instanceof PersistentCollection ) ) { PersistentCollection wrapper = ( PersistentCollection ) collection; wrapper.setCurrentSession( 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; }
Example 6
Source File: WrapVisitor.java From lams with GNU General Public License v2.0 | 4 votes |
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() ); } return persistentCollection; //Force a substitution! } } }
Example 7
Source File: Cascade.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
/** * Cascade to the collection elements */ private void cascadeCollectionElements( final Object child, final CollectionType collectionType, final CascadeStyle style, final Type elemType, final Object anything, final boolean isCascadeDeleteEnabled) throws HibernateException { // we can't cascade to non-embedded elements boolean embeddedElements = eventSource.getEntityMode()!=EntityMode.DOM4J || ( (EntityType) collectionType.getElementType( eventSource.getFactory() ) ).isEmbeddedInXML(); boolean reallyDoCascade = style.reallyDoCascade(action) && embeddedElements && child!=CollectionType.UNFETCHED_COLLECTION; if ( reallyDoCascade ) { if ( log.isTraceEnabled() ) { log.trace( "cascade " + action + " for collection: " + collectionType.getRole() ); } Iterator iter = action.getCascadableChildrenIterator(eventSource, collectionType, child); while ( iter.hasNext() ) { cascadeProperty( iter.next(), elemType, style, anything, isCascadeDeleteEnabled ); } if ( log.isTraceEnabled() ) { log.trace( "done cascade " + action + " for collection: " + collectionType.getRole() ); } } final boolean deleteOrphans = style.hasOrphanDelete() && action.deleteOrphans() && elemType.isEntityType() && child instanceof PersistentCollection; //a newly instantiated collection can't have orphans if ( deleteOrphans ) { // handle orphaned entities!! if ( log.isTraceEnabled() ) { log.trace( "deleting orphans for collection: " + collectionType.getRole() ); } // we can do the cast since orphan-delete does not apply to: // 1. newly instantiated collections // 2. arrays (we can't track orphans for detached arrays) final String entityName = collectionType.getAssociatedEntityName( eventSource.getFactory() ); deleteOrphans( entityName, (PersistentCollection) child ); if ( log.isTraceEnabled() ) { log.trace( "done deleting orphans for collection: " + collectionType.getRole() ); } } }