Search in sources :

Example 1 with ORMSession

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

the class EntityDelete method call.

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

Example 2 with ORMSession

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

the class EntityNew method call.

public static Object call(PageContext pc, String name, Struct properties) throws PageException {
    ORMSession session = ORMUtil.getSession(pc);
    if (properties == null)
        return session.create(pc, name);
    Component entity = session.create(pc, name);
    setPropeties(pc, entity, properties, false);
    return entity;
}
Also used : ORMSession(lucee.runtime.orm.ORMSession) Component(lucee.runtime.Component)

Example 3 with ORMSession

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

the class Query method _call.

public static Object _call(PageContext pc, String hql, Object params, boolean unique, Struct queryOptions) throws PageException {
    ORMSession session = ORMUtil.getSession(pc);
    String dsn = Caster.toString(queryOptions.get(KeyConstants._datasource, null), null);
    if (StringUtil.isEmpty(dsn, true))
        dsn = ORMUtil.getDefaultDataSource(pc).getName();
    if (Decision.isCastableToArray(params))
        return session.executeQuery(pc, dsn, hql, Caster.toArray(params), unique, queryOptions);
    else if (Decision.isCastableToStruct(params))
        return session.executeQuery(pc, dsn, hql, Caster.toStruct(params), unique, queryOptions);
    else
        return session.executeQuery(pc, dsn, hql, (Array) params, unique, queryOptions);
}
Also used : ORMSession(lucee.runtime.orm.ORMSession)

Example 4 with ORMSession

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

the class Query method executeORM.

private Object executeORM(SQL sql, int returnType, Struct ormoptions) throws PageException {
    ORMSession session = ORMUtil.getSession(pageContext);
    if (ormoptions == null)
        ormoptions = new StructImpl();
    String dsn = null;
    if (ormoptions != null)
        dsn = Caster.toString(ormoptions.get(KeyConstants._datasource, null), null);
    if (StringUtil.isEmpty(dsn, true))
        dsn = ORMUtil.getDefaultDataSource(pageContext).getName();
    // params
    SQLItem[] _items = sql.getItems();
    Array params = new ArrayImpl();
    for (int i = 0; i < _items.length; i++) {
        params.appendEL(_items[i]);
    }
    // query options
    if (maxrows != -1 && !ormoptions.containsKey(MAX_RESULTS))
        ormoptions.setEL(MAX_RESULTS, new Double(maxrows));
    if (timeout != null && ((int) timeout.getSeconds()) > 0 && !ormoptions.containsKey(TIMEOUT))
        ormoptions.setEL(TIMEOUT, new Double(timeout.getSeconds()));
    /*
		 * MUST offset: Specifies the start index of the resultset from where it has to start the retrieval. cacheable: Whether the result of this query is to
		 * be cached in the secondary cache. Default is false. cachename: Name of the cache in secondary cache.
		 */
    Object res = session.executeQuery(pageContext, dsn, sql.getSQLString(), params, unique, ormoptions);
    if (returnType == RETURN_TYPE_ARRAY || returnType == RETURN_TYPE_UNDEFINED)
        return res;
    return session.toQuery(pageContext, res, null);
}
Also used : Array(lucee.runtime.type.Array) QueryArray(lucee.runtime.type.query.QueryArray) StructImpl(lucee.runtime.type.StructImpl) ORMSession(lucee.runtime.orm.ORMSession) ArrayImpl(lucee.runtime.type.ArrayImpl) SQLItem(lucee.runtime.db.SQLItem)

Example 5 with ORMSession

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

the class EntityReload method call.

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

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