use of lucee.commons.lang.Pair in project Lucee by lucee.
the class DatasourceManagerImpl method end.
public void end(boolean onlyORM) {
autoCommit = true;
Pair<DatasourceConnection, Exception> pair = null;
if (transConns.size() > 0) {
Map<DataSource, DatasourceConnection> tmp = null;
if (onlyORM)
tmp = new HashMap<DataSource, DatasourceConnection>();
Iterator<Entry<DataSource, DatasourceConnection>> it = this.transConns.entrySet().iterator();
DatasourceConnection dc;
Entry<DataSource, DatasourceConnection> entry;
while (it.hasNext()) {
entry = it.next();
dc = entry.getValue();
try {
if (onlyORM && !(dc.getConnection() instanceof ORMConnection)) {
tmp.put(entry.getKey(), entry.getValue());
continue;
}
dc.getConnection().setAutoCommit(true);
} catch (Exception e) {
// we only keep the first exception
if (pair == null) {
pair = new Pair<DatasourceConnection, Exception>(dc, e);
}
}
releaseConnection(null, dc);
}
transConns.clear();
if (onlyORM)
transConns = tmp;
}
this.isolation = Connection.TRANSACTION_NONE;
if (pair != null) {
if (pair.getValue() instanceof SQLException) {
throw new PageRuntimeException(new DatabaseException((SQLException) pair.getValue(), pair.getName()));
}
throw new PageRuntimeException(pair.getValue());
}
}
use of lucee.commons.lang.Pair in project Lucee by lucee.
the class DatasourceManagerImpl method savepoint.
@Override
public void savepoint() throws DatabaseException {
if (autoCommit || transConns.size() == 0)
return;
Iterator<DatasourceConnection> it = this.transConns.values().iterator();
DatasourceConnection dc = null;
Pair<DatasourceConnection, Exception> pair = null;
while (it.hasNext()) {
dc = it.next();
try {
dc.getConnection().setSavepoint();
} catch (Exception e) {
// we only keep the first exception
if (pair == null) {
pair = new Pair<DatasourceConnection, Exception>(dc, e);
}
}
}
if (pair != null) {
if (pair.getValue() instanceof SQLException) {
throw new DatabaseException((SQLException) pair.getValue(), pair.getName());
}
throw new PageRuntimeException(pair.getValue());
}
}
use of lucee.commons.lang.Pair in project Lucee by lucee.
the class Filter method _call.
public static Collection _call(PageContext pc, Object obj, UDF udf, boolean parallel, int maxThreads, short type) throws PageException {
ExecutorService execute = null;
List<Future<Data<Pair<Object, Object>>>> futures = null;
if (parallel) {
execute = Executors.newFixedThreadPool(maxThreads);
futures = new ArrayList<Future<Data<Pair<Object, Object>>>>();
}
Collection coll;
// Array
if (type == TYPE_ARRAY) {
coll = invoke(pc, (Array) obj, udf, execute, futures);
} else // Query
if (type == TYPE_QUERY) {
coll = invoke(pc, (Query) obj, udf, execute, futures);
} else // Struct
if (type == TYPE_STRUCT) {
coll = invoke(pc, (Struct) obj, udf, execute, futures);
} else // Array
if (obj instanceof Array) {
coll = invoke(pc, (Array) obj, udf, execute, futures);
} else // Query
if (obj instanceof Query) {
coll = invoke(pc, (Query) obj, udf, execute, futures);
} else // Struct
if (obj instanceof Struct) {
coll = invoke(pc, (Struct) obj, udf, execute, futures);
} else // other Iteratorable
if (obj instanceof Iteratorable) {
coll = invoke(pc, (Iteratorable) obj, udf, execute, futures);
} else // Map
if (obj instanceof java.util.Map) {
coll = invoke(pc, (java.util.Map) obj, udf, execute, futures);
} else // List
if (obj instanceof List) {
coll = invoke(pc, (List) obj, udf, execute, futures);
} else // Iterator
if (obj instanceof Iterator) {
coll = invoke(pc, (Iterator) obj, udf, execute, futures);
} else // Enumeration
if (obj instanceof Enumeration) {
coll = invoke(pc, (Enumeration) obj, udf, execute, futures);
} else // String List
if (obj instanceof StringListData) {
coll = invoke(pc, (StringListData) obj, udf, execute, futures);
} else
throw new FunctionException(pc, "Filter", 1, "data", "cannot iterate througth this type " + Caster.toTypeName(obj.getClass()));
if (parallel)
afterCall(pc, coll, futures, execute);
return coll;
}
use of lucee.commons.lang.Pair in project Lucee by lucee.
the class HttpServletRequestDummy method translateQS.
/**
* constructor of the class
* @throws PageException
* /
* public HttpServletRequestDummy(String serverName, String scriptName,Struct queryString) throws PageException {
* this.serverName=serverName;
* requestURI=scriptName;
*
* StringBuffer qs=new StringBuffer();
* String[] keys=queryString.keys();
* parameters=new Item[keys.length];
* String key;
* Object value;
* for(int i=0;i<keys.length;i++) {
* if(i>0) qs.append('&');
* key=keys[i];
* value=queryString.get(key);
* parameters[i]=new Item(key,value);
*
* qs.append(key);
* qs.append('=');
* qs.append(Caster.toString(value));
* }
*
* this.queryString=qs.toString();
* }
*/
private Pair[] translateQS(String qs) {
if (qs == null)
return new Pair[0];
Array arr = lucee.runtime.type.util.ListUtil.listToArrayRemoveEmpty(qs, "&");
Pair[] parameters = new Pair[arr.size()];
// Array item;
int index;
String name;
for (int i = 1; i <= parameters.length; i++) {
name = Caster.toString(arr.get(i, ""), "");
index = name.indexOf('=');
if (index != -1)
parameters[i - 1] = new Pair(name.substring(0, index), name.substring(index + 1));
else
parameters[i - 1] = new Pair(name, "");
}
return parameters;
}
use of lucee.commons.lang.Pair in project Lucee by lucee.
the class ApplicationContextSupport method initLog.
public static Map<Collection.Key, Pair<Log, Struct>> initLog(Struct sct) {
Map<Collection.Key, Pair<Log, Struct>> rtn = new ConcurrentHashMap<Collection.Key, Pair<Log, Struct>>();
if (sct == null)
return rtn;
Iterator<Entry<Key, Object>> it = sct.entryIterator();
Entry<Key, Object> e;
Struct v;
int k;
Collection.Key name;
LoggerAndSourceData las;
while (it.hasNext()) {
e = it.next();
name = e.getKey();
v = Caster.toStruct(e.getValue(), null);
if (v == null)
continue;
// raw way
Struct sctApp = Caster.toStruct(v.get("appender", null), null);
ClassDefinition cdApp = toClassDefinition(sctApp, null, true, false);
Struct sctLay = Caster.toStruct(v.get("layout", null), null);
ClassDefinition cdLay = toClassDefinition(sctLay, null, false, true);
if (cdApp != null && cdApp.hasClass()) {
// level
String strLevel = Caster.toString(v.get("level", null), null);
if (StringUtil.isEmpty(strLevel, true))
Caster.toString(v.get("loglevel", null), null);
Level level = Log4jUtil.toLevel(StringUtil.trim(strLevel, ""), Level.ERROR);
Struct sctAppArgs = Caster.toStruct(sctApp.get("arguments", null), null);
Struct sctLayArgs = Caster.toStruct(sctLay.get("arguments", null), null);
boolean readOnly = Caster.toBooleanValue(v.get("readonly", null), false);
// ignore when no appender/name is defined
if (!StringUtil.isEmpty(name)) {
Map<String, String> appArgs = toMap(sctAppArgs);
if (cdLay != null && cdLay.hasClass()) {
Map<String, String> layArgs = toMap(sctLayArgs);
las = addLogger(name, level, cdApp, appArgs, cdLay, layArgs, readOnly);
} else
las = addLogger(name, level, cdApp, appArgs, null, null, readOnly);
rtn.put(name, new Pair<Log, Struct>(las.getLog(), v));
}
}
}
return rtn;
}
Aggregations