• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java CacheKey类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.hibernate.cache.spi.CacheKey的典型用法代码示例。如果您正苦于以下问题:Java CacheKey类的具体用法?Java CacheKey怎么用?Java CacheKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CacheKey类属于org.hibernate.cache.spi包,在下文中一共展示了CacheKey类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: beforeExecutions

import org.hibernate.cache.spi.CacheKey; //导入依赖的package包/类
@Override
public final void beforeExecutions() throws CacheException {
	// we need to obtain the lock before any actions are executed, since this may be an inverse="true"
	// bidirectional association and it is one of the earlier entity actions which actually updates
	// the database (this action is responsible for second-level cache invalidation only)
	if ( persister.hasCache() ) {
		final CacheKey ck = session.generateCacheKey(
				key,
				persister.getKeyType(),
				persister.getRole()
		);
		final SoftLock lock = persister.getCacheAccessStrategy().lockItem( ck, null );
		// the old behavior used key as opposed to getKey()
		afterTransactionProcess = new CacheCleanupProcess( key, persister, lock );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:CollectionAction.java


示例2: doAfterTransactionCompletion

import org.hibernate.cache.spi.CacheKey; //导入依赖的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 );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:EntityUpdateAction.java


示例3: write

import org.hibernate.cache.spi.CacheKey; //导入依赖的package包/类
@Override
public void write(ObjectDataOutput out, CacheKey object)
        throws IOException {

    try {
        Object key = UNSAFE.getObject(object, KEY_OFFSET);
        Type type = (Type) UNSAFE.getObject(object, TYPE_OFFSET);
        String entityOrRoleName = (String) UNSAFE.getObject(object, ENTITY_OR_ROLE_NAME_OFFSET);
        String tenantId = (String) UNSAFE.getObject(object, TENANT_ID_OFFSET);
        int hashCode = UNSAFE.getInt(object, HASH_CODE_OFFSET);

        out.writeObject(key);
        out.writeObject(type);
        out.writeUTF(entityOrRoleName);
        out.writeUTF(tenantId);
        out.writeInt(hashCode);

    } catch (Exception e) {
        if (e instanceof IOException) {
            throw (IOException) e;
        }
        throw new IOException(e);
    }
}
 
开发者ID:hazelcast,项目名称:hazelcast-hibernate,代码行数:25,代码来源:Hibernate4CacheKeySerializer.java


示例4: read

import org.hibernate.cache.spi.CacheKey; //导入依赖的package包/类
@Override
public CacheKey read(ObjectDataInput in)
        throws IOException {

    try {
        Object key = in.readObject();
        Type type = in.readObject();
        String entityOrRoleName = in.readUTF();
        String tenantId = in.readUTF();
        int hashCode = in.readInt();

        CacheKey cacheKey = (CacheKey) UNSAFE.allocateInstance(CacheKey.class);
        UNSAFE.putObjectVolatile(cacheKey, KEY_OFFSET, key);
        UNSAFE.putObjectVolatile(cacheKey, TYPE_OFFSET, type);
        UNSAFE.putObjectVolatile(cacheKey, ENTITY_OR_ROLE_NAME_OFFSET, entityOrRoleName);
        UNSAFE.putObjectVolatile(cacheKey, TENANT_ID_OFFSET, tenantId);
        UNSAFE.putIntVolatile(cacheKey, HASH_CODE_OFFSET, hashCode);
        return cacheKey;

    } catch (Exception e) {
        if (e instanceof IOException) {
            throw (IOException) e;
        }
        throw new IOException(e);
    }
}
 
开发者ID:hazelcast,项目名称:hazelcast-hibernate,代码行数:27,代码来源:Hibernate4CacheKeySerializer.java


示例5: testAutoregistrationOnHibernate4Available

import org.hibernate.cache.spi.CacheKey; //导入依赖的package包/类
@Test
public void testAutoregistrationOnHibernate4Available()
        throws Exception {

    HazelcastInstance hz = Hazelcast.newHazelcastInstance();
    HazelcastInstanceImpl impl = (HazelcastInstanceImpl) ORIGINAL.get(hz);
    SerializationService ss = impl.getSerializationService();
    ConcurrentMap<Class, ?> typeMap = (ConcurrentMap<Class, ?>) TYPE_MAP.get(ss);

    boolean cacheKeySerializerFound = false;
    boolean cacheEntrySerializerFound = false;
    for (Class clazz : typeMap.keySet()) {
        if (clazz == CacheKey.class) {
            cacheKeySerializerFound = true;
        } else if (clazz == CacheEntry.class) {
            cacheEntrySerializerFound = true;
        }
    }

    assertTrue("CacheKey serializer not found", cacheKeySerializerFound);
    assertTrue("CacheEntry serializer not found", cacheEntrySerializerFound);
}
 
开发者ID:hazelcast,项目名称:hazelcast-hibernate,代码行数:23,代码来源:HibernateSerializationHookAvailableTest.java


示例6: removeCache

import org.hibernate.cache.spi.CacheKey; //导入依赖的package包/类
private void removeCache(String cacheRegion, Serializable key) {
    String cacheName = cacheRegion;
    if (key instanceof CacheKey) {
        cacheName = ((CacheKey) key).getEntityOrRoleName();
        key = ((CacheKey) key).getKey();
    }
    if (containsCache(cacheRegion, cacheName)) {
        HydratedCache cache = hydratedCacheContainer.get(cacheRegion + "_" + cacheName);
        String myKey = cacheRegion + "_" + cacheName + "_" + key;
        if (cache.containsKey(myKey)) {
            if (LOG.isInfoEnabled()) {
                LOG.info("Clearing hydrated cache for cache name: " + cacheRegion + "_" + cacheName + "_" + key);
            }
            cache.removeCacheElement(cacheRegion, cacheName, key);
        }
    }
}
 
开发者ID:passion1014,项目名称:metaworks_framework,代码行数:18,代码来源:HydratedCacheManagerImpl.java


示例7: removeCache

import org.hibernate.cache.spi.CacheKey; //导入依赖的package包/类
protected void removeCache(String cacheRegion, Serializable key) {
    String cacheName = cacheRegion;
    if (key instanceof CacheKey) {
        cacheName = ((CacheKey) key).getEntityOrRoleName();
        key = ((CacheKey) key).getKey();
    }
    String nameKey = cacheRegion + '_' + cacheName + '_' + key;
    if (cacheMembersByEntity.containsKey(nameKey)) {
        String[] members = new String[cacheMembersByEntity.get(nameKey).size()];
        members = cacheMembersByEntity.get(nameKey).toArray(members);
        for (String myMember : members) {
            String itemKey = cacheRegion + '_' + cacheName + '_' + myMember + '_' + key;
            getHeap().remove(itemKey);
        }
        cacheMembersByEntity.remove(nameKey);
    }
}
 
开发者ID:passion1014,项目名称:metaworks_framework,代码行数:18,代码来源:EhcacheHydratedCacheManagerImpl.java


示例8: removeCache

import org.hibernate.cache.spi.CacheKey; //导入依赖的package包/类
protected void removeCache(String cacheRegion, Serializable key) {
    String cacheName = cacheRegion;
    if (key instanceof CacheKey) {
        cacheName = ((CacheKey) key).getEntityOrRoleName();
        key = ((CacheKey) key).getKey();
    }
    String nameKey = cacheRegion + '_' + cacheName + '_' + key;
    if (cacheMemberNamesByEntity.containsKey(nameKey)) {
        String[] members = new String[cacheMemberNamesByEntity.get(nameKey).size()];
        members = cacheMemberNamesByEntity.get(nameKey).toArray(members);
        for (String myMember : members) {
            String itemKey = cacheRegion + '_' + myMember + '_' + key;
            removeKeys.add(itemKey);
        }
        cacheMemberNamesByEntity.remove(nameKey);
    }
}
 
开发者ID:passion1014,项目名称:metaworks_framework,代码行数:18,代码来源:BigMemoryHydratedCacheManagerImpl.java


示例9: initializeLazyProperty

import org.hibernate.cache.spi.CacheKey; //导入依赖的package包/类
public Object initializeLazyProperty(String fieldName, Object entity, SessionImplementor session)
		throws HibernateException {

	final Serializable id = session.getContextEntityIdentifier( entity );

	final EntityEntry entry = session.getPersistenceContext().getEntry( entity );
	if ( entry == null ) {
		throw new HibernateException( "entity is not associated with the session: " + id );
	}

	if ( LOG.isTraceEnabled() ) {
		LOG.tracev( "Initializing lazy properties of: {0}, field access: {1}", MessageHelper.infoString( this, id, getFactory() ), fieldName );
	}

	if ( session.getCacheMode().isGetEnabled() && hasCache() ) {
		final CacheKey cacheKey = session.generateCacheKey( id, getIdentifierType(), getEntityName() );
		final Object ce = CacheHelper.fromSharedCache( session, cacheKey, getCacheAccessStrategy() );
		if ( ce != null ) {
			final CacheEntry cacheEntry = (CacheEntry) getCacheEntryStructure().destructure(ce, factory);
			if ( !cacheEntry.areLazyPropertiesUnfetched() ) {
				//note early exit here:
				return initializeLazyPropertiesFromCache( fieldName, entity, session, entry, cacheEntry );
			}
		}
	}

	return initializeLazyPropertiesFromDatastore( fieldName, entity, session, id, entry );

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:AbstractEntityPersister.java


示例10: isCached

import org.hibernate.cache.spi.CacheKey; //导入依赖的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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:12,代码来源:BatchFetchQueue.java


示例11: getEntries

import org.hibernate.cache.spi.CacheKey; //导入依赖的package包/类
public Map getEntries() {
	Map map = new HashMap();
	Iterator iter = region.toMap().entrySet().iterator();
	while (iter.hasNext()) {
		Map.Entry me = (Map.Entry) iter.next();
		map.put(((CacheKey) me.getKey()).getKey(), me.getValue());
	}
	return map;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:ConcurrentSecondLevelCacheStatisticsImpl.java


示例12: buildCacheKey

import org.hibernate.cache.spi.CacheKey; //导入依赖的package包/类
private CacheKey buildCacheKey(Serializable identifier, EntityPersister p) {
	return new CacheKey(
			identifier,
			p.getIdentifierType(),
			p.getRootEntityName(),
			null,                         // have to assume non tenancy
			sessionFactory
	);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:CacheImpl.java


示例13: evictCollection

import org.hibernate.cache.spi.CacheKey; //导入依赖的package包/类
@Override
public void evictCollection(String role, Serializable ownerIdentifier) {
	CollectionPersister p = sessionFactory.getCollectionPersister( role );
	if ( p.hasCache() ) {
		if ( LOG.isDebugEnabled() ) {
			LOG.debugf(
					"Evicting second-level cache: %s",
					MessageHelper.collectionInfoString( p, ownerIdentifier, sessionFactory )
			);
		}
		CacheKey cacheKey = buildCacheKey( ownerIdentifier, p );
		p.getCacheAccessStrategy().evict( cacheKey );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:CacheImpl.java


示例14: refresh

import org.hibernate.cache.spi.CacheKey; //导入依赖的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() );
	}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:StatelessSessionImpl.java


示例15: lockAndLoad

import org.hibernate.cache.spi.CacheKey; //导入依赖的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 );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:47,代码来源:DefaultLoadEventListener.java


示例16: doAfterTransactionCompletion

import org.hibernate.cache.spi.CacheKey; //导入依赖的package包/类
@Override
public void doAfterTransactionCompletion(boolean success, SessionImplementor session) throws HibernateException {
	if ( getPersister().hasCache() ) {
		final CacheKey ck = getSession().generateCacheKey(
				getId(),
				getPersister().getIdentifierType(),
				getPersister().getRootEntityName()
		);
		getPersister().getCacheAccessStrategy().unlockItem( ck, lock );
	}
	postCommitDelete( success );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:EntityDeleteAction.java


示例17: cacheInsert

import org.hibernate.cache.spi.CacheKey; //导入依赖的package包/类
private boolean cacheInsert(EntityPersister persister, CacheKey ck) {
	try {
		getSession().getEventListenerManager().cachePutStart();
		return persister.getCacheAccessStrategy().insert( ck, cacheEntry, version );
	}
	finally {
		getSession().getEventListenerManager().cachePutEnd();
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:EntityInsertAction.java


示例18: doAfterTransactionCompletion

import org.hibernate.cache.spi.CacheKey; //导入依赖的package包/类
@Override
public void doAfterTransactionCompletion(boolean success, SessionImplementor session) throws HibernateException {
	final EntityPersister persister = getPersister();
	if ( success && isCachePutEnabled( persister, getSession() ) ) {
		final CacheKey ck = getSession().generateCacheKey( getId(), persister.getIdentifierType(), persister.getRootEntityName() );
		final boolean put = cacheAfterInsert( persister, ck );

		if ( put && getSession().getFactory().getStatistics().isStatisticsEnabled() ) {
			getSession().getFactory().getStatisticsImplementor()
					.secondLevelCachePut( getPersister().getCacheAccessStrategy().getRegion().getName() );
		}
	}
	postCommitInsert( success );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:EntityInsertAction.java


示例19: cacheAfterInsert

import org.hibernate.cache.spi.CacheKey; //导入依赖的package包/类
private boolean cacheAfterInsert(EntityPersister persister, CacheKey ck) {
	try {
		getSession().getEventListenerManager().cachePutStart();
		return persister.getCacheAccessStrategy().afterInsert( ck, cacheEntry, version );
	}
	finally {
		getSession().getEventListenerManager().cachePutEnd();
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:EntityInsertAction.java


示例20: evict

import org.hibernate.cache.spi.CacheKey; //导入依赖的package包/类
protected final void evict() throws CacheException {
	if ( persister.hasCache() ) {
		final CacheKey ck = session.generateCacheKey(
				key, 
				persister.getKeyType(), 
				persister.getRole()
		);
		persister.getCacheAccessStrategy().remove( ck );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:CollectionAction.java



注:本文中的org.hibernate.cache.spi.CacheKey类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TDTDReader类代码示例发布时间:2022-05-23
下一篇:
Java ActionDomainEvent类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap