net.sf.ehcache.Element Java Examples

The following examples show how to use net.sf.ehcache.Element. 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: ActionListWithPersonSupNestedObject.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
		ActionResult<List<Wo>> result = new ActionResult<>();
		Business business = new Business(emc);
		String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(),
				StringUtils.join(wi.getPersonList(), ","));
		Element element = cache.get(cacheKey);
		if (null != element && (null != element.getObjectValue())) {
			result.setData((List<Wo>) element.getObjectValue());
		} else {
			List<Wo> wos = this.list(business, wi);
			cache.put(new Element(cacheKey, wos));
			result.setData(wos);
		}
		return result;
	}
}
 
Example #2
Source File: ActionListMajorWithPersonObject.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
		ActionResult<List<Wo>> result = new ActionResult<>();
		Business business = new Business(emc);
		String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(),
				StringUtils.join(wi.getPersonList(), ","));
		Element element = cache.get(cacheKey);
		if (null != element && (null != element.getObjectValue())) {
			result.setData((List<Wo>) element.getObjectValue());
		} else {
			List<Wo> wos = this.list(business, wi);
			cache.put(new Element(cacheKey, wos));
			result.setData(wos);
		}
		return result;
	}
}
 
Example #3
Source File: ActionListLoginRecent.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
		ActionResult<Wo> result = new ActionResult<>();
		Business business = new Business(emc);
		String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(), wi.getCount());
		Element element = cache.get(cacheKey);
		if (null != element && (null != element.getObjectValue())) {
			result.setData((Wo) element.getObjectValue());
		} else {
			Wo wo = this.list(business, wi);
			cache.put(new Element(cacheKey, wo));
			result.setData(wo);
		}
		return result;
	}
}
 
Example #4
Source File: ActionListSubNestedWithGroup.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String groupFlag) throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		ActionResult<List<Wo>> result = new ActionResult<>();
		Business business = new Business(emc);
		String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(), groupFlag);
		Element element = business.cache().get(cacheKey);
		if (null != element && (null != element.getObjectValue())) {
			result.setData((List<Wo>) element.getObjectValue());
		} else {
			List<Wo> wos = this.list(business, groupFlag);
			business.cache().put(new Element(cacheKey, wos));
			result.setData(wos);
		}
		this.updateControl(effectivePerson, business, result.getData());
		this.hide(effectivePerson, business, result.getData());
		return result;
	}
}
 
Example #5
Source File: ActionViewWithForum.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected ActionResult<List<Wo>> execute( HttpServletRequest request, EffectivePerson effectivePerson, String forumId ) throws Exception {
	ActionResult<List<Wo>> result = new ActionResult<>();
	Boolean check = true;
	Boolean isBBSManager = false;
	
	if ( check ) {
		isBBSManager = ThisApplication.isBBSManager(effectivePerson);
	}
	
	if( check ) {
		String cacheKey = getCacheKey( effectivePerson, isBBSManager, forumId );
		Element element = cache.get( cacheKey );
		
		if ((null != element) && (null != element.getObjectValue())) {
			ActionResult<List<Wo>> result_cache = (ActionResult<List<Wo>>) element.getObjectValue();
			result.setData( result_cache.getData() );
			result.setCount( result_cache.getCount() );
		} else {
			//继续进行数据查询
			result = getSectionQueryResult( request, effectivePerson, forumId, isBBSManager );
			cache.put(new Element( cacheKey, result ));
		}
	}		
	return result;		
}
 
Example #6
Source File: ActionGetSupDirect.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag) throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		ActionResult<Wo> result = new ActionResult<>();
		Business business = new Business(emc);
		String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(), flag);
		Element element = business.cache().get(cacheKey);
		if (null != element && (null != element.getObjectValue())) {
			result.setData((Wo) element.getObjectValue());
		} else {
			Wo wo = this.get(business, flag);
			business.cache().put(new Element(cacheKey, wo));
			result.setData(wo);
		}
		this.updateControl(effectivePerson, business, result.getData());
		return result;
	}
}
 
Example #7
Source File: ActionHtmlToWord.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
	ActionResult<Wo> result = new ActionResult<>();
	Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
	byte[] bytes = this.local(wi);
	HtmlToWordResultObject resultObject = new HtmlToWordResultObject();

	resultObject.setBytes(bytes);
	resultObject.setName(wi.getFileName());
	resultObject.setPerson(effectivePerson.getDistinguishedName());

	String flag = StringTools.uniqueToken();
	cache.put(new Element(flag, resultObject));
	Wo wo = new Wo();
	wo.setId(flag);
	result.setData(wo);
	return result;
}
 
Example #8
Source File: ActionListWithPerson.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
		ActionResult<Wo> result = new ActionResult<>();
		Business business = new Business(emc);
		String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(),
				StringUtils.join(wi.getPersonList(), ","));
		Element element = cache.get(cacheKey);
		if (null != element && (null != element.getObjectValue())) {
			result.setData((Wo) element.getObjectValue());
		} else {
			Wo wo = this.list(business, wi);
			cache.put(new Element(cacheKey, wo));
			result.setData(wo);
		}
		return result;
	}
}
 
Example #9
Source File: ActionListWithPersonWithUnit.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
		ActionResult<Wo> result = new ActionResult<>();
		Business business = new Business(emc);
		String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(),
				StringUtils.join(wi.getUnitList(), ","), StringUtils.join(wi.getPersonList(), ","));
		Element element = cache.get(cacheKey);
		if (null != element && (null != element.getObjectValue())) {
			result.setData((Wo) element.getObjectValue());
		} else {
			Wo wo = this.list(business, wi);
			cache.put(new Element(cacheKey, wo));
			result.setData(wo);
		}
		return result;
	}
}
 
Example #10
Source File: EhcacheCache.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Override
public V get(K key) {
    final Element element = cache.get(key);
    V value;
    if (element == null) {
        if (loader != null) {
            // trigger the cache loader on cache miss
            try {
                //noinspection unchecked
                value = (V) loader.load(key);
            } catch (Exception e1) {
                value = null;
                log.error("Cache loader failed trying to load (" + key + ") for cache (" + getName() + "), return value will be null:" + e1, e1);
            }
        } else {
            // convert to the null value when not found
            value = null;
        }
    } else {
        value = (V) element.getObjectValue();
        ArrayList<String> w = new ArrayList();
    }
    return value;
}
 
Example #11
Source File: ActionGet.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag) throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		Business business = new Business(emc);
		ActionResult<Wo> result = new ActionResult<>();
		String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(), flag);
		Element element = business.cache().get(cacheKey);
		if (null != element && (null != element.getObjectValue())) {
			result.setData((Wo) element.getObjectValue());
		} else {
			Wo wo = this.get(business, flag);
			business.cache().put(new Element(cacheKey, wo));
			result.setData(wo);
		}
		return result;
	}
}
 
Example #12
Source File: ActionListWithUnitDuty.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
		ActionResult<Wo> result = new ActionResult<>();
		Business business = new Business(emc);
		String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(), wi.getName() + "," + wi.getIdentity());
		Element element = cache.get(cacheKey);
		if (null != element && (null != element.getObjectValue())) {
			result.setData((Wo) element.getObjectValue());
		} else {
			Wo wo = this.list(business, wi);
			cache.put(new Element(cacheKey, wo));
			result.setData(wo);
		}
		return result;
	}
}
 
Example #13
Source File: ScriptFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public Script flagWithPortalObject(String flag, String portalId) throws Exception {
	String cacheKey = ApplicationCache.concreteCacheKey("flagObject", flag);
	Element element = scriptCache.get(cacheKey);
	if ((null != element) && (null != element.getObjectValue())) {
		return (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_.portal), portalId);
		p = cb.and(p, cb.or(cb.equal(root.get(Script_.name), flag), cb.equal(root.get(Script_.alias), flag)));
		List<Script> list = em.createQuery(cq.select(root).where(p)).setMaxResults(1).getResultList();
		if (list.isEmpty()) {
			return null;
		} else {
			Script o = list.get(0);
			em.detach(o);
			scriptCache.put(new Element(cacheKey, o));
			return o;
		}
	}
}
 
Example #14
Source File: RoleFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public Role pick(String flag) throws Exception {
	if (StringUtils.isEmpty(flag)) {
		return null;
	}
	Role o = null;
	Element element = cache.get(flag);
	if (null != element) {
		if (null != element.getObjectValue()) {
			o = (Role) element.getObjectValue();
		}
	} else {
		o = this.pickObject(flag);
		cache.put(new Element(flag, o));
	}
	return o;
}
 
Example #15
Source File: ActionListWithGroup.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
		ActionResult<Wo> result = new ActionResult<>();
		Business business = new Business(emc);
		String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(),
				StringUtils.join(wi.getGroupList(), ","));
		Element element = cache.get(cacheKey);
		if (null != element && (null != element.getObjectValue())) {
			result.setData((Wo) element.getObjectValue());
		} else {
			Wo wo = this.list(business, wi);
			cache.put(new Element(cacheKey, wo));
			result.setData(wo);
		}
		return result;
	}
}
 
Example #16
Source File: UnitFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public Unit pick(String flag) throws Exception {
	if (StringUtils.isEmpty(flag)) {
		return null;
	}
	Unit o = null;
	Element element = this.business.cache().get(flag);
	if (null != element) {
		if (null != element.getObjectValue()) {
			o = (Unit) element.getObjectValue();
		}
	} else {
		o = this.pickObject(flag);
		this.business.cache().put(new Element(flag, o));
	}
	return o;
}
 
Example #17
Source File: ActionListWithRole.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
		ActionResult<Wo> result = new ActionResult<>();
		Business business = new Business(emc);
		String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(),
				StringUtils.join(wi.getRoleList(), ","));
		Element element = cache.get(cacheKey);
		if (null != element && (null != element.getObjectValue())) {
			result.setData((Wo) element.getObjectValue());
		} else {
			Wo wo = this.list(business, wi);
			cache.put(new Element(cacheKey, wo));
			result.setData(wo);
		}
		return result;
	}
}
 
Example #18
Source File: ActionListPinyinInitial.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		ActionResult<List<Wo>> result = new ActionResult<>();
		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
		Business business = new Business(emc);
		String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(), wi.getKey(),
				StringUtils.join(wi.getUnitList(), ","));
		Element element = business.cache().get(cacheKey);
		if (null != element && (null != element.getObjectValue())) {
			result.setData((List<Wo>) element.getObjectValue());
		} else {
			List<Wo> wos = this.list(business, wi);
			business.cache().put(new Element(cacheKey, wos));
			result.setData(wos);
		}
		return result;
	}
}
 
Example #19
Source File: BounceProxyEhcacheAdapter.java    From joynr with Apache License 2.0 6 votes vote down vote up
@Override
public List<BounceProxyStatusInformation> getBounceProxyStatusInformation() {

    if (log.isTraceEnabled()) {
        log.trace("getBounceProxyStatusInformation from cache {}", cacheName);
        tracePeers();
    }

    List<BounceProxyStatusInformation> result = new LinkedList<BounceProxyStatusInformation>();

    Cache cache = manager.getCache(cacheName);
    @SuppressWarnings("rawtypes")
    List keys = cache.getKeys();
    Map<Object, Element> elements = cache.getAll(keys);

    for (Element element : elements.values()) {
        result.add(getBounceProxyRecordFromElement(element));
    }

    return result;
}
 
Example #20
Source File: ActionListWithPersonWithUnit.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
		ActionResult<Wo> result = new ActionResult<>();
		Business business = new Business(emc);
		String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(),
				StringUtils.join(wi.getUnitList(), ","), StringUtils.join(wi.getPersonList(), ","));
		Element element = cache.get(cacheKey);
		if (null != element && (null != element.getObjectValue())) {
			result.setData((Wo) element.getObjectValue());
		} else {
			Wo wo = this.list(business, wi);
			cache.put(new Element(cacheKey, wo));
			result.setData(wo);
		}
		return result;
	}
}
 
Example #21
Source File: ActionListLoginRecentObject.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
		ActionResult<List<Wo>> result = new ActionResult<>();
		Business business = new Business(emc);
		String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(), wi.getCount());
		Element element = cache.get(cacheKey);
		if (null != element && (null != element.getObjectValue())) {
			result.setData((List<Wo>) element.getObjectValue());
		} else {
			List<Wo> wos = this.list(business, wi);
			cache.put(new Element(cacheKey, wos));
			result.setData(wos);
		}
		return result;
	}
}
 
Example #22
Source File: AbstractFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
@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 #23
Source File: ActionListLoginAfter.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
		ActionResult<Wo> result = new ActionResult<>();
		Business business = new Business(emc);
		String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(), DateTools.format(wi.getDate()));
		Element element = cache.get(cacheKey);
		if (null != element && (null != element.getObjectValue())) {
			result.setData((Wo) element.getObjectValue());
		} else {
			Wo wo = this.list(business, wi);
			cache.put(new Element(cacheKey, wo));
			result.setData(wo);
		}
		return result;
	}
}
 
Example #24
Source File: ActionListNameWithIdentity.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
		ActionResult<Wo> result = new ActionResult<>();
		Business business = new Business(emc);
		String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(),
				StringUtils.join(wi.getIdentityList(), ","));
		Element element = cache.get(cacheKey);
		if (null != element && (null != element.getObjectValue())) {
			result.setData((Wo) element.getObjectValue());
		} else {
			Wo wo = this.list(business, wi);
			cache.put(new Element(cacheKey, wo));
			result.setData(wo);
		}
		return result;
	}
}
 
Example #25
Source File: QueryFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public List<Query> pick(List<String> flags) throws Exception {
	List<Query> list = new ArrayList<>();
	for (String str : flags) {
		Element element = cache.get(str);
		if (null != element) {
			if (null != element.getObjectValue()) {
				list.add((Query) element.getObjectValue());
			}
		} else {
			Query o = this.pickObject(str);
			cache.put(new Element(str, o));
			if (null != o) {
				list.add(o);
			}
		}
	}
	return list;
}
 
Example #26
Source File: QueryFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public Query pick(String flag) throws Exception {
	if (StringUtils.isEmpty(flag)) {
		return null;
	}
	Query o = null;
	Element element = cache.get(flag);
	if (null != element) {
		if (null != element.getObjectValue()) {
			o = (Query) element.getObjectValue();
		}
	} else {
		o = this.pickObject(flag);
		cache.put(new Element(flag, o));
	}
	return o;
}
 
Example #27
Source File: ActionListAllObject.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson) throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		ActionResult<List<Wo>> result = new ActionResult<>();
		Business business = new Business(emc);
		String cacheKey = ApplicationCache.concreteCacheKey(this.getClass());
		Element element = cache.get(cacheKey);
		if (null != element && (null != element.getObjectValue())) {
			result.setData((List<Wo>) element.getObjectValue());
		} else {
			List<Wo> wos = this.list(business);
			cache.put(new Element(cacheKey, wos));
			result.setData(wos);
		}
		return result;
	}
}
 
Example #28
Source File: GenericDaoBase.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@DB()
protected T toEntityBean(final ResultSet result, final boolean cache) throws SQLException {
    final T entity = (T)_factory.newInstance(new Callback[] {NoOp.INSTANCE, new UpdateBuilder(this)});

    toEntityBean(result, entity);

    if (cache && _cache != null) {
        try {
            _cache.put(new Element(_idField.get(entity), entity));
        } catch (final Exception e) {
            s_logger.debug("Can't put it in the cache", e);
        }
    }

    return entity;
}
 
Example #29
Source File: ActionGetWithIdentityWithLevelObject.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/*** 查找指定身份所在的递归群组,并返回指定level的那个群组 */
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		ActionResult<Wo> result = new ActionResult<>();
		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
		Business business = new Business(emc);
		String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(), wi.getIdentity(), wi.getLevel());
		Element element = cache.get(cacheKey);
		if (null != element && (null != element.getObjectValue())) {
			result.setData((Wo) element.getObjectValue());
		} else {
			Wo wo = this.get(effectivePerson, business, wi);
			cache.put(new Element(cacheKey, wo));
			result.setData(wo);
		}
		return result;
	}
}
 
Example #30
Source File: ScriptFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public Script flagWithPortalObject(String flag, String portalId) throws Exception {
	String cacheKey = ApplicationCache.concreteCacheKey("flagObject", flag);
	Element element = scriptCache.get(cacheKey);
	if ((null != element) && (null != element.getObjectValue())) {
		return (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_.portal), portalId);
		p = cb.and(p, cb.or(cb.equal(root.get(Script_.name), flag), cb.equal(root.get(Script_.alias), flag)));
		List<Script> list = em.createQuery(cq.select(root).where(p)).setMaxResults(1).getResultList();
		if (list.isEmpty()) {
			return null;
		} else {
			Script o = list.get(0);
			em.detach(o);
			scriptCache.put(new Element(cacheKey, o));
			return o;
		}
	}
}