下面列出了怎么用org.hibernate.collection.internal.PersistentSet的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* If object is proxy, get unwrapped non-proxy object.
*
* @param proxy Object to check and unwrap
* @return Unwrapped object if proxyied, if not just returns same object
*/
@SuppressWarnings( "unchecked" )
public static <T> T unwrap( T proxy )
{
if ( !isProxy( proxy ) )
{
return proxy;
}
Hibernate.initialize( proxy );
if ( HibernateProxy.class.isInstance( proxy ) )
{
Object result = ((HibernateProxy) proxy).writeReplace();
if ( !SerializableProxy.class.isInstance( result ) )
{
return (T) result;
}
}
if ( PersistentCollection.class.isInstance( proxy ) )
{
PersistentCollection persistentCollection = (PersistentCollection) proxy;
if ( PersistentSet.class.isInstance( persistentCollection ) )
{
Map<?, ?> map = (Map<?, ?>) persistentCollection.getStoredSnapshot();
return (T) new LinkedHashSet<>( map.keySet() );
}
return (T) persistentCollection.getStoredSnapshot();
}
return proxy;
}
@Override
public PersistentCollection instantiate(SharedSessionContractImplementor session, CollectionPersister persister, Serializable key) {
return new PersistentSet( session );
}
@Override
public PersistentCollection wrap(SharedSessionContractImplementor session, Object collection) {
return new PersistentSet( session, (java.util.Set) collection );
}
@Override
public boolean canConvert(final Class type) {
return PersistentBag.class == type || PersistentList.class == type || PersistentSet.class == type;
}