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


Java PersistentCollection.wasInitialized方法代码示例

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


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

示例1: deleteOrphans

import org.hibernate.collection.spi.PersistentCollection; //导入方法依赖的package包/类
/**
 * Delete any entities that were removed from the collection
 */
private void deleteOrphans(String entityName, PersistentCollection pc) throws HibernateException {
	//TODO: suck this logic into the collection!
	final Collection orphans;
	if ( pc.wasInitialized() ) {
		final CollectionEntry ce = eventSource.getPersistenceContext().getCollectionEntry( pc );
		orphans = ce==null
				? java.util.Collections.EMPTY_LIST
				: ce.getOrphans( entityName, pc );
	}
	else {
		orphans = pc.getQueuedOrphans( entityName );
	}

	for ( Object orphan : orphans ) {
		if ( orphan != null ) {
			LOG.tracev( "Deleting orphaned entity instance: {0}", entityName );
			eventSource.delete( entityName, orphan, false, new HashSet() );
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:Cascade.java

示例2: dirty

import org.hibernate.collection.spi.PersistentCollection; //导入方法依赖的package包/类
/**
 * Determine if the collection is "really" dirty, by checking dirtiness
 * of the collection elements, if necessary
 */
private void dirty(PersistentCollection collection) throws HibernateException {

	boolean forceDirty = collection.wasInitialized() &&
			!collection.isDirty() && //optimization
			getLoadedPersister() != null &&
			getLoadedPersister().isMutable() && //optimization
			( collection.isDirectlyAccessible() || getLoadedPersister().getElementType().isMutable() ) && //optimization
			!collection.equalsSnapshot( getLoadedPersister() );

	if ( forceDirty ) {
		collection.dirty();
	}

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:CollectionEntry.java

示例3: afterAction

import org.hibernate.collection.spi.PersistentCollection; //导入方法依赖的package包/类
/**
 * Called after execution of an action
 */
public void afterAction(PersistentCollection collection) {
	loadedKey = getCurrentKey();
	setLoadedPersister( getCurrentPersister() );

	boolean resnapshot = collection.wasInitialized() &&
			( isDoremove() || isDorecreate() || isDoupdate() );
	if ( resnapshot ) {
		snapshot = loadedPersister==null || !loadedPersister.isMutable() ?
				null :
				collection.getSnapshot(loadedPersister); //re-snapshot
	}

	collection.postAction();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:CollectionEntry.java

示例4: isSnapshotEmpty

import org.hibernate.collection.spi.PersistentCollection; //导入方法依赖的package包/类
public boolean isSnapshotEmpty(PersistentCollection collection) {
	//TODO: does this really need to be here?
	//      does the collection already have
	//      it's own up-to-date snapshot?
	return collection.wasInitialized() &&
		( getLoadedPersister()==null || getLoadedPersister().isMutable() ) &&
		collection.isSnapshotEmpty( getSnapshot() );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:CollectionEntry.java

示例5: processCollection

import org.hibernate.collection.spi.PersistentCollection; //导入方法依赖的package包/类
@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().getCollectionPersister( type.getRole() );

	if ( isUpdate ) {
		removeCollection( persister, extractCollectionKeyFromOwner( persister ), session );
	}
	if ( collection != null && collection instanceof PersistentCollection ) {
		final 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;

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:OnReplicateVisitor.java

示例6: getCollectionBatch

import org.hibernate.collection.spi.PersistentCollection; //导入方法依赖的package包/类
/**
 * Get a batch of uninitialized collection keys for a given role
 *
 * @param collectionPersister The persister for the collection role.
 * @param id A key that must be included in the batch fetch
 * @param batchSize the maximum number of keys to return
 * @return an array of collection keys, of length batchSize (padded with nulls)
 */
public Serializable[] getCollectionBatch(
		final CollectionPersister collectionPersister,
		final Serializable id,
		final int batchSize) {

	Serializable[] keys = new Serializable[batchSize];
	keys[0] = id;

	int i = 1;
	int end = -1;
	boolean checkForEnd = false;

	final LinkedHashMap<CollectionEntry, PersistentCollection> map =  batchLoadableCollections.get( collectionPersister.getRole() );
	if ( map != null ) {
		for ( Entry<CollectionEntry, PersistentCollection> me : map.entrySet() ) {
			final CollectionEntry ce = me.getKey();
			final PersistentCollection collection = me.getValue();
			
			if ( ce.getLoadedKey() == null ) {
				// the loadedKey of the collectionEntry might be null as it might have been reset to null
				// (see for example Collections.processDereferencedCollection()
				// and CollectionEntry.afterAction())
				// though we clear the queue on flush, it seems like a good idea to guard
				// against potentially null loadedKeys (which leads to various NPEs as demonstrated in HHH-7821).
				continue;
			}

			if ( collection.wasInitialized() ) {
				// should never happen
				LOG.warn( "Encountered initialized collection in BatchFetchQueue, this should not happen." );
				continue;
			}

			if ( checkForEnd && i == end ) {
				return keys; //the first key found after the given key
			}

			final boolean isEqual = collectionPersister.getKeyType().isEqual(
					id,
					ce.getLoadedKey(),
					collectionPersister.getFactory()
			);

			if ( isEqual ) {
				end = i;
				//checkForEnd = false;
			}
			else if ( !isCached( ce.getLoadedKey(), collectionPersister ) ) {
				keys[i++] = ce.getLoadedKey();
				//count++;
			}

			if ( i == batchSize ) {
				i = 1; //end of array, start filling again from start
				if ( end != -1 ) {
					checkForEnd = true;
				}
			}
		}
	}
	return keys; //we ran out of keys to try
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:71,代码来源:BatchFetchQueue.java

示例7: 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

示例8: getLoadingCollection

import org.hibernate.collection.spi.PersistentCollection; //导入方法依赖的package包/类
/**
 * Retrieve the collection that is being loaded as part of processing this
 * result set.
 * <p/>
 * Basically, there are two valid return values from this method:<ul>
 * <li>an instance of {@link org.hibernate.collection.spi.PersistentCollection} which indicates to
 * continue loading the result set row data into that returned collection
 * instance; this may be either an instance already associated and in the
 * midst of being loaded, or a newly instantiated instance as a matching
 * associated collection was not found.</li>
 * <li><i>null</i> indicates to ignore the corresponding result set row
 * data relating to the requested collection; this indicates that either
 * the collection was found to already be associated with the persistence
 * context in a fully loaded state, or it was found in a loading state
 * associated with another result set processing context.</li>
 * </ul>
 *
 * @param persister The persister for the collection being requested.
 * @param key The key of the collection being requested.
 *
 * @return The loading collection (see discussion above).
 */
public PersistentCollection getLoadingCollection(final CollectionPersister persister, final Serializable key) {
	final EntityMode em = persister.getOwnerEntityPersister().getEntityMetamodel().getEntityMode();
	final CollectionKey collectionKey = new CollectionKey( persister, key, em );
	if ( LOG.isTraceEnabled() ) {
		LOG.tracev( "Starting attempt to find loading collection [{0}]",
				MessageHelper.collectionInfoString( persister.getRole(), key ) );
	}
	final LoadingCollectionEntry loadingCollectionEntry = loadContexts.locateLoadingCollectionEntry( collectionKey );
	if ( loadingCollectionEntry == null ) {
		// look for existing collection as part of the persistence context
		PersistentCollection collection = loadContexts.getPersistenceContext().getCollection( collectionKey );
		if ( collection != null ) {
			if ( collection.wasInitialized() ) {
				LOG.trace( "Collection already initialized; ignoring" );
				// ignore this row of results! Note the early exit
				return null;
			}
			LOG.trace( "Collection not yet initialized; initializing" );
		}
		else {
			final Object owner = loadContexts.getPersistenceContext().getCollectionOwner( key, persister );
			final boolean newlySavedEntity = owner != null
					&& loadContexts.getPersistenceContext().getEntry( owner ).getStatus() != Status.LOADING;
			if ( newlySavedEntity ) {
				// important, to account for newly saved entities in query
				// todo : some kind of check for new status...
				LOG.trace( "Owning entity already loaded; ignoring" );
				return null;
			}
			// create one
			LOG.tracev( "Instantiating new collection [key={0}, rs={1}]", key, resultSet );
			collection = persister.getCollectionType().instantiate(
					loadContexts.getPersistenceContext().getSession(), persister, key );
		}
		collection.beforeInitialize( persister, -1 );
		collection.beginRead();
		localLoadingCollectionKeys.add( collectionKey );
		loadContexts.registerLoadingCollectionXRef( collectionKey, new LoadingCollectionEntry( resultSet, persister, key, collection ) );
		return collection;
	}
	if ( loadingCollectionEntry.getResultSet() == resultSet ) {
		LOG.trace( "Found loading collection bound to current result set processing; reading row" );
		return loadingCollectionEntry.getCollection();
	}
	// ignore this row, the collection is in process of
	// being loaded somewhere further "up" the stack
	LOG.trace( "Collection is already being initialized; ignoring row" );
	return null;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:72,代码来源:CollectionLoadContext.java

示例9: onInitializeCollection

import org.hibernate.collection.spi.PersistentCollection; //导入方法依赖的package包/类
/**
 * called by a collection that wants to initialize itself
 */
public void onInitializeCollection(InitializeCollectionEvent event) throws HibernateException {
	PersistentCollection collection = event.getCollection();
	SessionImplementor source = event.getSession();

	CollectionEntry ce = source.getPersistenceContext().getCollectionEntry( collection );
	if ( ce == null ) {
		throw new HibernateException( "collection was evicted" );
	}
	if ( !collection.wasInitialized() ) {
		final boolean traceEnabled = LOG.isTraceEnabled();
		if ( traceEnabled ) {
			LOG.tracev(
					"Initializing collection {0}",
					MessageHelper.collectionInfoString(
							ce.getLoadedPersister(),
							collection,
							ce.getLoadedKey(),
							source
					)
			);
			LOG.trace( "Checking second-level cache" );
		}

		final boolean foundInCache = initializeCollectionFromCache(
				ce.getLoadedKey(),
				ce.getLoadedPersister(),
				collection,
				source
		);

		if ( foundInCache ) {
			if ( traceEnabled ) {
				LOG.trace( "Collection initialized from cache" );
			}
		}
		else {
			if ( traceEnabled ) {
				LOG.trace( "Collection not cached" );
			}
			ce.getLoadedPersister().initialize( ce.getLoadedKey(), source );
			if ( traceEnabled ) {
				LOG.trace( "Collection initialized" );
			}

			if ( source.getFactory().getStatistics().isStatisticsEnabled() ) {
				source.getFactory().getStatisticsImplementor().fetchCollection(
						ce.getLoadedPersister().getRole()
				);
			}
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:56,代码来源:DefaultInitializeCollectionEventListener.java

示例10: execute

import org.hibernate.collection.spi.PersistentCollection; //导入方法依赖的package包/类
@Override
public void execute() throws HibernateException {
	final Serializable id = getKey();
	final SessionImplementor session = getSession();
	final CollectionPersister persister = getPersister();
	final PersistentCollection collection = getCollection();
	final boolean affectedByFilters = persister.isAffectedByEnabledFilters( session );

	preUpdate();

	if ( !collection.wasInitialized() ) {
		if ( !collection.hasQueuedOperations() ) {
			throw new AssertionFailure( "no queued adds" );
		}
		//do nothing - we only need to notify the cache... 
	}
	else if ( !affectedByFilters && collection.empty() ) {
		if ( !emptySnapshot ) {
			persister.remove( id, session );
		}
	}
	else if ( collection.needsRecreate( persister ) ) {
		if ( affectedByFilters ) {
			throw new HibernateException(
					"cannot recreate collection while filter is enabled: " +
							MessageHelper.collectionInfoString( persister, collection, id, session )
			);
		}
		if ( !emptySnapshot ) {
			persister.remove( id, session );
		}
		persister.recreate( collection, id, session );
	}
	else {
		persister.deleteRows( collection, id, session );
		persister.updateRows( collection, id, session );
		persister.insertRows( collection, id, session );
	}

	getSession().getPersistenceContext().getCollectionEntry( collection ).afterAction( collection );
	evict();
	postUpdate();

	if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) {
		getSession().getFactory().getStatisticsImplementor().updateCollection( getPersister().getRole() );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:48,代码来源:CollectionUpdateAction.java


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