当前位置: 首页>>代码示例>>Java>>正文


Java PersistentCollection.setOwner方法代码示例

本文整理汇总了Java中org.hibernate.collection.spi.PersistentCollection.setOwner方法的典型用法代码示例。如果您正苦于以下问题:Java PersistentCollection.setOwner方法的具体用法?Java PersistentCollection.setOwner怎么用?Java PersistentCollection.setOwner使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.hibernate.collection.spi.PersistentCollection的用法示例。


在下文中一共展示了PersistentCollection.setOwner方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processReachableCollection

import org.hibernate.collection.spi.PersistentCollection; //导入方法依赖的package包/类
/**
    * Initialize the role of the collection.
    *
    * @param collection The collection to be updated by reachability.
    * @param type The type of the collection.
    * @param entity The owner of the collection.
 * @param session The session from which this request originates
    */
public static void processReachableCollection(
		PersistentCollection collection,
		CollectionType type,
		Object entity,
		SessionImplementor session) {
	collection.setOwner( entity );
	final CollectionEntry ce = session.getPersistenceContext().getCollectionEntry( collection );

	if ( ce == null ) {
		// refer to comment in StatefulPersistenceContext.addCollection()
		throw new HibernateException(
				"Found two representations of same collection: " +
				type.getRole()
		);
	}

	// The CollectionEntry.isReached() stuff is just to detect any silly users
	// who set up circular or shared references between/to collections.
	if ( ce.isReached() ) {
		// We've been here before
		throw new HibernateException(
				"Found shared references to a collection: " + type.getRole()
		);
	}
	ce.setReached( true );

	final SessionFactoryImplementor factory = session.getFactory();
	final CollectionPersister persister = factory.getCollectionPersister( type.getRole() );
	ce.setCurrentPersister( persister );
	//TODO: better to pass the id in as an argument?
	ce.setCurrentKey( type.getKeyOfOwner( entity, session ) );

	if ( LOG.isDebugEnabled() ) {
		if ( collection.wasInitialized() ) {
			LOG.debugf(
					"Collection found: %s, was: %s (initialized)",
					MessageHelper.collectionInfoString( persister, collection, ce.getCurrentKey(), session ),
					MessageHelper.collectionInfoString( ce.getLoadedPersister(), collection, ce.getLoadedKey(), session )
			);
		}
		else {
			LOG.debugf(
					"Collection found: %s, was: %s (uninitialized)",
					MessageHelper.collectionInfoString( persister, collection, ce.getCurrentKey(), session ),
					MessageHelper.collectionInfoString( ce.getLoadedPersister(), collection, ce.getLoadedKey(), session )
			);
		}
	}

	prepareCollectionForUpdate( collection, ce, factory );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:60,代码来源:Collections.java

示例2: getCollection

import org.hibernate.collection.spi.PersistentCollection; //导入方法依赖的package包/类
/**
 * instantiate a collection wrapper (called when loading an object)
 *
 * @param key The collection owner key
 * @param session The session from which the request is originating.
 * @param owner The collection owner
 * @return The collection
 */
public Object getCollection(Serializable key, SessionImplementor session, Object owner) {

	CollectionPersister persister = getPersister( session );
	final PersistenceContext persistenceContext = session.getPersistenceContext();
	final EntityMode entityMode = persister.getOwnerEntityPersister().getEntityMode();

	// check if collection is currently being loaded
	PersistentCollection collection = persistenceContext.getLoadContexts().locateLoadingCollection( persister, key );
	
	if ( collection == null ) {
		
		// check if it is already completely loaded, but unowned
		collection = persistenceContext.useUnownedCollection( new CollectionKey(persister, key, entityMode) );
		
		if ( collection == null ) {
			// create a new collection wrapper, to be initialized later
			collection = instantiate( session, persister, key );
			
			collection.setOwner(owner);

			persistenceContext.addUninitializedCollection( persister, collection, key );

			// some collections are not lazy:
			if ( initializeImmediately() ) {
				session.initializeCollection( collection, false );
			}
			else if ( !persister.isLazy() ) {
				persistenceContext.addNonLazyCollection( collection );
			}

			if ( hasHolder() ) {
				session.getPersistenceContext().addCollectionHolder( collection );
			}
			
		}
		
		if ( LOG.isTraceEnabled() ) {
			LOG.tracef( "Created collection wrapper: %s",
					MessageHelper.collectionInfoString( persister, collection,
							key, session ) );
		}
		
	}
	
	collection.setOwner(owner);

	return collection.getValue();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:57,代码来源:CollectionType.java


注:本文中的org.hibernate.collection.spi.PersistentCollection.setOwner方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。