类org.hibernate.cache.spi.access.SoftLock源码实例Demo

下面列出了怎么用org.hibernate.cache.spi.access.SoftLock的API类实例代码及写法,或者点击链接到github查看源代码。

@Override
public boolean afterUpdate(Object key, Object value, SoftLock lock) throws CacheException {
    region().writeLock(key);
    try {
        final Lockable item = (Lockable) region().get(key);
        if (item != null && item.isUnlockable(lock)) {
            final Lock lockItem = (Lock) item;
            if (lockItem.wasLockedConcurrently()) {
                decrementLock(key, lockItem);
                return false;
            } else {
                region().put(key, new Item(value, null, region().nextTimestamp()));
                return true;
            }
        } else {
            handleLockExpiry(key, item);
            return false;
        }
    } finally {
        region().writeUnlock(key);
    }
}
 
@Override
public boolean afterUpdate(SharedSessionContractImplementor session, Object key, Object value, SoftLock lock) throws CacheException {
    region().writeLock(key);
    try {
        final Lockable item = (Lockable) region().get(key);
        if (item != null && item.isUnlockable(lock)) {
            final Lock lockItem = (Lock) item;
            if (lockItem.wasLockedConcurrently()) {
                decrementLock(key, lockItem);
                return false;
            } else {
                region().put(key, new Item(value, null, region().nextTimestamp()));
                return true;
            }
        } else {
            handleLockExpiry(key, item);
            return false;
        }
    } finally {
        region().writeUnlock(key);
    }
}
 
private void evictCachedCollections(Type[] types, Serializable id, EventSource source)
		throws HibernateException {
	final ActionQueue actionQueue = source.getActionQueue();
	final SessionFactoryImplementor factory = source.getFactory();
	final MetamodelImplementor metamodel = factory.getMetamodel();
	for ( Type type : types ) {
		if ( type.isCollectionType() ) {
			CollectionPersister collectionPersister = metamodel.collectionPersister( ( (CollectionType) type ).getRole() );
			if ( collectionPersister.hasCache() ) {
				final CollectionDataAccess cache = collectionPersister.getCacheAccessStrategy();
				final Object ck = cache.generateCacheKey(
					id,
					collectionPersister,
					factory,
					source.getTenantIdentifier()
				);
				final SoftLock lock = cache.lockItem( source, ck, null );
				cache.remove( source, ck );
				actionQueue.registerProcess( (success, session) -> cache.unlockItem( session, ck, lock ) );
			}
		}
		else if ( type.isComponentType() ) {
			CompositeType actype = (CompositeType) type;
			evictCachedCollections( actype.getSubtypes(), id, source );
		}
	}
}
 
@Override
public boolean afterUpdate(Object key, Object value, SoftLock lock) throws CacheException {
    try {
        return actualStrategy.afterUpdate(key, value, lock);
    } catch (NonStopCacheException nonStopCacheException) {
        hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException);
        return false;
    }
}
 
@Override
public SoftLock lockItem(Object key, Object version) throws CacheException {
    try {
        return actualStrategy.lockItem(key, version);
    } catch (NonStopCacheException nonStopCacheException) {
        hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException);
        return null;
    }
}
 
@Override
public SoftLock lockRegion() throws CacheException {
    try {
        return actualStrategy.lockRegion();
    } catch (NonStopCacheException nonStopCacheException) {
        hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException);
        return null;
    }
}
 
@Override
public void unlockItem(Object key, SoftLock lock) throws CacheException {
    try {
        actualStrategy.unlockItem(key, lock);
    } catch (NonStopCacheException nonStopCacheException) {
        hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException);
    }
}
 
@Override
public void unlockRegion(SoftLock lock) throws CacheException {
    try {
        actualStrategy.unlockRegion(lock);
    } catch (NonStopCacheException nonStopCacheException) {
        hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException);
    }
}
 
@Override
public SoftLock lockItem(Object key, Object version) throws CacheException {
    try {
        return actualStrategy.lockItem(key, version);
    } catch (NonStopCacheException nonStopCacheException) {
        hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException);
        return null;
    }
}
 
@Override
public SoftLock lockRegion() throws CacheException {
    try {
        return actualStrategy.lockRegion();
    } catch (NonStopCacheException nonStopCacheException) {
        hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException);
        return null;
    }
}
 
@Override
public void unlockItem(Object key, SoftLock lock) throws CacheException {
    try {
        actualStrategy.unlockItem(key, lock);
    } catch (NonStopCacheException nonStopCacheException) {
        hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException);
    }
}
 
@Override
public void unlockRegion(SoftLock lock) throws CacheException {
    try {
        actualStrategy.unlockRegion(lock);
    } catch (NonStopCacheException nonStopCacheException) {
        hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException);
    }
}
 
@Override
public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException {
    try {
        return actualStrategy.afterUpdate(key, value, currentVersion, previousVersion, lock);
    } catch (NonStopCacheException nonStopCacheException) {
        hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException);
        return false;
    }
}
 
@Override
public SoftLock lockItem(Object key, Object version) throws CacheException {
    try {
        return actualStrategy.lockItem(key, version);
    } catch (NonStopCacheException nonStopCacheException) {
        hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException);
        return null;
    }
}
 
@Override
public boolean afterUpdate(SharedSessionContractImplementor session, Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock)
        throws CacheException {
    //what should we do with previousVersion here?
    region().writeLock( key );
    try {
        final AbstractReadWriteJ2CacheAccessStrategy.Lockable item = (AbstractReadWriteJ2CacheAccessStrategy.Lockable) region().get( key );

        if ( item != null && item.isUnlockable( lock ) ) {
            final AbstractReadWriteJ2CacheAccessStrategy.Lock lockItem = (AbstractReadWriteJ2CacheAccessStrategy.Lock) item;
            if ( lockItem.wasLockedConcurrently() ) {
                decrementLock( key, lockItem );
                return false;
            }
            else {
                region().put( key, new AbstractReadWriteJ2CacheAccessStrategy.Item( value, currentVersion, region().nextTimestamp() ) );
                return true;
            }
        }
        else {
            handleLockExpiry( key, item );
            return false;
        }
    }
    finally {
        region().writeUnlock( key );
    }
}
 
@Override
public void unlockItem(Object key, SoftLock lock) throws CacheException {
    try {
        actualStrategy.unlockItem(key, lock);
    } catch (NonStopCacheException nonStopCacheException) {
        hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException);
    }
}
 
@Override
public void unlockRegion(SoftLock lock) throws CacheException {
    try {
        actualStrategy.unlockRegion(lock);
    } catch (NonStopCacheException nonStopCacheException) {
        hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException);
    }
}
 
public final SoftLock lockItem(Object key, Object version) throws CacheException {
    region().writeLock(key);
    try {
        final Lockable item = (Lockable) region().get(key);
        final long timeout = region().nextTimestamp() + region().getTimeout();
        final Lock lock = (item == null) ? new Lock(timeout, uuid, nextLockId(), version) : item.lock(timeout, uuid, nextLockId());
        region().put(key, lock);
        return lock;
    } finally {
        region().writeUnlock(key);
    }
}
 
@Override
public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock)
        throws CacheException {
    //what should we do with previousVersion here?
    region().writeLock( key );
    try {
        final AbstractReadWriteJ2CacheAccessStrategy.Lockable item = (AbstractReadWriteJ2CacheAccessStrategy.Lockable) region().get( key );

        if ( item != null && item.isUnlockable( lock ) ) {
            final AbstractReadWriteJ2CacheAccessStrategy.Lock lockItem = (AbstractReadWriteJ2CacheAccessStrategy.Lock) item;
            if ( lockItem.wasLockedConcurrently() ) {
                decrementLock( key, lockItem );
                return false;
            }
            else {
                region().put( key, new AbstractReadWriteJ2CacheAccessStrategy.Item( value, currentVersion, region().nextTimestamp() ) );
                return true;
            }
        }
        else {
            handleLockExpiry( key, item );
            return false;
        }
    }
    finally {
        region().writeUnlock( key );
    }
}
 
@Override
public boolean afterUpdate(SharedSessionContractImplementor session, Object key, Object value, SoftLock lock) throws CacheException {
    try {
        return this.actualStrategy.afterUpdate(session, key, value, lock);
    } catch (NonStopCacheException nonStopCacheException) {
        hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException);
        return false;
    }
}
 
@Override
public SoftLock lockItem(SharedSessionContractImplementor session, Object key, Object version) throws CacheException {
    try {
        return this.actualStrategy.lockItem(session, key, version);
    } catch (NonStopCacheException nonStopCacheException) {
        hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException);
        return null;
    }
}
 
@Override
public void unlockItem(SharedSessionContractImplementor session, Object key, SoftLock lock) throws CacheException {
    try {
        this.actualStrategy.unlockItem(session, key, lock);
    } catch (NonStopCacheException nonStopCacheException) {
        hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException);
    }
}
 
@Override
public void unlockRegion(SoftLock lock) throws CacheException {
    try {
        this.actualStrategy.unlockRegion(lock);
    } catch (NonStopCacheException nonStopCacheException) {
        hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException);
    }
}
 
@Override
public SoftLock lockItem(SharedSessionContractImplementor session, Object key, Object version) throws CacheException {
    try {
        return this.actualStrategy.lockItem(session, key, version);
    } catch (NonStopCacheException nonStopCacheException) {
        hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException);
        return null;
    }
}
 
@Override
public SoftLock lockRegion() throws CacheException {
    try {
        return this.actualStrategy.lockRegion();
    } catch (NonStopCacheException nonStopCacheException) {
        hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException);
        return null;
    }
}
 
@Override
public void unlockItem(SharedSessionContractImplementor session, Object key, SoftLock lock) throws CacheException {
    try {
        this.actualStrategy.unlockItem(session, key, lock);
    } catch (NonStopCacheException nonStopCacheException) {
        hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException);
    }
}
 
@Override
public void unlockRegion(SoftLock lock) throws CacheException {
    try {
        this.actualStrategy.unlockRegion(lock);
    } catch (NonStopCacheException nonStopCacheException) {
        hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException);
    }
}
 
@Override
public boolean afterUpdate(SharedSessionContractImplementor session, Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException {
    try {
        return this.actualStrategy.afterUpdate(session, key, value, currentVersion, previousVersion, lock);
    } catch (NonStopCacheException nonStopCacheException) {
        hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException);
        return false;
    }
}
 
@Override
public SoftLock lockItem(SharedSessionContractImplementor session, Object key, Object version) throws CacheException {
    try {
        return this.actualStrategy.lockItem(session, key, version);
    } catch (NonStopCacheException nonStopCacheException) {
        hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException);
        return null;
    }
}
 
@Override
public void unlockItem(SharedSessionContractImplementor session, Object key, SoftLock lock) throws CacheException {
    try {
        this.actualStrategy.unlockItem(session, key, lock);
    } catch (NonStopCacheException nonStopCacheException) {
        hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException);
    }
}
 
 类所在包
 同包方法