本文整理匯總了Java中org.hibernate.persister.entity.EntityPersister.hasCache方法的典型用法代碼示例。如果您正苦於以下問題:Java EntityPersister.hasCache方法的具體用法?Java EntityPersister.hasCache怎麽用?Java EntityPersister.hasCache使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.hibernate.persister.entity.EntityPersister
的用法示例。
在下文中一共展示了EntityPersister.hasCache方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: registerInsertedKey
import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
@Override
public void registerInsertedKey(EntityPersister persister, Serializable id) {
// we only are worried about registering these if the persister defines caching
if ( persister.hasCache() ) {
if ( insertedKeysMap == null ) {
insertedKeysMap = new HashMap<String, List<Serializable>>();
}
final String rootEntityName = persister.getRootEntityName();
List<Serializable> insertedEntityIds = insertedKeysMap.get( rootEntityName );
if ( insertedEntityIds == null ) {
insertedEntityIds = new ArrayList<Serializable>();
insertedKeysMap.put( rootEntityName, insertedEntityIds );
}
insertedEntityIds.add( id );
}
}
示例2: doAfterTransactionCompletion
import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
@Override
public void doAfterTransactionCompletion(boolean success, SessionImplementor session) throws CacheException {
final EntityPersister persister = getPersister();
if ( persister.hasCache() ) {
final CacheKey ck = getSession().generateCacheKey(
getId(),
persister.getIdentifierType(),
persister.getRootEntityName()
);
if ( success && cacheEntry!=null /*!persister.isCacheInvalidationRequired()*/ ) {
final boolean put = cacheAfterUpdate( persister, ck );
if ( put && getSession().getFactory().getStatistics().isStatisticsEnabled() ) {
getSession().getFactory().getStatisticsImplementor().secondLevelCachePut( getPersister().getCacheAccessStrategy().getRegion().getName() );
}
}
else {
persister.getCacheAccessStrategy().unlockItem( ck, lock );
}
}
postCommitUpdate( success );
}
示例3: isCached
import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
private boolean isCached(EntityKey entityKey, EntityPersister persister) {
if ( context.getSession().getCacheMode().isGetEnabled() && persister.hasCache() ) {
final CacheKey key = context.getSession().generateCacheKey(
entityKey.getIdentifier(),
persister.getIdentifierType(),
entityKey.getEntityName()
);
return CacheHelper.fromSharedCache( context.getSession(), key, persister.getCacheAccessStrategy() ) != null;
}
return false;
}
示例4: wasInsertedDuringTransaction
import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
@Override
public boolean wasInsertedDuringTransaction(EntityPersister persister, Serializable id) {
// again, we only really care if the entity is cached
if ( persister.hasCache() ) {
if ( insertedKeysMap != null ) {
final List<Serializable> insertedEntityIds = insertedKeysMap.get( persister.getRootEntityName() );
if ( insertedEntityIds != null ) {
return insertedEntityIds.contains( id );
}
}
}
return false;
}
示例5: evictEntity
import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
@Override
public void evictEntity(String entityName, Serializable identifier) {
EntityPersister p = sessionFactory.getEntityPersister( entityName );
if ( p.hasCache() ) {
if ( LOG.isDebugEnabled() ) {
LOG.debugf(
"Evicting second-level cache: %s",
MessageHelper.infoString( p, identifier, sessionFactory )
);
}
p.getCacheAccessStrategy().evict( buildCacheKey( identifier, p ) );
}
}
示例6: evictEntityRegion
import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
@Override
public void evictEntityRegion(String entityName) {
EntityPersister p = sessionFactory.getEntityPersister( entityName );
if ( p.hasCache() ) {
if ( LOG.isDebugEnabled() ) {
LOG.debugf( "Evicting second-level cache: %s", p.getEntityName() );
}
p.getCacheAccessStrategy().evictAll();
}
}
示例7: refresh
import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
@Override
public void refresh(String entityName, Object entity, LockMode lockMode) {
final EntityPersister persister = this.getEntityPersister( entityName, entity );
final Serializable id = persister.getIdentifier( entity, this );
if ( LOG.isTraceEnabled() ) {
LOG.tracev( "Refreshing transient {0}", MessageHelper.infoString( persister, id, this.getFactory() ) );
}
// TODO : can this ever happen???
// EntityKey key = new EntityKey( id, persister, source.getEntityMode() );
// if ( source.getPersistenceContext().getEntry( key ) != null ) {
// throw new PersistentObjectException(
// "attempted to refresh transient instance when persistent " +
// "instance was already associated with the Session: " +
// MessageHelper.infoString( persister, id, source.getFactory() )
// );
// }
if ( persister.hasCache() ) {
final CacheKey ck = generateCacheKey( id, persister.getIdentifierType(), persister.getRootEntityName() );
persister.getCacheAccessStrategy().evict( ck );
}
String previousFetchProfile = this.getFetchProfile();
Object result = null;
try {
this.setFetchProfile( "refresh" );
result = persister.load( id, entity, lockMode, this );
}
finally {
this.setFetchProfile( previousFetchProfile );
}
UnresolvableObjectException.throwIfNull( result, id, persister.getEntityName() );
}
示例8: lockAndLoad
import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
/**
* If the class to be loaded has been configured with a cache, then lock
* given id in that cache and then perform the load.
*
* @param event The initiating load request event
* @param persister The persister corresponding to the entity to be loaded
* @param keyToLoad The key of the entity to be loaded
* @param options The defined load options
* @param source The originating session
*
* @return The loaded entity
*
* @throws HibernateException
*/
protected Object lockAndLoad(
final LoadEvent event,
final EntityPersister persister,
final EntityKey keyToLoad,
final LoadEventListener.LoadType options,
final SessionImplementor source) {
SoftLock lock = null;
final CacheKey ck;
if ( persister.hasCache() ) {
ck = source.generateCacheKey(
event.getEntityId(),
persister.getIdentifierType(),
persister.getRootEntityName()
);
lock = persister.getCacheAccessStrategy().lockItem( ck, null );
}
else {
ck = null;
}
Object entity;
try {
entity = load( event, persister, keyToLoad, options );
}
finally {
if ( persister.hasCache() ) {
persister.getCacheAccessStrategy().unlockItem( ck, lock );
}
}
return event.getSession().getPersistenceContext().proxyFor( persister, keyToLoad, entity );
}
示例9: BulkOperationCleanupAction
import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
/**
* Constructs an action to cleanup "affected cache regions" based on a
* set of affected table spaces. This differs from {@link #BulkOperationCleanupAction(SessionImplementor, Queryable[])}
* in that here we have the affected <strong>table names</strong>. From those
* we deduce the entity persisters which are affected based on the defined
* {@link EntityPersister#getQuerySpaces() table spaces}; and from there, we
* determine the affected collection regions based on any collections
* in which those entity persisters participate as elements/keys/etc.
*
* @param session The session to which this request is tied.
* @param tableSpaces The table spaces.
*/
@SuppressWarnings({ "unchecked" })
public BulkOperationCleanupAction(SessionImplementor session, Set tableSpaces) {
final LinkedHashSet<String> spacesList = new LinkedHashSet<String>();
spacesList.addAll( tableSpaces );
final SessionFactoryImplementor factory = session.getFactory();
for ( String entityName : factory.getAllClassMetadata().keySet() ) {
final EntityPersister persister = factory.getEntityPersister( entityName );
final String[] entitySpaces = (String[]) persister.getQuerySpaces();
if ( affectedEntity( tableSpaces, entitySpaces ) ) {
spacesList.addAll( Arrays.asList( entitySpaces ) );
if ( persister.hasCache() ) {
entityCleanups.add( new EntityCleanup( persister.getCacheAccessStrategy() ) );
}
if ( persister.hasNaturalIdentifier() && persister.hasNaturalIdCache() ) {
naturalIdCleanups.add( new NaturalIdCleanup( persister.getNaturalIdCacheAccessStrategy() ) );
}
final Set<String> roles = session.getFactory().getCollectionRolesByEntityParticipant( persister.getEntityName() );
if ( roles != null ) {
for ( String role : roles ) {
final CollectionPersister collectionPersister = factory.getCollectionPersister( role );
if ( collectionPersister.hasCache() ) {
collectionCleanups.add(
new CollectionCleanup( collectionPersister.getCacheAccessStrategy() )
);
}
}
}
}
}
this.affectedTableSpaces = spacesList.toArray( new String[ spacesList.size() ] );
}
示例10: containsEntity
import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
@Override
public boolean containsEntity(String entityName, Serializable identifier) {
EntityPersister p = sessionFactory.getEntityPersister( entityName );
return p.hasCache() &&
p.getCacheAccessStrategy().getRegion().contains( buildCacheKey( identifier, p ) );
}
示例11: upgradeLock
import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
/**
* Performs a pessimistic lock upgrade on a given entity, if needed.
*
* @param object The entity for which to upgrade the lock.
* @param entry The entity's EntityEntry instance.
* @param lockOptions contains the requested lock mode.
* @param source The session which is the source of the event being processed.
*/
protected void upgradeLock(Object object, EntityEntry entry, LockOptions lockOptions, EventSource source) {
LockMode requestedLockMode = lockOptions.getLockMode();
if ( requestedLockMode.greaterThan( entry.getLockMode() ) ) {
// The user requested a "greater" (i.e. more restrictive) form of
// pessimistic lock
if ( entry.getStatus() != Status.MANAGED ) {
throw new ObjectDeletedException(
"attempted to lock a deleted instance",
entry.getId(),
entry.getPersister().getEntityName()
);
}
final EntityPersister persister = entry.getPersister();
if ( log.isTraceEnabled() ) {
log.tracev(
"Locking {0} in mode: {1}",
MessageHelper.infoString( persister, entry.getId(), source.getFactory() ),
requestedLockMode
);
}
final SoftLock lock;
final CacheKey ck;
if ( persister.hasCache() ) {
ck = source.generateCacheKey( entry.getId(), persister.getIdentifierType(), persister.getRootEntityName() );
lock = persister.getCacheAccessStrategy().lockItem( ck, entry.getVersion() );
}
else {
ck = null;
lock = null;
}
try {
if ( persister.isVersioned() && requestedLockMode == LockMode.FORCE ) {
// todo : should we check the current isolation mode explicitly?
Object nextVersion = persister.forceVersionIncrement(
entry.getId(), entry.getVersion(), source
);
entry.forceLocked( object, nextVersion );
}
else {
persister.lock( entry.getId(), entry.getVersion(), object, lockOptions, source );
}
entry.setLockMode(requestedLockMode);
}
finally {
// the database now holds a lock + the object is flushed from the cache,
// so release the soft lock
if ( persister.hasCache() ) {
persister.getCacheAccessStrategy().unlockItem( ck, lock );
}
}
}
}
示例12: loadFromSecondLevelCache
import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
/**
* Attempts to load the entity from the second-level cache.
*
* @param event The load event
* @param persister The persister for the entity being requested for load
* @param options The load options.
*
* @return The entity from the second-level cache, or null.
*/
protected Object loadFromSecondLevelCache(
final LoadEvent event,
final EntityPersister persister,
final LoadEventListener.LoadType options) {
final SessionImplementor source = event.getSession();
final boolean useCache = persister.hasCache()
&& source.getCacheMode().isGetEnabled()
&& event.getLockMode().lessThan( LockMode.READ );
if ( !useCache ) {
// we can't use cache here
return null;
}
final SessionFactoryImplementor factory = source.getFactory();
final CacheKey ck = source.generateCacheKey(
event.getEntityId(),
persister.getIdentifierType(),
persister.getRootEntityName()
);
final Object ce = CacheHelper.fromSharedCache( source, ck, persister.getCacheAccessStrategy() );
if ( factory.getStatistics().isStatisticsEnabled() ) {
if ( ce == null ) {
factory.getStatisticsImplementor().secondLevelCacheMiss(
persister.getCacheAccessStrategy().getRegion().getName()
);
}
else {
factory.getStatisticsImplementor().secondLevelCacheHit(
persister.getCacheAccessStrategy().getRegion().getName()
);
}
}
if ( ce == null ) {
// nothing was found in cache
return null;
}
CacheEntry entry = (CacheEntry) persister.getCacheEntryStructure().destructure( ce, factory );
Object entity = convertCacheEntryToEntity( entry, event.getEntityId(), persister, event );
if ( !persister.isInstance( entity ) ) {
throw new WrongClassException(
"loaded object was of wrong class " + entity.getClass(),
event.getEntityId(),
persister.getEntityName()
);
}
return entity;
}
示例13: execute
import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
@Override
public void execute() throws HibernateException {
final Serializable id = getId();
final EntityPersister persister = getPersister();
final SessionImplementor session = getSession();
final Object instance = getInstance();
final boolean veto = preDelete();
Object version = this.version;
if ( persister.isVersionPropertyGenerated() ) {
// we need to grab the version value from the entity, otherwise
// we have issues with generated-version entities that may have
// multiple actions queued during the same flush
version = persister.getVersion( instance );
}
final CacheKey ck;
if ( persister.hasCache() ) {
ck = session.generateCacheKey( id, persister.getIdentifierType(), persister.getRootEntityName() );
lock = persister.getCacheAccessStrategy().lockItem( ck, version );
}
else {
ck = null;
}
if ( !isCascadeDeleteEnabled && !veto ) {
persister.delete( id, version, instance, session );
}
//postDelete:
// After actually deleting a row, record the fact that the instance no longer
// exists on the database (needed for identity-column key generation), and
// remove it from the session cache
final PersistenceContext persistenceContext = session.getPersistenceContext();
final EntityEntry entry = persistenceContext.removeEntry( instance );
if ( entry == null ) {
throw new AssertionFailure( "possible nonthreadsafe access to session" );
}
entry.postDelete();
persistenceContext.removeEntity( entry.getEntityKey() );
persistenceContext.removeProxy( entry.getEntityKey() );
if ( persister.hasCache() ) {
persister.getCacheAccessStrategy().remove( ck );
}
persistenceContext.getNaturalIdHelper().removeSharedNaturalIdCrossReference( persister, id, naturalIdValues );
postDelete();
if ( getSession().getFactory().getStatistics().isStatisticsEnabled() && !veto ) {
getSession().getFactory().getStatisticsImplementor().deleteEntity( getPersister().getEntityName() );
}
}
示例14: isCachePutEnabled
import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
private boolean isCachePutEnabled(EntityPersister persister, SessionImplementor session) {
return persister.hasCache()
&& !persister.isCacheInvalidationRequired()
&& session.getCacheMode().isPutEnabled();
}