org.hibernate.type.CollectionType Java Examples

The following examples show how to use org.hibernate.type.CollectionType. 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: EvictVisitor.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void evictCollection(Object value, CollectionType type) {

		final Object pc;
		if ( type.hasHolder( getSession().getEntityMode() ) ) {
			pc = getSession().getPersistenceContext().removeCollectionHolder(value);
		}
		else if ( value instanceof PersistentCollection ) {
			pc = value;
		}
		else {
			return; //EARLY EXIT!
		}

		PersistentCollection collection = (PersistentCollection) pc;
		if ( collection.unsetSession( getSession() ) ) evictCollection(collection);
	}
 
Example #2
Source File: AbstractEntityPersister.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected Serializable getCollectionKey(
		CollectionPersister persister,
		Object owner,
		EntityEntry ownerEntry,
		SharedSessionContractImplementor session) {
	final CollectionType collectionType = persister.getCollectionType();

	if ( ownerEntry != null ) {
		// this call only works when the owner is associated with the Session, which is not always the case
		return collectionType.getKeyOfOwner( owner, session );
	}

	if ( collectionType.getLHSPropertyName() == null ) {
		// collection key is defined by the owning entity identifier
		return persister.getOwnerEntityPersister().getIdentifier( owner, session );
	}
	else {
		return (Serializable) persister.getOwnerEntityPersister().getPropertyValue( owner, collectionType.getLHSPropertyName() );
	}
}
 
Example #3
Source File: Nullability.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * check sub elements-nullability. Returns property path that break
 * nullability or null if none
 *
 * @param propertyType type to check
 * @param value value to check
 *
 * @return property path
 * @throws HibernateException error while getting subcomponent values
 */
private String checkSubElementsNullability(Type propertyType, Object value) throws HibernateException {
	if ( propertyType.isComponentType() ) {
		return checkComponentNullability( value, (CompositeType) propertyType );
	}

	if ( propertyType.isCollectionType() ) {
		// persistent collections may have components
		final CollectionType collectionType = (CollectionType) propertyType;
		final Type collectionElementType = collectionType.getElementType( session.getFactory() );

		if ( collectionElementType.isComponentType() ) {
			// check for all components values in the collection
			final CompositeType componentType = (CompositeType) collectionElementType;
			final Iterator itr = CascadingActions.getLoadedElementsIterator( session, collectionType, value );
			while ( itr.hasNext() ) {
				final Object compositeElement = itr.next();
				if ( compositeElement != null ) {
					return checkComponentNullability( compositeElement, componentType );
				}
			}
		}
	}

	return null;
}
 
Example #4
Source File: AbstractEmptinessExpression.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected QueryableCollection getQueryableCollection(String entityName, String propertyName, SessionFactoryImplementor factory)
        throws HibernateException {
	PropertyMapping ownerMapping = ( PropertyMapping ) factory.getEntityPersister( entityName );
	Type type = ownerMapping.toType( propertyName );
	if ( !type.isCollectionType() ) {
		throw new MappingException(
		        "Property path [" + entityName + "." + propertyName + "] does not reference a collection"
		);
	}

	String role = ( ( CollectionType ) type ).getRole();
	try {
		return ( QueryableCollection ) factory.getCollectionPersister( role );
	}
	catch ( ClassCastException cce ) {
		throw new QueryException( "collection role is not queryable: " + role );
	}
	catch ( Exception e ) {
		throw new QueryException( "collection role not found: " + role );
	}
}
 
Example #5
Source File: WrapVisitor.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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 );
	}

}
 
Example #6
Source File: Map.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public CollectionType getDefaultCollectionType() {
	if ( isSorted() ) {
		return getMetadata().getTypeResolver()
				.getTypeFactory()
				.sortedMap( getRole(), getReferencedPropertyName(), getComparator() );
	}
	else if ( hasOrder() ) {
		return getMetadata().getTypeResolver()
				.getTypeFactory()
				.orderedMap( getRole(), getReferencedPropertyName() );
	}
	else {
		return getMetadata().getTypeResolver()
				.getTypeFactory()
				.map( getRole(), getReferencedPropertyName() );
	}
}
 
Example #7
Source File: Set.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public CollectionType getDefaultCollectionType() {
	if ( isSorted() ) {
		return getMetadata().getTypeResolver()
				.getTypeFactory()
				.sortedSet( getRole(), getReferencedPropertyName(), getComparator() );
	}
	else if ( hasOrder() ) {
		return getMetadata().getTypeResolver()
				.getTypeFactory()
				.orderedSet( getRole(), getReferencedPropertyName() );
	}
	else {
		return getMetadata().getTypeResolver()
				.getTypeFactory()
				.set( getRole(), getReferencedPropertyName() );
	}
}
 
Example #8
Source File: PathExpressionParser.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void end(QueryTranslatorImpl q) throws QueryException {
	ignoreInitialJoin = false;

	Type propertyType = getPropertyType();
	if ( propertyType != null && propertyType.isCollectionType() ) {
		collectionRole = ( ( CollectionType ) propertyType ).getRole();
		collectionName = q.createNameForCollection( collectionRole );
		prepareForIndex( q );
	}
	else {
		columns = currentColumns();
		setType();
	}

	//important!!
	continuation = false;

}
 
Example #9
Source File: AbstractEmptinessExpression.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected QueryableCollection getQueryableCollection(
		String entityName,
		String propertyName,
		SessionFactoryImplementor factory) throws HibernateException {
	final PropertyMapping ownerMapping = (PropertyMapping) factory.getEntityPersister( entityName );
	final Type type = ownerMapping.toType( propertyName );
	if ( !type.isCollectionType() ) {
		throw new MappingException(
				"Property path [" + entityName + "." + propertyName + "] does not reference a collection"
		);
	}

	final String role = ( (CollectionType) type ).getRole();
	try {
		return (QueryableCollection) factory.getCollectionPersister( role );
	}
	catch ( ClassCastException cce ) {
		throw new QueryException( "collection role is not queryable: " + role );
	}
	catch ( Exception e ) {
		throw new QueryException( "collection role not found: " + role );
	}
}
 
Example #10
Source File: DefaultRefreshEventListener.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void evictCachedCollections(Type[] types, Serializable id, EventSource source)
		throws HibernateException {
	for ( Type type : types ) {
		if ( type.isCollectionType() ) {
			CollectionPersister collectionPersister = source.getFactory().getMetamodel().collectionPersister( ( (CollectionType) type ).getRole() );
			if ( collectionPersister.hasCache() ) {
				final CollectionDataAccess cache = collectionPersister.getCacheAccessStrategy();
				final Object ck = cache.generateCacheKey(
					id,
					collectionPersister,
					source.getFactory(),
					source.getTenantIdentifier()
				);
				final SoftLock lock = cache.lockItem( source, ck, null );
				cache.remove( source, ck );
				source.getActionQueue().registerProcess( (success, session) -> cache.unlockItem( session, ck, lock ) );
			}
		}
		else if ( type.isComponentType() ) {
			CompositeType actype = (CompositeType) type;
			evictCachedCollections( actype.getSubtypes(), id, source );
		}
	}
}
 
Example #11
Source File: PathExpressionParser.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void end(QueryTranslatorImpl q) throws QueryException {
	ignoreInitialJoin = false;

	Type propertyType = getPropertyType();
	if ( propertyType != null && propertyType.isCollectionType() ) {
		collectionRole = ( ( CollectionType ) propertyType ).getRole();
		collectionName = q.createNameForCollection( collectionRole );
		prepareForIndex( q );
	}
	else {
		columns = currentColumns();
		setType();
	}

	//important!!
	continuation = false;

}
 
Example #12
Source File: JoinHelper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public JoinDefinedByMetadata createCollectionJoin(
		QuerySpace leftHandSide,
		String lhsPropertyName,
		CollectionQuerySpace rightHandSide,
		boolean rightHandSideRequired,
		CollectionType joinedPropertyType,
		SessionFactoryImplementor sessionFactory) {
	return new JoinImpl(
			leftHandSide,
			lhsPropertyName,
			rightHandSide,
			joinedPropertyType.getAssociatedJoinable( sessionFactory ).getKeyColumnNames(),
			joinedPropertyType,
			rightHandSideRequired
	);
}
 
Example #13
Source File: Cascade.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Cascade an action to a collection
 */
private void cascadeCollection(
		final Object child,
		final CascadeStyle style,
		final Object anything,
		final CollectionType type) {
	CollectionPersister persister = eventSource.getFactory()
			.getCollectionPersister( type.getRole() );
	Type elemType = persister.getElementType();

	final int oldCascadeTo = cascadeTo;
	if ( cascadeTo==AFTER_INSERT_BEFORE_DELETE) {
		cascadeTo = AFTER_INSERT_BEFORE_DELETE_VIA_COLLECTION;
	}

	//cascade to current collection elements
	if ( elemType.isEntityType() || elemType.isAnyType() || elemType.isComponentType() ) {
		cascadeCollectionElements(
			child,
			type,
			style,
			elemType,
			anything,
			persister.isCascadeDeleteEnabled()
		);
	}

	cascadeTo = oldCascadeTo;
}
 
Example #14
Source File: EvictVisitor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
Object processCollection(Object collection, CollectionType type) throws HibernateException {
	if (collection != null) {
		evictCollection(collection, type);
	}

	return null;
}
 
Example #15
Source File: DefaultRefreshEventListener.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void evictCachedCollections(Type[] types, Serializable id, SessionFactoryImplementor factory)
throws HibernateException {
	for ( int i = 0; i < types.length; i++ ) {
		if ( types[i].isCollectionType() ) {
			factory.evictCollection( ( (CollectionType) types[i] ).getRole(), id );
		}
		else if ( types[i].isComponentType() ) {
			AbstractComponentType actype = (AbstractComponentType) types[i];
			evictCachedCollections( actype.getSubtypes(), id, factory );
		}
	}
}
 
Example #16
Source File: WrapVisitor.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 #17
Source File: OnLockVisitor.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
Object processCollection(Object collection, CollectionType type) throws HibernateException {

		SessionImplementor session = getSession();
		CollectionPersister persister = session.getFactory().getCollectionPersister( type.getRole() );

		if ( collection == null ) {
			//do nothing
		}
		else if ( collection instanceof PersistentCollection ) {
			PersistentCollection persistentCollection = ( PersistentCollection ) collection;
			if ( persistentCollection.setCurrentSession( session ) ) {
				if ( isOwnerUnchanged( persistentCollection, persister, extractCollectionKeyFromOwner( persister ) ) ) {
					// a "detached" collection that originally belonged to the same entity
					if ( persistentCollection.isDirty() ) {
						throw new HibernateException( "reassociated object has dirty collection" );
					}
					reattachCollection( persistentCollection, type );
				}
				else {
					// a "detached" collection that belonged to a different entity
					throw new HibernateException( "reassociated object has dirty collection reference" );
				}
			}
			else {
				// a collection loaded in the current session
				// can not possibly be the collection belonging
				// to the entity passed to update()
				throw new HibernateException( "reassociated object has dirty collection reference" );
			}
		}
		else {
			// brand new collection
			//TODO: or an array!! we can't lock objects with arrays now??
			throw new HibernateException( "reassociated object has dirty collection reference (or an array)" );
		}

		return null;

	}
 
Example #18
Source File: Collection.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public CollectionType getCollectionType() {
	if ( typeName == null ) {
		return getDefaultCollectionType();
	}
	else {
		return TypeFactory.customCollection( typeName, typeParameters, role, referencedPropertyName, isEmbedded() );
	}
}
 
Example #19
Source File: IdentNode.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void resolveIndex(AST parent) throws SemanticException {
	// An ident node can represent an index expression if the ident
	// represents a naked property ref
	//      *Note: this makes the assumption (which is currently the case
	//      in the hql-sql grammar) that the ident is first resolved
	//      itself (addrExpr -> resolve()).  The other option, if that
	//      changes, is to call resolve from here; but it is
	//      currently un-needed overhead.
	if (!(isResolved() && nakedPropertyRef)) {
		throw new UnsupportedOperationException();
	}

	String propertyName = getOriginalText();
	if (!getDataType().isCollectionType()) {
		throw new SemanticException("Collection expected; [" + propertyName + "] does not refer to a collection property");
	}

	// TODO : most of below was taken verbatim from DotNode; should either delegate this logic or super-type it
	CollectionType type = (CollectionType) getDataType();
	String role = type.getRole();
	QueryableCollection queryableCollection = getSessionFactoryHelper().requireQueryableCollection(role);

	String alias = null;  // DotNode uses null here...
	String columnTableAlias = getFromElement().getTableAlias();
	JoinType joinType = JoinType.INNER_JOIN;
	boolean fetch = false;

	FromElementFactory factory = new FromElementFactory(
			getWalker().getCurrentFromClause(),
			getFromElement(),
			propertyName,
			alias,
			getFromElement().toColumns(columnTableAlias, propertyName, false),
			true
	);
	FromElement elem = factory.createCollection(queryableCollection, role, joinType, fetch, true);
	setFromElement(elem);
	getWalker().addQuerySpaces(queryableCollection.getCollectionSpaces());	// Always add the collection's query spaces.
}
 
Example #20
Source File: OnUpdateVisitor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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 #21
Source File: DotNode.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void resolveIndex(AST parent) throws SemanticException {
	if ( isResolved() ) {
		return;
	}
	Type propertyType = prepareLhs();            // Prepare the left hand side and get the data type.
	dereferenceCollection( (CollectionType) propertyType, true, true, null, parent );
}
 
Example #22
Source File: Nullability.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * check sub elements-nullability. Returns property path that break
 * nullability or null if none
 *
 * @param propertyType type to check
 * @param value value to check
 *
 * @return property path
 * @throws HibernateException error while getting subcomponent values
 */
private String checkSubElementsNullability(final Type propertyType, final Object value) 
throws HibernateException {
	//for non null args, check for components and elements containing components
	if ( propertyType.isComponentType() ) {
		return checkComponentNullability( value, (AbstractComponentType) propertyType );
	}
	else if ( propertyType.isCollectionType() ) {

		//persistent collections may have components
		CollectionType collectionType = (CollectionType) propertyType;
		Type collectionElementType = collectionType.getElementType( session.getFactory() );
		if ( collectionElementType.isComponentType() ) {
			//check for all components values in the collection

			AbstractComponentType componentType = (AbstractComponentType) collectionElementType;
			Iterator iter = CascadingAction.getLoadedElementsIterator(session, collectionType, value);
			while ( iter.hasNext() ) {
				Object compValue = iter.next();
				if (compValue != null) {
					return checkComponentNullability(compValue, componentType);
				}
			}
		}
	}
	return null;
}
 
Example #23
Source File: Set.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public CollectionType getDefaultCollectionType() {
	if ( isSorted() ) {
		return TypeFactory.sortedSet( getRole(), getReferencedPropertyName(), isEmbedded(), getComparator() );
	}
	else if ( hasOrder() ) {
		return TypeFactory.orderedSet( getRole(), getReferencedPropertyName(), isEmbedded() );
	}
	else {
		return TypeFactory.set( getRole(), getReferencedPropertyName(), isEmbedded() );
	}
}
 
Example #24
Source File: OnUpdateVisitor.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@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 #25
Source File: OnReplicateVisitor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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 #26
Source File: AbstractMapComponentNode.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void resolve(
		boolean generateJoin,
		boolean implicitJoin,
		String classAlias,
		AST parent,
		AST parentPredicate) throws SemanticException {
	if ( mapFromElement == null ) {
		final FromReferenceNode mapReference = getMapReference();
		mapReference.resolve( true, true );

		FromElement sourceFromElement = null;
		if ( isAliasRef( mapReference ) ) {
			final QueryableCollection collectionPersister = mapReference.getFromElement().getQueryableCollection();
			if ( Map.class.isAssignableFrom( collectionPersister.getCollectionType().getReturnedClass() ) ) {
				sourceFromElement = mapReference.getFromElement();
			}
		}
		else {
			if ( mapReference.getDataType().isCollectionType() ) {
				final CollectionType collectionType = (CollectionType) mapReference.getDataType();
				if ( Map.class.isAssignableFrom( collectionType.getReturnedClass() ) ) {
					sourceFromElement = mapReference.getFromElement();
				}
			}
		}

		if ( sourceFromElement == null ) {
			throw nonMap();
		}

		mapFromElement = sourceFromElement;
	}

	setFromElement( mapFromElement );
	setDataType( resolveType( mapFromElement.getQueryableCollection() ) );
	this.columns = resolveColumns( mapFromElement.getQueryableCollection() );
	initText( this.columns );
	setFirstChild( null );
}
 
Example #27
Source File: CascadingAction.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Iterate just the elements of the collection that are already there. Don't load
 * any new elements from the database.
 */
public static Iterator getLoadedElementsIterator(SessionImplementor session, CollectionType collectionType, Object collection) {
	if ( collectionIsInitialized(collection) ) {
		// handles arrays and newly instantiated collections
		return collectionType.getElementsIterator(collection, session);
	}
	else {
		// does not handle arrays (thats ok, cos they can't be lazy)
		// or newly instantiated collections, so we can do the cast
		return ( (PersistentCollection) collection ).queuedAdditionIterator();
	}
}
 
Example #28
Source File: Cascade.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static void cascadeAssociation(
		final CascadingAction action,
		final CascadePoint cascadePoint,
		final EventSource eventSource,
		final int componentPathStackDepth,
		final Object parent,
		final Object child,
		final Type type,
		final CascadeStyle style,
		final Object anything,
		final boolean isCascadeDeleteEnabled) {
	if ( type.isEntityType() || type.isAnyType() ) {
		cascadeToOne( action, eventSource, parent, child, type, style, anything, isCascadeDeleteEnabled );
	}
	else if ( type.isCollectionType() ) {
		cascadeCollection(
				action,
				cascadePoint,
				eventSource,
				componentPathStackDepth,
				parent,
				child,
				style,
				anything,
				(CollectionType) type
		);
	}
}
 
Example #29
Source File: CascadingActions.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Iterate just the elements of the collection that are already there. Don't load
 * any new elements from the database.
 */
public static Iterator getLoadedElementsIterator(
		SharedSessionContractImplementor session,
		CollectionType collectionType,
		Object collection) {
	if ( collectionIsInitialized( collection ) ) {
		// handles arrays and newly instantiated collections
		return collectionType.getElementsIterator( collection, session );
	}
	else {
		// does not handle arrays (thats ok, cos they can't be lazy)
		// or newly instantiated collections, so we can do the cast
		return ((PersistentCollection) collection).queuedAdditionIterator();
	}
}
 
Example #30
Source File: CascadingActions.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Iterator getCascadableChildrenIterator(
		EventSource session,
		CollectionType collectionType,
		Object collection) {
	// replicate does cascade to uninitialized collections
	return getLoadedElementsIterator( session, collectionType, collection );
}