Search in sources :

Example 16 with DatasourceConnection

use of lucee.runtime.db.DatasourceConnection in project Lucee by lucee.

the class StorageScopeDatasource method store.

@Override
public void store(PageContext pc) {
    DatasourceConnection dc = null;
    ConfigImpl ci = (ConfigImpl) ThreadLocalPageContext.getConfig(pc);
    DatasourceConnectionPool pool = ci.getDatasourceConnectionPool();
    Log log = ci.getLog("scope");
    try {
        // FUTURE change method interface
        pc = ThreadLocalPageContext.get(pc);
        DataSource ds;
        if (pc != null)
            ds = pc.getDataSource(datasourceName);
        else
            ds = ci.getDataSource(datasourceName);
        dc = pool.getDatasourceConnection(null, ds, null, null);
        SQLExecutor executor = SQLExecutionFactory.getInstance(dc);
        executor.update(ci, cfid, appName, dc, getType(), sct, getTimeSpan(), log);
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        ScopeContext.error(log, t);
    } finally {
        if (dc != null)
            pool.releaseDatasourceConnection(dc);
    }
}
Also used : DatasourceConnection(lucee.runtime.db.DatasourceConnection) DatasourceConnectionPool(lucee.runtime.db.DatasourceConnectionPool) Log(lucee.commons.io.log.Log) SQLExecutor(lucee.runtime.type.scope.storage.db.SQLExecutor) ConfigImpl(lucee.runtime.config.ConfigImpl) DataSource(lucee.runtime.db.DataSource)

Example 17 with DatasourceConnection

use of lucee.runtime.db.DatasourceConnection in project Lucee by lucee.

the class DatasourceResourceProvider method getOutputStream.

public synchronized OutputStream getOutputStream(ConnectionData data, int fullPathHash, int pathHash, String path, String name, boolean append) throws IOException {
    Attr attr = getAttr(data, fullPathHash, path, name);
    if (attr.getId() == 0) {
        create(data, fullPathHash, pathHash, path, name, Attr.TYPE_FILE);
        attr = getAttr(data, fullPathHash, path, name);
    }
    PipedInputStream pis = new PipedInputStream();
    PipedOutputStream pos = new PipedOutputStream();
    pis.connect(pos);
    DatasourceConnection dc = null;
    // Connection c=null;
    try {
        dc = getDatasourceConnection(data);
        // Connection c = dc.getConnection();
        DataWriter writer = new DataWriter(getCore(data), dc, data.getPrefix(), attr, pis, this, append);
        writer.start();
        return new DatasourceResourceOutputStream(writer, pos);
    // core.getOutputStream(dc, name, attr, pis);
    } catch (PageException e) {
        throw new PageRuntimeException(e);
    } finally {
        removeFromCache(data, path, name);
    // manager.releaseConnection(CONNECTION_ID,dc);
    }
}
Also used : PageException(lucee.runtime.exp.PageException) DatasourceConnection(lucee.runtime.db.DatasourceConnection) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) PageRuntimeException(lucee.runtime.exp.PageRuntimeException)

Example 18 with DatasourceConnection

use of lucee.runtime.db.DatasourceConnection in project Lucee by lucee.

the class DatasourceResourceProvider method create.

public void create(ConnectionData data, int fullPathHash, int pathHash, String path, String name, int type) throws IOException {
    if (StringUtil.isEmpty(data.getDatasourceName()))
        throw new IOException("missing datasource definition");
    removeFromCache(data, path, name);
    DatasourceConnection dc = null;
    try {
        dc = getDatasourceConnection(data);
        getCore(data).create(dc, data.getPrefix(), fullPathHash, pathHash, path, name, type);
    } catch (SQLException e) {
        throw new IOException(e.getMessage());
    } catch (PageException e) {
        throw new PageRuntimeException(e);
    } finally {
        release(dc);
    }
}
Also used : PageException(lucee.runtime.exp.PageException) DatasourceConnection(lucee.runtime.db.DatasourceConnection) SQLException(java.sql.SQLException) IOException(java.io.IOException) PageRuntimeException(lucee.runtime.exp.PageRuntimeException)

Example 19 with DatasourceConnection

use of lucee.runtime.db.DatasourceConnection in project Lucee by lucee.

the class DatasourceResourceProvider method getDatasourceConnection.

private DatasourceConnection getDatasourceConnection(ConnectionData data, boolean autoCommit) throws PageException {
    DatasourceConnection dc = getManager().getConnection(ThreadLocalPageContext.get(), data.getDatasourceName(), data.getUsername(), data.getPassword());
    try {
        dc.getConnection().setAutoCommit(autoCommit);
        dc.getConnection().setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
    } catch (SQLException e) {
        throw new DatabaseException(e, dc);
    }
    return dc;
}
Also used : DatasourceConnection(lucee.runtime.db.DatasourceConnection) SQLException(java.sql.SQLException) DatabaseException(lucee.runtime.exp.DatabaseException)

Example 20 with DatasourceConnection

use of lucee.runtime.db.DatasourceConnection in project Lucee by lucee.

the class DatasourceResourceProvider method setMode.

public boolean setMode(ConnectionData data, int fullPathHash, String path, String name, int mode) {
    try {
        Attr attr = getAttr(data, fullPathHash, path, name);
        DatasourceConnection dc = getDatasourceConnection(data);
        try {
            getCore(data).setMode(dc, data.getPrefix(), attr, mode);
        } finally /*catch (SQLException e) {
				return false;
			} */
        {
            removeFromCache(data, path, name);
            release(dc);
        // manager.releaseConnection(CONNECTION_ID,dc);
        }
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        return false;
    }
    return true;
}
Also used : DatasourceConnection(lucee.runtime.db.DatasourceConnection)

Aggregations

DatasourceConnection (lucee.runtime.db.DatasourceConnection)24 SQLException (java.sql.SQLException)14 ConfigImpl (lucee.runtime.config.ConfigImpl)10 PageException (lucee.runtime.exp.PageException)9 DataSource (lucee.runtime.db.DataSource)8 DatabaseException (lucee.runtime.exp.DatabaseException)8 Log (lucee.commons.io.log.Log)7 DatasourceConnectionPool (lucee.runtime.db.DatasourceConnectionPool)7 SQLExecutor (lucee.runtime.type.scope.storage.db.SQLExecutor)7 ApplicationException (lucee.runtime.exp.ApplicationException)5 DataSourceManager (lucee.runtime.db.DataSourceManager)4 PageRuntimeException (lucee.runtime.exp.PageRuntimeException)4 QueryImpl (lucee.runtime.type.QueryImpl)4 Struct (lucee.runtime.type.Struct)4 IOException (java.io.IOException)3 ResultSet (java.sql.ResultSet)3 StructImpl (lucee.runtime.type.StructImpl)3 Connection (java.sql.Connection)2 Iterator (java.util.Iterator)2 SQL (lucee.runtime.db.SQL)2