Java Code Examples for org.hibernate.persister.collection.CollectionPersister#getCollectionType()

The following examples show how to use org.hibernate.persister.collection.CollectionPersister#getCollectionType() . 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: 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 2
Source File: PersistentOwnedSet.java    From webdsl with Apache License 2.0 5 votes vote down vote up
public utils.AbstractOwnedSetType getOwnedSetType() {
	if(cachedType != null) {
		return cachedType;
	}
	else {
		SessionImplementor session = getSession();
		CollectionPersister persister = session.getPersistenceContext().getCollectionEntry(this).getLoadedPersister();
		if(persister.getCollectionType() instanceof CustomCollectionType && ((CustomCollectionType)persister.getCollectionType()).getUserType() instanceof utils.AbstractOwnedSetType) {
			cachedType = (utils.AbstractOwnedSetType)((CustomCollectionType)persister.getCollectionType()).getUserType();
			return cachedType;
		}
		return null;
	}
}
 
Example 3
Source File: PersistentOwnedList.java    From webdsl with Apache License 2.0 5 votes vote down vote up
public utils.AbstractOwnedListType getOwnedListType() {
	if(cachedType != null) {
		return cachedType;
	}
	else {
		SessionImplementor session = getSession();
		CollectionPersister persister = session.getPersistenceContext().getCollectionEntry(this).getLoadedPersister();
		if(persister.getCollectionType() instanceof CustomCollectionType && ((CustomCollectionType)persister.getCollectionType()).getUserType() instanceof utils.AbstractOwnedListType) {
			cachedType = (utils.AbstractOwnedListType)((CustomCollectionType)persister.getCollectionType()).getUserType();
			return cachedType;
		}
		return null;
	}
}
 
Example 4
Source File: StatefulPersistenceContext.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Object getCollectionOwner(Serializable key, CollectionPersister collectionPersister) throws MappingException {
	// todo : we really just need to add a split in the notions of:
	//		1) collection key
	//		2) collection owner key
	// these 2 are not always the same.  Same is true in the case of ToOne associations with property-ref...
	final EntityPersister ownerPersister = collectionPersister.getOwnerEntityPersister();
	if ( ownerPersister.getIdentifierType().getReturnedClass().isInstance( key ) ) {
		return getEntity( session.generateEntityKey( key, collectionPersister.getOwnerEntityPersister() ) );
	}

	// we have a property-ref type mapping for the collection key.  But that could show up a few ways here...
	//
	//		1) The incoming key could be the entity itself...
	if ( ownerPersister.isInstance( key ) ) {
		final Serializable owenerId = ownerPersister.getIdentifier( key, session );
		if ( owenerId == null ) {
			return null;
		}
		return getEntity( session.generateEntityKey( owenerId, ownerPersister ) );
	}

	final CollectionType collectionType = collectionPersister.getCollectionType();

	//		2) The incoming key is most likely the collection key which we need to resolve to the owner key
	//			find the corresponding owner instance
	//			a) try by EntityUniqueKey
	if ( collectionType.getLHSPropertyName() != null ) {
		final Object owner = getEntity(
				new EntityUniqueKey(
						ownerPersister.getEntityName(),
						collectionType.getLHSPropertyName(),
						key,
						collectionPersister.getKeyType(),
						ownerPersister.getEntityMode(),
						session.getFactory()
				)
		);
		if ( owner != null ) {
			return owner;
		}

		//		b) try by EntityKey, which means we need to resolve owner-key -> collection-key
		//			IMPL NOTE : yes if we get here this impl is very non-performant, but PersistenceContext
		//					was never designed to handle this case; adding that capability for real means splitting
		//					the notions of:
		//						1) collection key
		//						2) collection owner key
		// 					these 2 are not always the same (same is true in the case of ToOne associations with
		// 					property-ref).  That would require changes to (at least) CollectionEntry and quite
		//					probably changes to how the sql for collection initializers are generated
		//
		//			We could also possibly see if the referenced property is a natural id since we already have caching
		//			in place of natural id snapshots.  BUt really its better to just do it the right way ^^ if we start
		// 			going that route
		final Serializable ownerId = ownerPersister.getIdByUniqueKey( key, collectionType.getLHSPropertyName(), session );
		return getEntity( session.generateEntityKey( ownerId, ownerPersister ) );
	}

	// as a last resort this is what the old code did...
	return getEntity( session.generateEntityKey( key, collectionPersister.getOwnerEntityPersister() ) );
}