use of lucee.runtime.listener.ApplicationContext in project Lucee by lucee.
the class ScopeContext method getCFSessionScope.
/**
* return cf session scope
*
* @param pc PageContext
* @param isNew
* @return cf session matching the context
* @throws PageException
*/
private Session getCFSessionScope(PageContext pc, RefBoolean isNew) throws PageException {
ApplicationContext appContext = pc.getApplicationContext();
// get Context
Map<String, Scope> context = getSubMap(cfSessionContexts, appContext.getName());
// get Session
boolean isMemory = false;
String storage = appContext.getSessionstorage();
if (StringUtil.isEmpty(storage, true)) {
storage = ConfigImpl.DEFAULT_STORAGE_SESSION;
isMemory = true;
} else if ("ram".equalsIgnoreCase(storage)) {
storage = "memory";
isMemory = true;
} else if ("registry".equalsIgnoreCase(storage)) {
storage = "file";
} else {
storage = storage.toLowerCase();
if ("memory".equals(storage))
isMemory = true;
}
Session existing = (Session) context.get(pc.getCFID());
if (existing != null && (existing.isExpired() || !(existing instanceof StorageScope)))
// second should not happen
existing = null;
Session session = appContext.getSessionCluster() ? null : existing;
if (session == null || !(session instanceof StorageScope) || !((StorageScope) session).getStorage().equalsIgnoreCase(storage)) {
// not necessary to check session in the same way, because it is overwritten anyway
if (isMemory) {
if (existing != null)
session = existing;
else
session = SessionMemory.getInstance(pc, isNew, getLog());
} else if ("file".equals(storage)) {
session = SessionFile.getInstance(appContext.getName(), pc, getLog());
} else if ("cookie".equals(storage))
session = SessionCookie.getInstance(appContext.getName(), pc, getLog());
else {
DataSource ds = pc.getDataSource(storage, null);
if (ds != null && ds.isStorage()) {
if (INVIDUAL_STORAGE_KEYS) {
try {
session = (Session) IKStorageScopeSupport.getInstance(Scope.SCOPE_SESSION, new IKHandlerDatasource(), appContext.getName(), storage, pc, existing, getLog());
} catch (PageException pe) {
session = SessionDatasource.getInstance(storage, pc, getLog(), null);
}
} else
session = SessionDatasource.getInstance(storage, pc, getLog(), null);
} else {
if (INVIDUAL_STORAGE_KEYS) {
try {
session = (Session) IKStorageScopeSupport.getInstance(Scope.SCOPE_SESSION, new IKHandlerCache(), appContext.getName(), storage, pc, existing, getLog());
} catch (PageException pe) {
session = SessionCache.getInstance(storage, appContext.getName(), pc, existing, getLog(), null);
}
} else
session = SessionCache.getInstance(storage, appContext.getName(), pc, existing, getLog(), null);
}
if (session == null) {
// datasource not enabled for storage
if (ds != null)
throw new ApplicationException("datasource [" + storage + "] is not enabled to be used as session/client storage, " + "you have to enable it in the Lucee administrator or define key \"storage=true\" for datasources defined in the application event handler.");
CacheConnection cc = CacheUtil.getCacheConnection(pc, storage, null);
if (cc != null)
throw new ApplicationException("cache [" + storage + "] is not enabled to be used as a session/client storage, you have to enable it in the Lucee administrator.");
throw new ApplicationException("there is no cache or datasource with name [" + storage + "] defined.");
}
}
if (session instanceof StorageScope)
((StorageScope) session).setStorage(storage);
context.put(pc.getCFID(), session);
isNew.setValue(true);
} else {
getLog().log(Log.LEVEL_INFO, "scope-context", "use existing session scope for " + appContext.getName() + "/" + pc.getCFID() + " from storage " + storage);
}
session.touchBeforeRequest(pc);
return session;
}
use of lucee.runtime.listener.ApplicationContext in project Lucee by lucee.
the class IKStorageScopeSupport method setTimeSpan.
void setTimeSpan(PageContext pc) {
ApplicationContext ac = pc.getApplicationContext();
this.timeSpan = getType() == SCOPE_SESSION ? ac.getSessionTimeout().getMillis() : ac.getClientTimeout().getMillis();
}
use of lucee.runtime.listener.ApplicationContext in project Lucee by lucee.
the class StorageScopeImpl method setTimeSpan.
void setTimeSpan(PageContext pc) {
ApplicationContext ac = pc.getApplicationContext();
this.timeSpan = getType() == SCOPE_SESSION ? ac.getSessionTimeout().getMillis() : ac.getClientTimeout().getMillis();
}
use of lucee.runtime.listener.ApplicationContext in project Lucee by lucee.
the class _GetElement method hash.
@Override
public String hash() {
ApplicationContext _ac = ac;
if (_ac == null)
_ac = ThreadLocalPageContext.get().getApplicationContext();
Object ds = _ac.getORMDataSource();
String data = autogenmap + ":" + catalog + ":" + isDefaultCfcLocation + ":" + dbCreate + ":" + dialect + ":" + eventHandling + ":" + namingStrategy + ":" + eventHandler + ":" + flushAtRequestEnd + ":" + logSQL + ":" + autoManageSession + ":" + skipCFCWithError + ":" + saveMapping + ":" + schema + ":" + secondaryCacheEnabled + ":" + useDBForMapping + ":" + cacheProvider + "datasource:" + ds + ":" + toStr(cfcLocations) + ":" + toStr(sqlScript) + ":" + toStr(cacheConfig) + ":" + toStr(ormConfig);
try {
return MD5.getDigestAsString(data);
} catch (IOException e) {
return null;
}
}
use of lucee.runtime.listener.ApplicationContext in project Lucee by lucee.
the class UDFRemoveProperty method remove.
private boolean remove(PageContext pageContext, Object value) throws PageException {
Object propValue = component.getComponentScope().get(propName, null);
value = cast(pageContext, arguments[0], value, 1);
// make sure it is reconized that set is called by hibernate
// if(component.isPersistent())ORMUtil.getSession(pageContext);
ApplicationContext appContext = pageContext.getApplicationContext();
if (appContext.isORMEnabled() && component.isPersistent())
ORMUtil.getSession(pageContext);
// struct
if (isStruct()) {
String strKey = Caster.toString(value, null);
if (strKey == null)
return false;
if (propValue instanceof Struct) {
return ((Struct) propValue).removeEL(KeyImpl.getInstance(strKey)) != null;
} else if (propValue instanceof Map) {
return ((Map) propValue).remove(strKey) != null;
}
return false;
}
Object o;
boolean has = false;
if (propValue instanceof Array) {
Array arr = ((Array) propValue);
Key[] keys = CollectionUtil.keys(arr);
for (int i = 0; i < keys.length; i++) {
o = arr.get(keys[i], null);
if (ORMUtil.equals(value, o)) {
arr.removeEL(keys[i]);
has = true;
}
}
} else if (propValue instanceof java.util.List) {
Iterator it = ((java.util.List) propValue).iterator();
while (it.hasNext()) {
o = it.next();
if (ORMUtil.equals(value, o)) {
it.remove();
has = true;
}
}
}
return has;
}
Aggregations