Search in sources :

Example 6 with ORMSession

use of lucee.runtime.orm.ORMSession in project Lucee by lucee.

the class EntitySave method call.

public static String call(PageContext pc, Object obj, boolean forceInsert) throws PageException {
    ORMSession session = ORMUtil.getSession(pc);
    session.save(pc, obj, forceInsert);
    return null;
}
Also used : ORMSession(lucee.runtime.orm.ORMSession)

Example 7 with ORMSession

use of lucee.runtime.orm.ORMSession in project Lucee by lucee.

the class ORMExecuteQuery method _call.

private static Object _call(PageContext pc, String hql, Object params, boolean unique, Struct queryOptions) throws PageException {
    ORMSession session = ORMUtil.getSession(pc);
    String dsn = null;
    if (queryOptions != null)
        dsn = Caster.toString(queryOptions.get(KeyConstants._datasource, null), null);
    if (StringUtil.isEmpty(dsn, true))
        dsn = ORMUtil.getDefaultDataSource(pc).getName();
    if (params == null)
        return toCFML(session.executeQuery(pc, dsn, hql, new ArrayImpl(), unique, queryOptions));
    else if (Decision.isStruct(params))
        return toCFML(session.executeQuery(pc, dsn, hql, Caster.toStruct(params), unique, queryOptions));
    else if (Decision.isArray(params))
        return toCFML(session.executeQuery(pc, dsn, hql, Caster.toArray(params), unique, queryOptions));
    else if (Decision.isCastableToStruct(params))
        return toCFML(session.executeQuery(pc, dsn, hql, Caster.toStruct(params), unique, queryOptions));
    else if (Decision.isCastableToArray(params))
        return toCFML(session.executeQuery(pc, dsn, hql, Caster.toArray(params), unique, queryOptions));
    else
        throw new FunctionException(pc, "ORMExecuteQuery", 2, "params", "cannot convert the params to a array or a struct");
}
Also used : ORMSession(lucee.runtime.orm.ORMSession) ArrayImpl(lucee.runtime.type.ArrayImpl) FunctionException(lucee.runtime.exp.FunctionException)

Example 8 with ORMSession

use of lucee.runtime.orm.ORMSession in project Lucee by lucee.

the class ORMReload method call.

public static String call(PageContext pc) throws PageException {
    // flush and close session
    ORMSession session = ORMUtil.getSession(pc, false);
    if (session != null) {
        // MUST do the same with all sesson using the same engine
        ORMConfiguration config = session.getEngine().getConfiguration(pc);
        if (config.autoManageSession()) {
            session.flushAll(pc);
            session.closeAll(pc);
        }
    }
    pc.getApplicationContext().reinitORM(pc);
    ORMUtil.resetEngine(pc, true);
    return null;
}
Also used : ORMSession(lucee.runtime.orm.ORMSession) ORMConfiguration(lucee.runtime.orm.ORMConfiguration)

Aggregations

ORMSession (lucee.runtime.orm.ORMSession)8 ArrayImpl (lucee.runtime.type.ArrayImpl)2 Component (lucee.runtime.Component)1 SQLItem (lucee.runtime.db.SQLItem)1 FunctionException (lucee.runtime.exp.FunctionException)1 ORMConfiguration (lucee.runtime.orm.ORMConfiguration)1 Array (lucee.runtime.type.Array)1 StructImpl (lucee.runtime.type.StructImpl)1 QueryArray (lucee.runtime.type.query.QueryArray)1