Java Code Examples for net.sf.ehcache.Element#getObjectValue()

The following examples show how to use net.sf.ehcache.Element#getObjectValue() . 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: PersonAttributeFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public List<PersonAttribute> pick(List<String> flags) throws Exception {
	List<PersonAttribute> list = new ArrayList<>();
	for (String str : flags) {
		Element element = this.business.cache().get(str);
		if (null != element) {
			if (null != element.getObjectValue()) {
				list.add((PersonAttribute) element.getObjectValue());
			}
		} else {
			PersonAttribute o = this.pickObject(str);
			this.business.cache().put(new Element(str, o));
			if (null != o) {
				list.add(o);
			}
		}
	}
	return list;
}
 
Example 2
Source File: ActionListWithUnitSubNestedObject.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.getUnitList(), ","));
		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: OkrUserInfoService.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 获取用户登录的代理身份
 * 
 * 先从缓存里取信息,如果没有再从数据库中获取信息
 * 
 * @param name
 * @throws Exception 
 */
public OkrUserInfo getOkrUserInfoWithPersonName(String name) throws Exception {
	if( name  == null || name.isEmpty() ){
		throw new Exception( "name is null, return null!" );
	}
	String cacheKey = ThisApplication.getOkrUserInfoCacheKey( name );
	Element element = cache.get( cacheKey );
	OkrUserInfo okrUserInfo  = null;
	if( element != null ) {
		okrUserInfo = (OkrUserInfo)element.getObjectValue();
	}else {
		okrUserInfo  = getWithPersonName( name );
		cache.put( new Element( cacheKey, okrUserInfo ) );
	}
	return okrUserInfo;
}
 
Example 4
Source File: ActionListTop.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 = business.cache().get(cacheKey);
		if (null != element && (null != element.getObjectValue())) {
			result.setData((List<Wo>) element.getObjectValue());
		} else {
			List<Wo> wos = this.list(business);
			business.cache().put(new Element(cacheKey, wos));
			result.setData(wos);
		}
		this.updateControl(effectivePerson, business, result.getData());
		return result;
	}
}
 
Example 5
Source File: EhCacheCache.java    From java-technology-stack with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
@Nullable
public <T> T get(Object key, Callable<T> valueLoader) {
	Element element = lookup(key);
	if (element != null) {
		return (T) element.getObjectValue();
	}
	else {
		this.cache.acquireWriteLockOnKey(key);
		try {
			element = lookup(key);  // one more attempt with the write lock
			if (element != null) {
				return (T) element.getObjectValue();
			}
			else {
				return loadValue(key, valueLoader);
			}
		}
		finally {
			this.cache.releaseWriteLockOnKey(key);
		}
	}

}
 
Example 6
Source File: ActionGetWithIdentityWithType.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.getType());
		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 7
Source File: IdentityFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public Identity pick(String flag) throws Exception {
	if (StringUtils.isEmpty(flag)) {
		return null;
	}
	Identity o = null;
	Element element = cache.get(flag);
	if (null != element) {
		if (null != element.getObjectValue()) {
			o = (Identity) element.getObjectValue();
		}
	} else {
		o = this.pickObject(flag);
		cache.put(new Element(flag, o));
	}
	return o;
}
 
Example 8
Source File: ActionListWithGroupSupNestedObject.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.getGroupList(), ","));
		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 9
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 10
Source File: ActionListSupNested.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String key) 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(), key);
		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, key);
			business.cache().put(new Element(cacheKey, wos));
			result.setData(wos);
		}
		this.updateControl(effectivePerson, business, result.getData());
		return result;
	}
}
 
Example 11
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 12
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 13
Source File: AcademicSessionLogicImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private HashSet<String> getCurrentSessionEIDsFromCache() {
	Element element = cache.get(CACHE_KEY_CURRENTS);
	if (element != null) {
		log.debug("Getting list of current sessions from cache");
		@SuppressWarnings("unchecked")
		HashSet<String> objectValue = (HashSet<String>) element.getObjectValue();
		return objectValue;
	}
	else {
		return null;
	}

}
 
Example 14
Source File: ActionOutputFile.java    From o2oa with GNU Affero General Public License v3.0 5 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<>();
		Wo wo = null;
		Element element = cache.get(flag);
		if (null != element && null != element.getObjectValue()) {
			CacheObject cacheObject = (CacheObject) element.getObjectValue();
			WrapModule module = cacheObject.getModule();
			wo = new Wo(gson.toJson(module).getBytes(DefaultCharset.name),
					this.contentType(true, module.getName() +"."+ Structure.default_extension),
					this.contentDisposition(true, module.getName() +"."+ Structure.default_extension));
		} else {
			Structure structure = emc.find(flag, Structure.class);
			if(structure != null){
				StorageMapping mapping = ThisApplication.context().storageMappings().get(Structure.class,
						structure.getStorage());
				if (null == mapping) {
					throw new ExceptionStorageNotExist(structure.getStorage());
				}
				try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
					structure.readContent(mapping, os);
					byte[] bs = os.toByteArray();
					wo = new Wo(bs, this.contentType(true, structure.getName() +"."+ Structure.default_extension),
							this.contentDisposition(true, structure.getName() +"."+ Structure.default_extension));
				}
			}
		}
		result.setData(wo);
		return result;
	}
}
 
Example 15
Source File: EhCacheCache.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
@Nullable
public <T> T get(Object key, @Nullable Class<T> type) {
	Element element = this.cache.get(key);
	Object value = (element != null ? element.getObjectValue() : null);
	if (value != null && type != null && !type.isInstance(value)) {
		throw new IllegalStateException(
				"Cached value is not of required type [" + type.getName() + "]: " + value);
	}
	return (T) value;
}
 
Example 16
Source File: EhCacheCache.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> T get(Object key, Class<T> type) {
	Element element = this.cache.get(key);
	Object value = (element != null ? element.getObjectValue() : null);
	if (value != null && type != null && !type.isInstance(value)) {
		throw new IllegalStateException("Cached value is not of required type [" + type.getName() + "]: " + value);
	}
	return (T) value;
}
 
Example 17
Source File: ActionListIdentityWithUnitWithName.java    From o2oa with GNU Affero General Public License v3.0 5 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);
		List<String> names = new ArrayList<>();
		List<String> units = new ArrayList<>();
		if (StringUtils.isNotEmpty(wi.getName())) {
			names.add(wi.getName());
		}
		if (ListTools.isNotEmpty(wi.getNameList())) {
			names.addAll(wi.getNameList());
		}
		if (StringUtils.isNotEmpty(wi.getUnit())) {
			units.add(wi.getUnit());
		}
		if (ListTools.isNotEmpty(wi.getUnitList())) {
			units.addAll(wi.getUnitList());
		}
		names = ListTools.trim(names, true, true);
		units = ListTools.trim(units, true, true);
		String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(), ListTools.toStringJoin(names, ","),
				ListTools.toStringJoin(units, ","));
		Element element = cache.get(cacheKey);
		if (null != element && (null != element.getObjectValue())) {
			result.setData((Wo) element.getObjectValue());
		} else {
			Wo wo = this.list(business, names, units);
			cache.put(new Element(cacheKey, wo));
			result.setData(wo);
		}
		return result;
	}
}
 
Example 18
Source File: AcademicSessionLogicImpl.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
@Override
public Semester getSemester(String eid) {
	log.debug("get for eid: {}", eid);
	// check cache
	synchronized (cache) { // getSemesters() might be updating the cache at the same time..
		Element element = cache.get(eid);
		if (element != null) {
			log.debug("cache hit for {}", eid);
			return (Semester) element.getObjectValue();
		}
	}
	// Usually, getSemesters() will be called first by the Wicket tool and this call will have added 
	// all semesters to the cache, so right now it's unlikely that the following code will ever be executed.
	// (Though, in theory, a Semester's cache entry could expire between being created by a call to getSemesters()
	// and this call to getSemester(eid) which we're currently processing.)
	
	log.debug("cache fail for {}", eid);
	AcademicSession t = cmService.getAcademicSession(eid);
	if (t != null) {
		Semester sem = Semester.createFromAcademicSession(t);
		HashSet<String> currentEids = getCurrentSessionEIDs();
		if (currentEids != null && currentEids.contains(eid)) {
			sem.setCurrent(true);
		}
		log.debug("Adding item to cache for: {}", eid);
		synchronized (cache) {
			// It's theoretically possible that the above cache lookup failed because the Semester's cache entry has
			// expired.
			// PROBLEM: the list of all Semesters might still be cached and already (still) contain a Semester
			// object with the same EID.
			// => If we simply put our freshly created "sem" into the cache, we'll have two different semester
			// objects for the same ID: the one we just created and the one in the list returned by getSemesters()
			Element cachedList = cache.get(CACHE_KEY_LIST);
			if (cachedList == null) {
				// no cached list yet => we can cache our object and let getSemesters() worry
				// about keeping everything in sync
				cache.put(new Element(eid, sem));
			}
			else { // problem case as described above: WAT DO? Two ideas:
					// a) look up the Semester object with the matching EID in the list, update it and then cache
					//    the old, but updated Semester object instead of the one we created above
					// b) simply toss the cached list out of the cache and let getSemesters() create a new one the
					//    next time it's called
				//
				// Lets do a)
				@SuppressWarnings("unchecked")
				List<Semester> semList = (List<Semester>) cachedList.getObjectValue();
				// lets look for the old Semester in O(n)..
				boolean foundIt = false;
				for (Semester semester : semList) {
					if (eid.equals(semester.getEid())) {
						log.debug("No new, fix old! -> updating and caching the old object");
						try {
							BeanUtils.copyProperties(semester, sem);
						} catch (IllegalAccessException | InvocationTargetException e) {
							// TODO Auto-generated catch block
							log.warn("Could not copy properties", e);
						}
						cache.put(new Element(eid, semester));
						foundIt = true;
						break;
					}
				}
				if (!foundIt) { // not sure if that can actually happen, but lets play it safe and just add it
					log.debug("didn't find the old instance -> adding and caching the new object");
					semList.add(sem);
					cache.put(new Element(eid, sem));
				}
				// What b) might look like: 
				// cache.put(new Element(eid,sem));
				// cache.remove(CACHE_KEY_LIST);
				// ..well, it certainly beats a) on simplicity. 
			}
		}

		return sem;
	}
	else {
		log.debug("didnt find eid {} in the database", eid);
		return null;
	}

}
 
Example 19
Source File: DomainAccessControlStoreEhCache.java    From joynr with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> T getElementValue(Element e) {
    return (T) e.getObjectValue();
}
 
Example 20
Source File: GeneralDecryptorThread.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private KeyResult getKey(String encryptionKeyId) {
   LOG.info("GET KEY FROM CACHE FOR ID: " + encryptionKeyId);
   Element tmpKey = this.kgssCache.get((Serializable)encryptionKeyId);
   return tmpKey != null ? (KeyResult)tmpKey.getObjectValue() : null;
}