/** * Return the data cache for this class, or null if it is not cachable. */ public DataCache getDataCache() { String name = getDataCacheName(); if (name == null) { return null; } return _repos.getConfiguration().getDataCacheManagerInstance().getDataCache(name, true); }
public boolean isCached(List<Object> oids, BitSet edata) { // If using partitioned cache, we were and still are broke. DataCache cache = _mgr.getSystemDataCache(); if (cache != null && !isLocking(null)) { // BitSet size is not consistent. for(int i = 0; i < oids.size(); i++) { Object oid = oids.get(i); // Only check the cache if we haven't found the current oid. if (edata.get(i) == false && cache.contains(oid)) { edata.set(i); } } if (edata.cardinality() == oids.size()){ return true; } } return super.isCached(oids, edata); }
public void setContext(StoreContext ctx) { _ctx = ctx; _mgr = ctx.getConfiguration().getDataCacheManagerInstance(); _gen = _mgr.getPCDataGenerator(); super.setContext(ctx); }
public void cache(String className, boolean enable) { if (enable) { _dcm.startCaching(className); } else { _dcm.stopCaching(className); } }
public StoreQuery newQuery(String language) { StoreQuery sq = newStoreQuery(language); if (sq == null || QueryLanguages.parserForLanguage(language) == null) { return sq; } QueryCache queryCache = _ctx.getConfiguration().getDataCacheManagerInstance().getSystemQueryCache(); if (queryCache == null) { return sq; } return new QueryCacheStoreQuery(sq, queryCache); }
@Override public void initialize() { Options opts = new Options(); if (getOptions() != null) { opts = Configurations.parseProperties(getOptions()); } String cacheName = opts.getProperty("name",null); OpenJPAConfiguration conf = (OpenJPAConfiguration)getProvider().getConfiguration(); DataCacheManager dcm = conf.getDataCacheManagerInstance(); DataCache dc = null; if (cacheName == null || cacheName.trim().length() == 0) { dc = dcm.getSystemDataCache(); } else { dc = dcm.getDataCache(cacheName); } if (dc == null) { throw new UserException(_loc.get("data-cache-not-found")); } setDataCache(dc); setDataCacheManager(dcm); setConfigId(conf.getId()); setContextRef(Integer.toString(System.identityHashCode(getContext()))); }
@Test public void query() { final EntityManagerFactory emf = Persistence.createEntityManagerFactory("test-jcache", props); final OpenJPAConfiguration conf = OpenJPAEntityManagerFactorySPI.class.cast(emf).getConfiguration(); final EntityManager em = emf.createEntityManager(); final MyEntity entity = new MyEntity(); entity.setName("cacheMe1"); em.getTransaction().begin(); em.persist(entity); em.getTransaction().commit(); final Query query = em.createQuery("select e from OpenJPAJCacheDataCacheTest$MyEntity e where e.id = :id"); assertEquals(1, query.setParameter("id", entity.getId()).getResultList().size()); assertNotNull(conf.getDataCacheManagerInstance().getDataCache("default")); assertThat(conf.getDataCacheManagerInstance(), instanceOf(OpenJPAJCacheDataCacheManager.class)); assertThat(conf.getDataCacheManagerInstance().getDataCache("default"), instanceOf(OpenJPAJCacheDataCache.class)); assertTrue(conf.getDataCacheManagerInstance().getDataCache("default").contains(JPAFacadeHelper.toOpenJPAObjectId(conf.getMetaDataRepositoryInstance().getCachedMetaData(MyEntity.class), entity.getId()))); final Map<Object, Object> args = new HashMap<Object, Object>() {{ put("id", entity.getId()); }}; final QueryKey qk = QueryKey.newInstance(query.unwrap(org.apache.openjpa.kernel.Query.class), args); assertNotNull(conf.getDataCacheManagerInstance().getSystemQueryCache().get(qk)); em.close(); emf.close(); }
/** * Return whether the given field is loaded for the given instance. */ private boolean isLoaded(OpenJPAStateManager sm, int field) { if (sm.getLoaded().get(field)) return true; // if the field isn't loaded in the state manager, it still might be // loaded in the data cache, in which case we still have to correct // it to keep the cache in sync DataCache cache = _mgr.selectCache(sm); if (cache == null) return false; // can't retrieve an embedded object directly, so always assume the // field is loaded and needs to be corrected if (sm.isEmbedded()) return true; PCData pc = cache.get(sm.getObjectId()); if (pc == null) return false; return pc.isLoaded(field); }
public void setDataCacheManager(DataCacheManager dcm) { if (dcm != null) dcm.initialize(this, dataCachePlugin, queryCachePlugin); dataCacheManagerPlugin.set(dcm); }
public Map<String, Boolean> listKnownTypes() { return _dcm.listKnownTypes(); } public void collectStatistics(boolean enable) {
public void initialize(DataCacheManager manager) { if (_schedule != null && !"".equals(_schedule)) { ClearableScheduler scheduler = manager.getClearableScheduler(); if (scheduler != null) scheduler.scheduleEviction(this, _schedule); } // Cast here rather than add to the interface because this is a hack to support an older way of configuring if(manager instanceof DataCacheManagerImpl){ List<String> invalidConfigured = new ArrayList<String>(); // assert that things are configured properly if(_includedTypes!=null){ for(String s : _includedTypes){ if(_excludedTypes.contains(s)){ invalidConfigured.add(s); } } if (invalidConfigured.size() > 0) { throw new GeneralException(s_loc.get("invalid-types-excluded-types", invalidConfigured.toString())); } } ((DataCacheManagerImpl)manager).setTypes(_includedTypes, _excludedTypes); } }
public StoreQuery newQuery(String language) { StoreQuery q = super.newQuery(language); // if the query can't be parsed or it's using a non-parsed language // (one for which there is no ExpressionParser), we can't cache it. if (q == null || QueryLanguages.parserForLanguage(language) == null) return q; QueryCache queryCache = _ctx.getConfiguration(). getDataCacheManagerInstance().getSystemQueryCache(); if (queryCache == null) return q; return new QueryCacheStoreQuery(q, queryCache); }
@Override public void initialize() { Options opts = new Options(); if (getOptions() != null) { opts = Configurations.parseProperties(getOptions()); } String cacheName = opts.getProperty("name",null); OpenJPAConfiguration conf = (OpenJPAConfiguration)getProvider().getConfiguration(); DataCacheManager dcm = conf.getDataCacheManagerInstance(); DataCache dc = null; if (cacheName == null || cacheName.trim().length() == 0) { dc = dcm.getSystemDataCache(); } else { dc = dcm.getDataCache(cacheName); } if (dc == null) { throw new UserException(_loc.get("data-cache-not-found")); } setDataCache(dc); setDataCacheManager(dcm); setConfigId(conf.getId()); setContextRef(Integer.toString(System.identityHashCode(getContext()))); }
/** * Return whether the given field is loaded for the given instance. */ private boolean isLoaded(OpenJPAStateManager sm, int field) { if (sm.getLoaded().get(field)) return true; // if the field isn't loaded in the state manager, it still might be // loaded in the data cache, in which case we still have to correct // it to keep the cache in sync DataCache cache = _mgr.selectCache(sm); if (cache == null) return false; // can't retrieve an embedded object directly, so always assume the // field is loaded and needs to be corrected if (sm.isEmbedded()) return true; PCData pc = cache.get(sm.getObjectId()); if (pc == null) return false; return pc.isLoaded(field); }
public void cache(String className, boolean enable) { if (enable) { _dcm.startCaching(className); } else { _dcm.stopCaching(className); } }
public void setDataCacheManager(DataCacheManager dcm) { if (dcm != null) dcm.initialize(this, dataCachePlugin, queryCachePlugin); dataCacheManagerPlugin.set(dcm); }
public Map<String, Boolean> listKnownTypes() { return _dcm.listKnownTypes(); } public void collectStatistics(boolean enable) {
public void initialize(DataCacheManager manager) { if (_schedule != null && !"".equals(_schedule)) { ClearableScheduler scheduler = manager.getClearableScheduler(); if (scheduler != null) scheduler.scheduleEviction(this, _schedule); } // Cast here rather than add to the interface because this is a hack to support an older way of configuring if(manager instanceof DataCacheManagerImpl){ List<String> invalidConfigured = new ArrayList<String>(); // assert that things are configured properly if(_includedTypes!=null){ for(String s : _includedTypes){ if(_excludedTypes.contains(s)){ invalidConfigured.add(s); } } if (invalidConfigured.size() > 0) { throw new GeneralException(s_loc.get("invalid-types-excluded-types", invalidConfigured.toString())); } } ((DataCacheManagerImpl)manager).setTypes(_includedTypes, _excludedTypes); } }
public QueryResultCache getQueryResultCache() { _factory.lock(); try { if (_queryCache == null) _queryCache = new QueryResultCacheImpl(_factory. getConfiguration().getDataCacheManagerInstance(). getSystemQueryCache()); return _queryCache; } finally { _factory.unlock(); } }
@Override public void initialize() { Options opts = new Options(); if (getOptions() != null) { opts = Configurations.parseProperties(getOptions()); } String cacheName = opts.getProperty("name",null); OpenJPAConfiguration conf = (OpenJPAConfiguration)getProvider().getConfiguration(); DataCacheManager dcm = conf.getDataCacheManagerInstance(); DataCache dc = null; if (cacheName == null || cacheName.trim().length() == 0) { dc = dcm.getSystemDataCache(); } else { dc = dcm.getDataCache(cacheName); } if (dc == null) { throw new UserException(_loc.get("data-cache-not-found")); } setDataCache(dc); setDataCacheManager(dcm); setConfigId(conf.getId()); setContextRef(Integer.toString(System.identityHashCode(getContext()))); }