Java Code Examples for net.sf.ehcache.Ehcache#put()
The following examples show how to use
net.sf.ehcache.Ehcache#put() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElementFactory.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") protected <T extends JpaObject> T pick(String flag, Class<T> clz) throws Exception { Ehcache cache = ApplicationCache.instance().getCache(clz); T t = null; Element element = cache.get(flag); if (null != element) { if (null != element.getObjectValue()) { t = (T) element.getObjectValue(); } } else { t = this.entityManagerContainer().flag(flag, clz); if (t != null) { this.entityManagerContainer().get(clz).detach(t); } cache.put(new Element(flag, t)); } return t; }
Example 2
Source File: AbstractFactory.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") protected <T extends JpaObject> T pick(String flag, Class<T> clz, String... attributes) throws Exception { if (StringUtils.isEmpty(flag)) { return null; } Ehcache cache = ApplicationCache.instance().getCache(clz); T t = null; Element element = cache.get(flag); if (null != element) { if (null != element.getObjectValue()) { t = (T) element.getObjectValue(); } } else { t = this.entityManagerContainer().flag(flag, clz); if (t != null) { this.entityManagerContainer().get(clz).detach(t); } cache.put(new Element(flag, t)); } return t; }
Example 3
Source File: ElementFactory.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") protected <T extends JpaObject> T pick(String flag, Class<T> clz) throws Exception { Ehcache cache = ApplicationCache.instance().getCache(clz); T t = null; Element element = cache.get(flag); if (null != element) { if (null != element.getObjectValue()) { t = (T) element.getObjectValue(); } } else { t = this.entityManagerContainer().flag(flag, clz); if (t != null) { this.entityManagerContainer().get(clz).detach(t); } cache.put(new Element(flag, t)); } return t; }
Example 4
Source File: ElementFactory.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") protected <T extends JpaObject> T pick(Application application, String flag, Class<T> clz) throws Exception { if (null == application) { return null; } Ehcache cache = ApplicationCache.instance().getCache(clz); T t = null; String cacheKey = ApplicationCache.concreteCacheKey(application.getId(), flag); Element element = cache.get(cacheKey); if (null != element) { if (null != element.getObjectValue()) { t = (T) element.getObjectValue(); } } else { t = this.entityManagerContainer().restrictFlag(flag, clz, Process.application_FIELDNAME, application.getId()); if (t != null) { this.entityManagerContainer().get(clz).detach(t); } cache.put(new Element(cacheKey, t)); } return t; }
Example 5
Source File: BeginFactory.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
public Begin getWithProcess(Process process) throws Exception { Begin o = null; Ehcache cache = ApplicationCache.instance().getCache(Begin.class); String cacheKey = "getWithProcess#" + process.getId(); Element element = cache.get(cacheKey); if (null != element) { Object obj = element.getObjectValue(); if (null != obj) { o = (Begin) obj; } } else { EntityManager em = this.entityManagerContainer().get(Begin.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Begin> cq = cb.createQuery(Begin.class); Root<Begin> root = cq.from(Begin.class); Predicate p = cb.equal(root.get("process"), process.getId()); cq.select(root).where(p); List<Begin> list = em.createQuery(cq).setMaxResults(1).getResultList(); if (!list.isEmpty()) { o = list.get(0); } cache.put(new Element(cacheKey, o)); } return o; }
Example 6
Source File: AbstractFactory.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") protected <T extends JpaObject> T pick(String flag, Class<T> clz, String... attributes) throws Exception { if (StringUtils.isEmpty(flag)) { return null; } Ehcache cache = ApplicationCache.instance().getCache(clz); T t = null; Element element = cache.get(flag); if (null != element) { if (null != element.getObjectValue()) { t = (T) element.getObjectValue(); } } else { t = this.entityManagerContainer().flag(flag, clz); if (t != null) { this.entityManagerContainer().get(clz).detach(t); } cache.put(new Element(flag, t)); } return t; }
Example 7
Source File: ElementFactory.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") public List<Route> listRouteWithParallel(String id) throws Exception { List<Route> list = new ArrayList<>(); Ehcache cache = ApplicationCache.instance().getCache(Parallel.class); String cacheKey = ApplicationCache.concreteCacheKey(id, Parallel.class.getCanonicalName()); Element element = cache.get(cacheKey); if (null != element) { list = (List<Route>) element.getObjectValue(); } else { EntityManager em = this.entityManagerContainer().get(Route.class); Parallel parallel = this.get(id, Parallel.class); if (null != parallel) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Route> cq = cb.createQuery(Route.class); Root<Route> root = cq.from(Route.class); Predicate p = root.get(Route_.id).in(parallel.getRouteList()); list = em.createQuery(cq.where(p).orderBy(cb.asc(root.get(Route_.orderNumber)))).getResultList(); if (!list.isEmpty()) { cache.put(new Element(cacheKey, list)); } } } return list; }
Example 8
Source File: ElementFactory.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") protected <T extends JpaObject> T pick( AppInfo appInfo, String flag, Class<T> clz) throws Exception { if (null == appInfo) { return null; } Ehcache cache = ApplicationCache.instance().getCache(clz); T t = null; String cacheKey = ApplicationCache.concreteCacheKey(appInfo.getId(), flag); Element element = cache.get(cacheKey); if (null != element) { if (null != element.getObjectValue()) { t = (T) element.getObjectValue(); } } else { t = this.entityManagerContainer().restrictFlag(flag, clz, CategoryInfo.appId_FIELDNAME, appInfo.getId()); if (t != null) { this.entityManagerContainer().get(clz).detach(t); } cache.put(new Element(cacheKey, t)); } return t; }
Example 9
Source File: ElementFactory.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
public Begin getBeginWithProcess(String id) throws Exception { Begin begin = null; Ehcache cache = ApplicationCache.instance().getCache(Begin.class); String cacheKey = id; Element element = cache.get(cacheKey); if (null != element) { begin = (Begin) element.getObjectValue(); } else { EntityManager em = this.entityManagerContainer().get(Begin.class); Process process = this.get(id, Process.class); if (null != process) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Begin> cq = cb.createQuery(Begin.class); Root<Begin> root = cq.from(Begin.class); Predicate p = cb.equal(root.get(Begin_.process), process.getId()); List<Begin> list = em.createQuery(cq.where(p)).setMaxResults(1).getResultList(); if (!list.isEmpty()) { begin = list.get(0); cache.put(new Element(cacheKey, begin)); } } } return begin; }
Example 10
Source File: ElementFactory.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") public List<Route> listRouteWithChoice(String id) throws Exception { List<Route> list = new ArrayList<>(); Ehcache cache = ApplicationCache.instance().getCache(Route.class); String cacheKey = ApplicationCache.concreteCacheKey(id, Choice.class.getCanonicalName()); Element element = cache.get(cacheKey); if (null != element) { list = (List<Route>) element.getObjectValue(); } else { EntityManager em = this.entityManagerContainer().get(Route.class); Choice choice = this.get(id, Choice.class); if (null != choice) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Route> cq = cb.createQuery(Route.class); Root<Route> root = cq.from(Route.class); Predicate p = root.get(Route_.id).in(choice.getRouteList()); list = em.createQuery(cq.where(p).orderBy(cb.asc(root.get(Route_.orderNumber)))).getResultList(); if (!list.isEmpty()) { cache.put(new Element(cacheKey, list)); } } } return list; }
Example 11
Source File: ElementFactory.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") public List<Route> listRouteWithManual(String id) throws Exception { List<Route> list = new ArrayList<>(); Ehcache cache = ApplicationCache.instance().getCache(Manual.class); String cacheKey = ApplicationCache.concreteCacheKey(id, Manual.class.getCanonicalName()); Element element = cache.get(cacheKey); if (null != element) { list = (List<Route>) element.getObjectValue(); } else { EntityManager em = this.entityManagerContainer().get(Route.class); Manual manual = this.get(id, Manual.class); if (null != manual) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Route> cq = cb.createQuery(Route.class); Root<Route> root = cq.from(Route.class); Predicate p = root.get(Route_.id).in(manual.getRouteList()); list = em.createQuery(cq.where(p).orderBy(cb.asc(root.get(Route_.orderNumber)))).getResultList(); if (!list.isEmpty()) { cache.put(new Element(cacheKey, list)); } } } return list; }
Example 12
Source File: ScriptFactory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public Script getScriptWithAppInfoWithUniqueName( String appId, String uniqueName ) throws Exception { Script script = null; try { Ehcache cache = ApplicationCache.instance().getCache( Script.class ); String cacheKey = "script.getScriptWithAppInfoWithUniqueName." + appId + "." + uniqueName; Element element = cache.get( cacheKey ); if (null != element) { script = (Script) element.getObjectValue(); } else { EntityManager em = this.entityManagerContainer().get(Script.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Script> cq = cb.createQuery(Script.class); Root<Script> root = cq.from(Script.class); Predicate p = cb.equal( root.get(Script_.name), uniqueName ); p = cb.or( p, cb.equal( root.get(Script_.alias), uniqueName )); p = cb.or( p, cb.equal( root.get(Script_.id), uniqueName )); p = cb.and( p, cb.equal( root.get(Script_.appId), appId )); List<Script> list = em.createQuery( cq.where(p) ).setMaxResults(1).getResultList(); if (!list.isEmpty()) { script = list.get(0); cache.put(new Element(cacheKey, script)); } } return script; } catch (Exception e) { throw new Exception("getScriptWithAppInfoWithUniqueName error.", e); } }
Example 13
Source File: ScriptFactory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") public List<Script> listScriptNestedWithAppInfoWithUniqueName( String appId, String uniqueName ) throws Exception { List<Script> list = new ArrayList<>(); try { Ehcache cache = ApplicationCache.instance().getCache( Script.class ); String cacheKey = "script.listScriptNestedWithAppInfoWithUniqueName." + appId + "." + uniqueName; Element element = cache.get(cacheKey); if (null != element) { list = (List<Script>) element.getObjectValue(); } else { List<String> names = new ArrayList<>(); names.add( uniqueName ); while (!names.isEmpty()) { List<String> loops = new ArrayList<>(); for ( String name : names ) { Script o = this.getScriptWithAppInfoWithUniqueName(appId, name); if ((null != o) && (!list.contains(o))) { list.add(o); loops.addAll(o.getDependScriptList()); } } names = loops; } if (!list.isEmpty()) { Collections.reverse(list); cache.put(new Element(cacheKey, list)); } } return list; } catch (Exception e) { throw new Exception("listScriptNestedWithAppInfoWithUniqueName error.", e); } }
Example 14
Source File: ElementFactory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public List<Mapping> listMappingEffectiveWithApplicationAndProcess(String application, String process) throws Exception { final List<Mapping> list = new ArrayList<>(); Ehcache cache = ApplicationCache.instance().getCache(Mapping.class); String cacheKey = ApplicationCache.concreteCacheKey(application, process, Application.class.getName(), Process.class.getName()); Element element = cache.get(cacheKey); if (null != element) { list.addAll((List<Mapping>) element.getObjectValue()); } else { EntityManager em = this.entityManagerContainer().get(Mapping.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Mapping> cq = cb.createQuery(Mapping.class); Root<Mapping> root = cq.from(Mapping.class); Predicate p = cb.equal(root.get(Mapping_.enable), true); p = cb.and(p, cb.equal(root.get(Mapping_.application), application)); p = cb.and(p, cb.or(cb.equal(root.get(Mapping_.process), process), cb.equal(root.get(Mapping_.process), ""), cb.isNull(root.get(Mapping_.process)))); List<Mapping> os = em.createQuery(cq.where(p)).getResultList(); os.stream().collect(Collectors.groupingBy(o -> { return o.getApplication() + o.getTableName(); })).forEach((k, v) -> { list.add(v.stream().filter(i -> StringUtils.isNotEmpty(i.getProcess())).findFirst().orElse(v.get(0))); }); if (!list.isEmpty()) { cache.put(new Element(cacheKey, list)); } } return list; }
Example 15
Source File: ElementFactory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") public List<Script> listScriptNestedWithApplicationWithUniqueName(String applicationId, String uniqueName) throws Exception { List<Script> list = new ArrayList<>(); Ehcache cache = ApplicationCache.instance().getCache(Script.class); String cacheKey = applicationId + "." + uniqueName; Element element = cache.get(cacheKey); if (null != element) { list = (List<Script>) element.getObjectValue(); } else { List<String> names = new ArrayList<>(); names.add(uniqueName); while (!names.isEmpty()) { List<String> loops = new ArrayList<>(); for (String name : names) { Script o = this.getScriptWithApplicationWithUniqueName(applicationId, name); if ((null != o) && (!list.contains(o))) { list.add(o); loops.addAll(o.getDependScriptList()); } } names = loops; } if (!list.isEmpty()) { Collections.reverse(list); cache.put(new Element(cacheKey, list)); } } return list; }
Example 16
Source File: ElementFactory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") public <T extends JpaObject> List<T> listWithProcess(Class<T> clz, Process process) throws Exception { List<T> list = new ArrayList<>(); Ehcache cache = ApplicationCache.instance().getCache(clz); String cacheKey = ApplicationCache.concreteCacheKey("listWithProcess", process.getId(), clz.getName()); Element element = cache.get(cacheKey); if (null != element) { Object obj = element.getObjectValue(); if (null != obj) { list = (List<T>) obj; } } else { EntityManager em = this.entityManagerContainer().get(clz); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<T> cq = cb.createQuery(clz); Root<T> root = cq.from(clz); Predicate p = cb.equal(root.get(Agent.process_FIELDNAME), process.getId()); cq.select(root).where(p); List<T> os = em.createQuery(cq).getResultList(); for (T t : os) { em.detach(t); list.add(t); } /* 将object改为unmodifiable */ list = Collections.unmodifiableList(list); cache.put(new Element(cacheKey, list)); } return list; }
Example 17
Source File: QueryViewFactory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public QueryView pick(String flag, Application application, ExceptionWhen exceptionWhen) throws Exception { Ehcache cache = ApplicationCache.instance().getCache(QueryView.class); String cacheKey = flag + "#" + application.getId(); Element element = cache.get(cacheKey); QueryView o = null; if (null != element) { if (null != element.getObjectValue()) { o = (QueryView) element.getObjectValue(); } } else { EntityManager em = this.entityManagerContainer().get(QueryView.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<QueryView> cq = cb.createQuery(QueryView.class); Root<QueryView> root = cq.from(QueryView.class); Predicate p = cb.equal(root.get(QueryView_.application), application.getId()); p = cb.and(p, cb.or(cb.equal(root.get(QueryView_.id), flag), cb.equal(root.get(QueryView_.alias), flag), cb.equal(root.get(QueryView_.name), flag))); cq.select(root).where(p); List<QueryView> list = em.createQuery(cq).getResultList(); if (list.isEmpty()) { cache.put(new Element(cacheKey, o)); } else if (list.size() == 1) { o = list.get(0); em.detach(o); cache.put(new Element(cacheKey, o)); } else { throw new Exception("multiple queryView with flag:" + flag + "."); } } if (o == null && Objects.equals(ExceptionWhen.not_found, exceptionWhen)) { throw new Exception("can not find queryView with flag:" + flag + "."); } return o; }
Example 18
Source File: ElementFactory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") protected <T extends JpaObject> List<T> listWithCategory(Class<T> clz, CategoryInfo categoryInfo) throws Exception { List<T> list = new ArrayList<>(); Ehcache cache = ApplicationCache.instance().getCache(clz); String cacheKey = "listWithCategory#" + categoryInfo.getId() + "#" + clz.getName(); Element element = cache.get(cacheKey); if (null != element) { Object obj = element.getObjectValue(); if (null != obj) { list = (List<T>) obj; } } else { EntityManager em = this.entityManagerContainer().get(clz); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<T> cq = cb.createQuery(clz); Root<T> root = cq.from(clz); Predicate p = cb.equal(root.get("categoryInfo"), categoryInfo.getId()); cq.select(root).where(p); List<T> os = em.createQuery(cq).getResultList(); for (T t : os) { em.detach(t); list.add(t); } /* 将object改为unmodifiable */ list = Collections.unmodifiableList(list); cache.put(new Element(cacheKey, list)); } return list; }
Example 19
Source File: QueryStatFactory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public QueryStat pick(String flag, Application application, ExceptionWhen exceptionWhen) throws Exception { Ehcache cache = ApplicationCache.instance().getCache(QueryStat.class); String cacheKey = flag + "#" + application.getId(); Element element = cache.get(cacheKey); QueryStat o = null; if (null != element) { if (null != element.getObjectValue()) { o = (QueryStat) element.getObjectValue(); } } else { EntityManager em = this.entityManagerContainer().get(QueryStat.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<QueryStat> cq = cb.createQuery(QueryStat.class); Root<QueryStat> root = cq.from(QueryStat.class); Predicate p = cb.equal(root.get(QueryStat_.application), application.getId()); p = cb.and(p, cb.or(cb.equal(root.get(QueryStat_.id), flag), cb.equal(root.get(QueryStat_.alias), flag), cb.equal(root.get(QueryStat_.name), flag))); cq.select(root).where(p); List<QueryStat> list = em.createQuery(cq).getResultList(); if (list.isEmpty()) { cache.put(new Element(cacheKey, o)); } else if (list.size() == 1) { o = list.get(0); em.detach(o); cache.put(new Element(cacheKey, o)); } else { throw new Exception("multiple queryStat with flag:" + flag + "."); } } if (o == null && Objects.equals(ExceptionWhen.not_found, exceptionWhen)) { throw new Exception("can not find queryStat with flag:" + flag + "."); } return o; }
Example 20
Source File: EhCacheFacade.java From cacheonix-core with GNU Lesser General Public License v2.1 | 3 votes |
/** * Stores the given object under the given key in the cache specified in the * given caching model. The caching model should be an instance of * <code>{@link EhCacheCachingModel}</code>. * * @param key the key of the cache entry * @param model the caching model * @param obj the object to store in the cache * @throws ObjectCannotBeCachedException if the object to store is not an implementation of * <code>java.io.Serializable</code>. * @throws CacheNotFoundException if the cache specified in the given model cannot be found. * @throws CacheAccessException wrapping any unexpected exception thrown by the cache. * @see AbstractCacheProviderFacade#onPutInCache(Serializable,CachingModel, *Object) */ protected void onPutInCache(Serializable key, CachingModel model, Object obj) throws CacheException { Ehcache cache = getCache(model); Element newCacheElement = new Element(key, (Serializable) obj); try { cache.put(newCacheElement); } catch (Exception exception) { throw new CacheAccessException(exception); } }