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;
}
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;
}
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);
}
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);
}
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;
}
Aggregations