本文整理汇总了Java中org.hibernate.collection.PersistentCollection类的典型用法代码示例。如果您正苦于以下问题:Java PersistentCollection类的具体用法?Java PersistentCollection怎么用?Java PersistentCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PersistentCollection类属于org.hibernate.collection包,在下文中一共展示了PersistentCollection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: updateRows
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
public void updateRows(PersistentCollection collection, Serializable id, SessionImplementor session)
throws HibernateException {
if ( !isInverse && collection.isRowUpdatePossible() ) {
if ( log.isDebugEnabled() ) {
log.debug( "Updating rows of collection: " + role + "#" + id );
}
//update all the modified entries
int count = doUpdateRows( id, collection, session );
if ( log.isDebugEnabled() ) {
log.debug( "done updating rows: " + count + " updated" );
}
}
}
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:18,代码来源:AbstractCollectionPersister.java
示例2: serialize
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
@Override
public void serialize(PersistentCollection coll, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException
{
// If lazy-loaded, not yet loaded, may serialize as null?
if (!_forceLazyLoading && !coll.wasInitialized()) {
jgen.writeNull();
return;
}
Object value = coll.getValue();
if (value == null) {
provider.defaultSerializeNull(jgen);
} else {
if (_serializer == null) { // sanity check...
throw new JsonMappingException("PersitentCollection does not have serializer set");
}
_serializer.serialize(value, jgen, provider);
}
}
开发者ID:RBGKew,项目名称:eMonocot,代码行数:20,代码来源:PersistentCollectionSerializer.java
示例3: initializeProperty
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
/**
*
* @param o Set the object
* @param association Set the association to initialize
*/
protected Object initializeProperty(final Object o, final String association) {
Object object;
try {
object = PropertyUtils.getProperty(o, association);
} catch (Exception e) {
logger.debug("Cannot get proxy " + association + " for class " + o.getClass());
return null;
}
if (object == null) {
return null;
} else if (object instanceof HibernateProxy) {
((HibernateProxy) object).getHibernateLazyInitializer().initialize();
LazyInitializer lazyInitializer = ((HibernateProxy) object)
.getHibernateLazyInitializer();
return lazyInitializer.getImplementation();
} else if (object instanceof PersistentCollection) {
((PersistentCollection) object).forceInitialization();
return object;
} else {
return object;
}
}
开发者ID:RBGKew,项目名称:eMonocot,代码行数:28,代码来源:DaoImpl.java
示例4: deleteOrphans
import org.hibernate.collection.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() ) {
CollectionEntry ce = eventSource.getPersistenceContext().getCollectionEntry(pc);
orphans = ce==null ?
CollectionHelper.EMPTY_COLLECTION :
ce.getOrphans(entityName, pc);
}
else {
orphans = pc.getQueuedOrphans(entityName);
}
final Iterator orphanIter = orphans.iterator();
while ( orphanIter.hasNext() ) {
Object orphan = orphanIter.next();
if (orphan!=null) {
if ( log.isTraceEnabled() ) {
log.trace("deleting orphaned entity instance: " + entityName);
}
eventSource.delete( entityName, orphan, false, null );
}
}
}
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:28,代码来源:Cascade.java
示例5: CollectionEntry
import org.hibernate.collection.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
}
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:21,代码来源:CollectionEntry.java
示例6: findSerializer
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
@Override
public JsonSerializer<?> findSerializer(
SerializationConfig config, JavaType type,
BeanDescription beanDesc)
{
Class<?> raw = type.getRawClass();
/* Note: PersistentCollection does not implement Collection, so we
* may get some types here...
*/
if (PersistentCollection.class.isAssignableFrom(raw)) {
// TODO: handle iterator types? Or PersistentArrayHolder?
}
if (HibernateProxy.class.isAssignableFrom(raw)) {
return new HibernateProxySerializer(isEnabled(Feature.FORCE_LAZY_LOADING));
}
return null;
}
开发者ID:RBGKew,项目名称:eMonocot,代码行数:20,代码来源:HibernateSerializers.java
示例7: initializeNonLazyCollections
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
/**
* Force initialization of all non-lazy collections encountered during
* the current two-phase load (actually, this is a no-op, unless this
* is the "outermost" load)
*/
public void initializeNonLazyCollections() throws HibernateException {
if ( loadCounter == 0 ) {
log.debug( "initializing non-lazy collections" );
//do this work only at the very highest level of the load
loadCounter++; //don't let this method be called recursively
try {
int size;
while ( ( size = nonlazyCollections.size() ) > 0 ) {
//note that each iteration of the loop may add new elements
( (PersistentCollection) nonlazyCollections.remove( size - 1 ) ).forceInitialization();
}
}
finally {
loadCounter--;
clearNullProperties();
}
}
}
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:24,代码来源:StatefulPersistenceContext.java
示例8: locateLoadingCollection
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
/**
* Attempt to locate the loading collection given the owner's key. The lookup here
* occurs against all result-set contexts...
*
* @param persister The collection persister
* @param ownerKey The owner key
* @return The loading collection, or null if not found.
*/
public PersistentCollection locateLoadingCollection(CollectionPersister persister, Serializable ownerKey) {
LoadingCollectionEntry lce = locateLoadingCollectionEntry( new CollectionKey( persister, ownerKey, getEntityMode() ) );
if ( lce != null ) {
if ( log.isTraceEnabled() ) {
log.trace( "returning loading collection:" + MessageHelper.collectionInfoString( persister, ownerKey, getSession().getFactory() ) );
}
return lce.getCollection();
}
else {
// todo : should really move this log statement to CollectionType, where this is used from...
if ( log.isTraceEnabled() ) {
log.trace( "creating collection wrapper:" + MessageHelper.collectionInfoString( persister, ownerKey, getSession().getFactory() ) );
}
return null;
}
}
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:25,代码来源:LoadContexts.java
示例9: processCollection
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
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);
}
}
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:19,代码来源:WrapVisitor.java
示例10: evictCollection
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
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);
}
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:17,代码来源:EvictVisitor.java
示例11: execute
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
public void execute() throws HibernateException {
final PersistentCollection collection = getCollection();
getPersister().recreate( collection, getKey(), getSession() );
getSession().getPersistenceContext()
.getCollectionEntry(collection)
.afterAction(collection);
evict();
if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) {
getSession().getFactory().getStatisticsImplementor()
.recreateCollection( getPersister().getRole() );
}
}
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:17,代码来源:CollectionRecreateAction.java
示例12: execute
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
public void execute() throws HibernateException {
if ( !emptySnapshot ) getPersister().remove( getKey(), getSession() );
final PersistentCollection collection = getCollection();
if (collection!=null) {
getSession().getPersistenceContext()
.getCollectionEntry(collection)
.afterAction(collection);
}
evict();
if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) {
getSession().getFactory().getStatisticsImplementor()
.removeCollection( getPersister().getRole() );
}
}
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:18,代码来源:CollectionRemoveAction.java
示例13: getCollection
import org.hibernate.collection.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 = session.getEntityMode();
if (entityMode==EntityMode.DOM4J && !isEmbeddedInXML) {
return UNFETCHED_COLLECTION;
}
// 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( entityMode ) ) {
session.initializeCollection( collection, false );
}
else if ( !persister.isLazy() ) {
persistenceContext.addNonLazyCollection( collection );
}
if ( hasHolder( entityMode ) ) {
session.getPersistenceContext().addCollectionHolder( collection );
}
}
}
collection.setOwner( owner );
return collection.getValue();
}
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:47,代码来源:CollectionType.java
示例14: replaceElements
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
/**
* Replace the elements of a collection with the elements of another collection.
*
* @param original The 'source' of the replacement elements (where we copy from)
* @param target The target of the replacement elements (where we copy to)
* @param owner The owner of the collection being merged
* @param copyCache The map of elements already replaced.
* @param session The session from which the merge event originated.
* @return The merged collection.
*/
public Object replaceElements(
Object original,
Object target,
Object owner,
Map copyCache,
SessionImplementor session) {
// TODO: does not work for EntityMode.DOM4J yet!
java.util.Collection result = ( java.util.Collection ) target;
result.clear();
// copy elements into newly empty target collection
Type elemType = getElementType( session.getFactory() );
Iterator iter = ( (java.util.Collection) original ).iterator();
while ( iter.hasNext() ) {
result.add( elemType.replace( iter.next(), null, session, owner, copyCache ) );
}
// if the original is a PersistentCollection, and that original
// was not flagged as dirty, then reset the target's dirty flag
// here after the copy operation.
// </p>
// One thing to be careful of here is a "bare" original collection
// in which case we should never ever ever reset the dirty flag
// on the target because we simply do not know...
if ( original instanceof PersistentCollection ) {
if ( result instanceof PersistentCollection ) {
if ( ! ( ( PersistentCollection ) original ).isDirty() ) {
( ( PersistentCollection ) result ).clearDirty();
}
}
}
return result;
}
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:45,代码来源:CollectionType.java
示例15: wrap
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
public PersistentCollection wrap(SessionImplementor session, Object collection) {
if ( session.getEntityMode()==EntityMode.DOM4J ) {
return new PersistentMapElementHolder( session, (Element) collection );
}
else {
return new PersistentMap( session, (java.util.Map) collection );
}
}
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:9,代码来源:MapType.java
示例16: instantiate
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
public PersistentCollection instantiate(SessionImplementor session, CollectionPersister persister, Serializable key) {
if ( session.getEntityMode()==EntityMode.DOM4J ) {
return new PersistentListElementHolder(session, persister, key);
}
else {
return new PersistentList(session);
}
}
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:9,代码来源:ListType.java
示例17: dirty
import org.hibernate.collection.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:cacheonix,项目名称:cacheonix-core,代码行数:19,代码来源:CollectionEntry.java
示例18: preFlush
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
public void preFlush(PersistentCollection collection) throws HibernateException {
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.debug(
"Collection dirty: " +
MessageHelper.collectionInfoString( getLoadedPersister().getRole(), getLoadedKey() )
);
}
setDoupdate(false);
setDoremove(false);
setDorecreate(false);
setReached(false);
setProcessed(false);
}
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:28,代码来源:CollectionEntry.java
示例19: afterAction
import org.hibernate.collection.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:cacheonix,项目名称:cacheonix-core,代码行数:18,代码来源:CollectionEntry.java
示例20: useUnownedCollection
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
public PersistentCollection useUnownedCollection(CollectionKey key) {
if (unownedCollections==null) {
return null;
}
else {
return (PersistentCollection) unownedCollections.remove(key);
}
}
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:9,代码来源:StatefulPersistenceContext.java
注:本文中的org.hibernate.collection.PersistentCollection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论