Search in sources :

Example 21 with ApplicationContext

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;
}
Also used : StorageScope(lucee.runtime.type.scope.storage.StorageScope) PageException(lucee.runtime.exp.PageException) DataSource(lucee.runtime.db.DataSource) IKHandlerDatasource(lucee.runtime.type.scope.storage.IKHandlerDatasource) ApplicationContext(lucee.runtime.listener.ApplicationContext) ApplicationException(lucee.runtime.exp.ApplicationException) StorageScope(lucee.runtime.type.scope.storage.StorageScope) MemoryScope(lucee.runtime.type.scope.storage.MemoryScope) CacheConnection(lucee.runtime.cache.CacheConnection) IKHandlerCache(lucee.runtime.type.scope.storage.IKHandlerCache) HttpSession(javax.servlet.http.HttpSession)

Example 22 with ApplicationContext

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();
}
Also used : ApplicationContext(lucee.runtime.listener.ApplicationContext)

Example 23 with ApplicationContext

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();
}
Also used : ApplicationContext(lucee.runtime.listener.ApplicationContext)

Example 24 with ApplicationContext

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;
    }
}
Also used : ApplicationContext(lucee.runtime.listener.ApplicationContext) IOException(java.io.IOException)

Example 25 with ApplicationContext

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;
}
Also used : ApplicationContext(lucee.runtime.listener.ApplicationContext) Iterator(java.util.Iterator) Map(java.util.Map) Key(lucee.runtime.type.Collection.Key)

Aggregations

ApplicationContext (lucee.runtime.listener.ApplicationContext)28 MemoryScope (lucee.runtime.type.scope.storage.MemoryScope)10 StorageScope (lucee.runtime.type.scope.storage.StorageScope)10 HttpSession (javax.servlet.http.HttpSession)6 DataSource (lucee.runtime.db.DataSource)4 ApplicationContextSupport (lucee.runtime.listener.ApplicationContextSupport)4 Key (lucee.runtime.type.Collection.Key)4 CacheConnection (lucee.runtime.cache.CacheConnection)3 ExpressionException (lucee.runtime.exp.ExpressionException)3 PageException (lucee.runtime.exp.PageException)3 TimeSpan (lucee.runtime.type.dt.TimeSpan)3 IKHandlerCache (lucee.runtime.type.scope.storage.IKHandlerCache)3 IKHandlerDatasource (lucee.runtime.type.scope.storage.IKHandlerDatasource)3 IOException (java.io.IOException)2 Map (java.util.Map)2 Resource (lucee.commons.io.res.Resource)2 RefBooleanImpl (lucee.commons.lang.types.RefBooleanImpl)2 ApplicationException (lucee.runtime.exp.ApplicationException)2 ClassicApplicationContext (lucee.runtime.listener.ClassicApplicationContext)2 ModernApplicationContext (lucee.runtime.listener.ModernApplicationContext)2