Search in sources :

Example 1 with ORMConnection

use of lucee.runtime.orm.ORMConnection 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)

Aggregations

SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 Pair (lucee.commons.lang.Pair)1 DatabaseException (lucee.runtime.exp.DatabaseException)1 DeprecatedException (lucee.runtime.exp.DeprecatedException)1 PageException (lucee.runtime.exp.PageException)1 PageRuntimeException (lucee.runtime.exp.PageRuntimeException)1 ORMConnection (lucee.runtime.orm.ORMConnection)1 ORMDatasourceConnection (lucee.runtime.orm.ORMDatasourceConnection)1