List of usage examples for org.hibernate.persister.entity EntityPersister getCacheAccessStrategy
EntityDataAccess getCacheAccessStrategy();
From source file:com.fiveamsolutions.nci.commons.test.AbstractHibernateTestCase.java
License:Open Source License
/** * In JUnit3x you would normally override the setUp() and add your own functionality locally however, in JUnit4 to * override simply define your method and give it the <code>@Before annotation</code>. Doing so will cause that * method to be invoked after the parent class's setUp(). *///w w w. ja va2 s . c o m @SuppressWarnings("unchecked") @Before public final void setUp() { Transaction tx = HibernateUtil.getHibernateHelper().beginTransaction(); SchemaExport se = new SchemaExport(HibernateUtil.getHibernateHelper().getConfiguration()); se.drop(false, true); se.create(false, true); tx.commit(); // clean up the hibernate second level cache between runs SessionFactory sf = getCurrentSession().getSessionFactory(); Map<?, EntityPersister> classMetadata = sf.getAllClassMetadata(); for (EntityPersister ep : classMetadata.values()) { if (ep.hasCache()) { sf.evictEntity(ep.getCacheAccessStrategy().getRegion().getName()); } } Map<?, AbstractCollectionPersister> collMetadata = sf.getAllCollectionMetadata(); for (AbstractCollectionPersister acp : collMetadata.values()) { if (acp.hasCache()) { sf.evictCollection(acp.getCacheAccessStrategy().getRegion().getName()); } } transaction = HibernateUtil.getHibernateHelper().beginTransaction(); }
From source file:fr.keyconsulting.oliphant.NotifyListener.java
License:Open Source License
public boolean isKnownToBeStaleInL2(Object object, EventSource session) { final EntityPersister persister = sessionFactory.getEntityPersister(session.getEntityName(object)); String uid = getUid(object, session); if (!versions.containsKey(uid)) { return false; }/*w w w.j a va 2 s. c om*/ if (persister.isVersioned()) { if (persister.hasCache() && session.getCacheMode().isGetEnabled()) { final EntityRegionAccessStrategy cacheAccessStrategy = persister.getCacheAccessStrategy(); if (cacheAccessStrategy == null) { return false; } final CacheKey ck = new CacheKey(session.getIdentifier(object), persister.getIdentifierType(), persister.getRootEntityName(), session.getEntityMode(), session.getFactory()); CacheEntry cachedObject = (CacheEntry) cacheAccessStrategy.get(ck, Long.MAX_VALUE); if (cachedObject == null) { return false; } if (Base64.encodeBytes(cachedObject.getDisassembledState()[persister.getVersionProperty()] .toString().getBytes()) != versions.get(uid)) { return true; } } } return false; }
From source file:fr.keyconsulting.oliphant.NotifyListener.java
License:Open Source License
public void evictFromL2(Object object, EventSource session) { final EntityPersister persister = sessionFactory.getEntityPersister(session.getEntityName(object)); if (persister.isVersioned()) { if (persister.hasCache() && session.getCacheMode().isGetEnabled()) { final EntityRegionAccessStrategy cacheAccessStrategy = persister.getCacheAccessStrategy(); if (cacheAccessStrategy == null) { return; }//from ww w . j a va 2s . c o m final CacheKey ck = new CacheKey(session.getIdentifier(object), persister.getIdentifierType(), persister.getRootEntityName(), session.getEntityMode(), session.getFactory()); cacheAccessStrategy.evict(ck); Serializable identifier = session.getIdentifier(object); LOG.debug("* Object " + identifier + " evicted from L2"); } } }
From source file:gov.nih.nci.firebird.test.AbstractHibernateTestCase.java
License:Open Source License
/** * Method that runs before the test to clean up the db and start the transaction. *///ww w.j a v a 2s .c o m @SuppressWarnings("unchecked") @Before public void setUp() throws Exception { // clean up the hibernate second level cache between runs SessionFactory sf = getCurrentSession().getSessionFactory(); Map<String, EntityPersister> classMetadata = sf.getAllClassMetadata(); for (EntityPersister ep : classMetadata.values()) { if (ep.hasCache()) { sf.evictEntity(ep.getCacheAccessStrategy().getRegion().getName()); } } Map<?, AbstractCollectionPersister> collMetadata = sf.getAllCollectionMetadata(); for (AbstractCollectionPersister acp : collMetadata.values()) { if (acp.hasCache()) { sf.evictCollection(acp.getCacheAccessStrategy().getRegion().getName()); } } transaction = helper.beginTransaction(); }