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