@Override public List<Partij> get() { final TypedQuery<Partij> query = em.createQuery("select p from Partij p where p.isActueelEnGeldig = true", Partij.class); query.setHint("javax.persistence.cache.retrieveMode", CacheRetrieveMode.BYPASS); query.setHint("javax.persistence.cache.storeMode", CacheStoreMode.REFRESH); return query.getResultList(); }
private void zetDefaults(final Query query) { final Calendar cal = Calendar.getInstance(); final int maandenTerug = -DATUM_EINDE_TERUG_MAAND; cal.add(Calendar.MONTH, maandenTerug); final Integer waarde = DatumUtil.vanDatumNaarInteger(cal.getTime()); query.setParameter("dateinde", waarde); query.setHint("javax.persistence.cache.retrieveMode", CacheRetrieveMode.BYPASS); query.setHint("javax.persistence.cache.storeMode", CacheStoreMode.REFRESH); }
@Test(threadPoolSize = 10, invocationCount = 100) public void selectWithCaseAndHintShouldWorkInParallel() { EntityManager em = emf.createEntityManager(); try { List result = em .createQuery("select case when d.id = 0 then 1 else 2 end from Dog d") .setHint("javax.persistence.cache.storeMode", CacheStoreMode.REFRESH) .getResultList(); } finally { em.close(); } }
@Test(threadPoolSize = 10, invocationCount = 100) public void selectWithHintAndNoCaseShouldWorkInParallel() { EntityManager em = emf.createEntityManager(); try { List result = em .createQuery("select d from Dog d") .setHint("javax.persistence.cache.storeMode", CacheStoreMode.REFRESH) .getResultList(); } finally { em.close(); } }
@Before public void configureEntityManager() { // These are defaults but put here for documentation purposes manager.setProperty("javax.persistence.cache.storeMode", CacheStoreMode.USE); manager.setProperty("javax.persistence.cache.retrieveMode", CacheRetrieveMode.USE); }
protected CacheStoreMode getCacheStoreMode() { return entityManager.getProperties().containsKey(CACHE_STORE_MODE) ? (CacheStoreMode) entityManager.getProperties().get( CACHE_STORE_MODE) : CacheStoreMode.BYPASS; }
protected void setCacheStoreMode(final CacheStoreMode storeMode) { if (storeMode != null) { entityManager.getProperties(). put(CACHE_STORE_MODE, storeMode); } }
private CacheConfig(CacheRetrieveMode retrieveMode, CacheStoreMode storeMode) { this.retrieveMode = retrieveMode; this.storeMode = storeMode; }
public CacheStoreMode getStoreMode() { return storeMode; }
/** * get entities from cache */ public static CacheConfig get() { return new CacheConfig(CacheRetrieveMode.USE, CacheStoreMode.USE); }
/** * get entities from db and refresh cache */ public static CacheConfig refresh() { return new CacheConfig(CacheRetrieveMode.USE, CacheStoreMode.REFRESH); }
/** * bypass cache */ public static CacheConfig bypass() { return new CacheConfig(CacheRetrieveMode.BYPASS, CacheStoreMode.BYPASS); }
public static void cacheable(Query query) { query.setHint(CACHEBLE, true); query.setHint(RETRIEVE_MODE, CacheRetrieveMode.USE); query.setHint(STORE_MODE, CacheStoreMode.USE); }