本文整理汇总了Java中org.hibernate.collection.spi.PersistentCollection类的典型用法代码示例。如果您正苦于以下问题:Java PersistentCollection类的具体用法?Java PersistentCollection怎么用?Java PersistentCollection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PersistentCollection类属于org.hibernate.collection.spi包,在下文中一共展示了PersistentCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.hibernate.collection.spi.PersistentCollection; //导入依赖的package包/类
@Override
public void execute() throws HibernateException {
// this method is called when a new non-null collection is persisted
// or when an existing (non-null) collection is moved to a new owner
final PersistentCollection collection = getCollection();
preRecreate();
getPersister().recreate( collection, getKey(), getSession() );
getSession().getPersistenceContext().getCollectionEntry( collection ).afterAction( collection );
evict();
postRecreate();
if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) {
getSession().getFactory().getStatisticsImplementor().recreateCollection( getPersister().getRole() );
}
}
示例2: evictCollection
import org.hibernate.collection.spi.PersistentCollection; //导入依赖的package包/类
public void evictCollection(Object value, CollectionType type) {
final Object pc;
if ( type.hasHolder() ) {
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);
}
示例3: CollectionRemoveAction
import org.hibernate.collection.spi.PersistentCollection; //导入依赖的package包/类
/**
* Removes a persistent collection from its loaded owner.
*
* Use this constructor when the collection is non-null.
*
* @param collection The collection to to remove; must be non-null
* @param persister The collection's persister
* @param id The collection key
* @param emptySnapshot Indicates if the snapshot is empty
* @param session The session
*
* @throws AssertionFailure if collection is null.
*/
public CollectionRemoveAction(
final PersistentCollection collection,
final CollectionPersister persister,
final Serializable id,
final boolean emptySnapshot,
final SessionImplementor session) {
super( persister, collection, id, session );
if ( collection == null ) {
throw new AssertionFailure("collection == null");
}
this.emptySnapshot = emptySnapshot;
// the loaded owner will be set to null after the collection is removed,
// so capture its value as the affected owner so it is accessible to
// both pre- and post- events
this.affectedOwner = session.getPersistenceContext().getLoadedCollectionOwnerOrNull( collection );
}
示例4: CollectionEntry
import org.hibernate.collection.spi.PersistentCollection; //导入依赖的package包/类
/**
* For collections just loaded from the database
*/
public CollectionEntry(
final PersistentCollection collection,
final CollectionPersister loadedPersister,
final Serializable loadedKey,
final boolean ignore
) {
this.ignore=ignore;
//collection.clearDirty()
this.loadedKey = loadedKey;
setLoadedPersister(loadedPersister);
collection.setSnapshot(loadedKey, role, null);
//postInitialize() will be called after initialization
}
示例5: execute
import org.hibernate.collection.spi.PersistentCollection; //导入依赖的package包/类
@Override
public void execute() throws HibernateException {
preRemove();
if ( !emptySnapshot ) {
// an existing collection that was either non-empty or uninitialized
// is replaced by null or a different collection
// (if the collection is uninitialized, hibernate has no way of
// knowing if the collection is actually empty without querying the db)
getPersister().remove( getKey(), getSession() );
}
final PersistentCollection collection = getCollection();
if ( collection != null ) {
getSession().getPersistenceContext().getCollectionEntry( collection ).afterAction( collection );
}
evict();
postRemove();
if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) {
getSession().getFactory().getStatisticsImplementor().removeCollection( getPersister().getRole() );
}
}
示例6: processNeverReferencedCollection
import org.hibernate.collection.spi.PersistentCollection; //导入依赖的package包/类
private static void processNeverReferencedCollection(PersistentCollection coll, SessionImplementor session)
throws HibernateException {
final PersistenceContext persistenceContext = session.getPersistenceContext();
final CollectionEntry entry = persistenceContext.getCollectionEntry( coll );
if ( LOG.isDebugEnabled() ) {
LOG.debugf(
"Found collection with unloaded owner: %s",
MessageHelper.collectionInfoString(
entry.getLoadedPersister(),
coll,
entry.getLoadedKey(),
session
)
);
}
entry.setCurrentPersister( entry.getLoadedPersister() );
entry.setCurrentKey( entry.getLoadedKey() );
prepareCollectionForUpdate( coll, entry, session.getFactory() );
}
示例7: addCollection
import org.hibernate.collection.spi.PersistentCollection; //导入依赖的package包/类
/**
* Add an collection to the cache, with a given collection entry.
*
* @param coll The collection for which we are adding an entry.
* @param entry The entry representing the collection.
* @param key The key of the collection's entry.
*/
private void addCollection(PersistentCollection coll, CollectionEntry entry, Serializable key) {
collectionEntries.put( coll, entry );
final CollectionKey collectionKey = new CollectionKey( entry.getLoadedPersister(), key );
final PersistentCollection old = collectionsByKey.put( collectionKey, coll );
if ( old != null ) {
if ( old == coll ) {
throw new AssertionFailure( "bug adding collection twice" );
}
// or should it actually throw an exception?
old.unsetSession( session );
collectionEntries.remove( old );
// watch out for a case where old is still referenced
// somewhere in the object graph! (which is a user error)
}
}
示例8: collectionInfoString
import org.hibernate.collection.spi.PersistentCollection; //导入依赖的package包/类
/**
* Generate an info message string relating to a particular managed
* collection. Attempts to intelligently handle property-refs issues
* where the collection key is not the same as the owner key.
*
* @param persister The persister for the collection
* @param collection The collection itself
* @param collectionKey The collection key
* @param session The session
* @return An info string, in the form [Foo.bars#1]
*/
public static String collectionInfoString(
CollectionPersister persister,
PersistentCollection collection,
Serializable collectionKey,
SessionImplementor session ) {
StringBuilder s = new StringBuilder();
s.append( '[' );
if ( persister == null ) {
s.append( "<unreferenced>" );
}
else {
s.append( persister.getRole() );
s.append( '#' );
Type ownerIdentifierType = persister.getOwnerEntityPersister()
.getIdentifierType();
Serializable ownerKey;
// TODO: Is it redundant to attempt to use the collectionKey,
// or is always using the owner id sufficient?
if ( collectionKey.getClass().isAssignableFrom(
ownerIdentifierType.getReturnedClass() ) ) {
ownerKey = collectionKey;
} else {
ownerKey = session.getPersistenceContext()
.getEntry( collection.getOwner() ).getId();
}
s.append( ownerIdentifierType.toLoggableString(
ownerKey, session.getFactory() ) );
}
s.append( ']' );
return s.toString();
}
示例9: PreCollectionRecreateEvent
import org.hibernate.collection.spi.PersistentCollection; //导入依赖的package包/类
public PreCollectionRecreateEvent(
CollectionPersister collectionPersister,
PersistentCollection collection,
EventSource source) {
super(
collectionPersister,
collection,
source,
collection.getOwner(),
getOwnerIdOrNull( collection.getOwner(), source )
);
}
示例10: CollectionUpdateAction
import org.hibernate.collection.spi.PersistentCollection; //导入依赖的package包/类
/**
* Constructs a CollectionUpdateAction
*
* @param collection The collection to update
* @param persister The collection persister
* @param id The collection key
* @param emptySnapshot Indicates if the snapshot is empty
* @param session The session
*/
public CollectionUpdateAction(
final PersistentCollection collection,
final CollectionPersister persister,
final Serializable id,
final boolean emptySnapshot,
final SessionImplementor session) {
super( persister, collection, id, session );
this.emptySnapshot = emptySnapshot;
}
示例11: processQueuedOps
import org.hibernate.collection.spi.PersistentCollection; //导入依赖的package包/类
@Override
public void processQueuedOps(PersistentCollection collection, Serializable key, SessionImplementor session)
throws HibernateException {
if ( collection.hasQueuedOperations() ) {
doProcessQueuedOps( collection, key, session );
}
}
示例12: addBatchLoadableCollection
import org.hibernate.collection.spi.PersistentCollection; //导入依赖的package包/类
/**
* If an CollectionEntry represents a batch loadable collection, add
* it to the queue.
*/
public void addBatchLoadableCollection(PersistentCollection collection, CollectionEntry ce) {
final CollectionPersister persister = ce.getLoadedPersister();
LinkedHashMap<CollectionEntry, PersistentCollection> map = batchLoadableCollections.get( persister.getRole() );
if ( map == null ) {
map = new LinkedHashMap<CollectionEntry, PersistentCollection>( 16 );
batchLoadableCollections.put( persister.getRole(), map );
}
map.put( ce, collection );
}
示例13: isOwnerUnchanged
import org.hibernate.collection.spi.PersistentCollection; //导入依赖的package包/类
/**
* Has the owner of the collection changed since the collection
* was snapshotted and detached?
*/
protected static boolean isOwnerUnchanged(
final PersistentCollection snapshot,
final CollectionPersister persister,
final Serializable id
) {
return isCollectionSnapshotValid(snapshot) &&
persister.getRole().equals( snapshot.getRole() ) &&
id.equals( snapshot.getKey() );
}
示例14: 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();
}
}
示例15: preFlush
import org.hibernate.collection.spi.PersistentCollection; //导入依赖的package包/类
public void preFlush(PersistentCollection collection) throws HibernateException {
if ( loadedKey == null && collection.getKey() != null ) {
loadedKey = collection.getKey();
}
boolean nonMutableChange = collection.isDirty() &&
getLoadedPersister()!=null &&
!getLoadedPersister().isMutable();
if (nonMutableChange) {
throw new HibernateException(
"changed an immutable collection instance: " +
MessageHelper.collectionInfoString( getLoadedPersister().getRole(), getLoadedKey() )
);
}
dirty(collection);
if ( LOG.isDebugEnabled() && collection.isDirty() && getLoadedPersister() != null ) {
LOG.debugf( "Collection dirty: %s",
MessageHelper.collectionInfoString( getLoadedPersister().getRole(), getLoadedKey() ) );
}
setDoupdate(false);
setDoremove(false);
setDorecreate(false);
setReached(false);
setProcessed(false);
}