Search in sources :

Example 11 with Pair

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());
    }
}
Also used : ORMDatasourceConnection(lucee.runtime.orm.ORMDatasourceConnection) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) DatabaseException(lucee.runtime.exp.DatabaseException) DeprecatedException(lucee.runtime.exp.DeprecatedException) SQLException(java.sql.SQLException) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) PageException(lucee.runtime.exp.PageException) Entry(java.util.Map.Entry) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) DatabaseException(lucee.runtime.exp.DatabaseException) ORMConnection(lucee.runtime.orm.ORMConnection) Pair(lucee.commons.lang.Pair)

Example 12 with Pair

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());
    }
}
Also used : ORMDatasourceConnection(lucee.runtime.orm.ORMDatasourceConnection) SQLException(java.sql.SQLException) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) DatabaseException(lucee.runtime.exp.DatabaseException) DatabaseException(lucee.runtime.exp.DatabaseException) DeprecatedException(lucee.runtime.exp.DeprecatedException) SQLException(java.sql.SQLException) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) PageException(lucee.runtime.exp.PageException) Pair(lucee.commons.lang.Pair)

Example 13 with Pair

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;
}
Also used : Enumeration(java.util.Enumeration) Query(lucee.runtime.type.Query) FunctionException(lucee.runtime.exp.FunctionException) Struct(lucee.runtime.type.Struct) Array(lucee.runtime.type.Array) StringListData(lucee.runtime.type.util.StringListData) Iteratorable(lucee.runtime.type.Iteratorable) ExecutorService(java.util.concurrent.ExecutorService) ListIterator(java.util.ListIterator) ForEachQueryIterator(lucee.runtime.type.it.ForEachQueryIterator) Iterator(java.util.Iterator) Future(java.util.concurrent.Future) Collection(lucee.runtime.type.Collection) ArrayList(java.util.ArrayList) List(java.util.List) Pair(lucee.commons.lang.Pair)

Example 14 with Pair

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;
}
Also used : Array(lucee.runtime.type.Array) Pair(lucee.commons.lang.Pair)

Example 15 with Pair

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;
}
Also used : LoggerAndSourceData(lucee.commons.io.log.LoggerAndSourceData) Log(lucee.commons.io.log.Log) ClassDefinition(lucee.runtime.db.ClassDefinition) Struct(lucee.runtime.type.Struct) Key(lucee.runtime.type.Collection.Key) Entry(java.util.Map.Entry) Collection(lucee.runtime.type.Collection) Level(org.apache.log4j.Level) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Key(lucee.runtime.type.Collection.Key) Pair(lucee.commons.lang.Pair)

Aggregations

Pair (lucee.commons.lang.Pair)15 PageException (lucee.runtime.exp.PageException)7 ThreadLocalPageContext (lucee.runtime.engine.ThreadLocalPageContext)5 Struct (lucee.runtime.type.Struct)5 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 Entry (java.util.Map.Entry)4 Cookie (javax.servlet.http.Cookie)4 PageContext (lucee.runtime.PageContext)4 DatabaseException (lucee.runtime.exp.DatabaseException)4 DeprecatedException (lucee.runtime.exp.DeprecatedException)4 PageRuntimeException (lucee.runtime.exp.PageRuntimeException)4 ORMDatasourceConnection (lucee.runtime.orm.ORMDatasourceConnection)4 StructImpl (lucee.runtime.type.StructImpl)4 Enumeration (java.util.Enumeration)3 ConfigWeb (lucee.runtime.config.ConfigWeb)3 DevNullOutputStream (lucee.commons.io.DevNullOutputStream)2 Log (lucee.commons.io.log.Log)2 PageContextImpl (lucee.runtime.PageContextImpl)2 HttpServletResponseDummy (lucee.runtime.net.http.HttpServletResponseDummy)2