Search in sources :

Example 6 with DataSourceManager

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

the class ColumnInfo method doEndTag.

@Override
public int doEndTag() throws PageException {
    Object ds = DBInfo.getDatasource(pageContext, datasource);
    DataSourceManager manager = pageContext.getDataSourceManager();
    DatasourceConnection dc = ds instanceof DataSource ? manager.getConnection(pageContext, (DataSource) ds, username, password) : manager.getConnection(pageContext, Caster.toString(ds), username, password);
    try {
        Struct meta = null;
        try {
            meta = getMeta(dc, tablequalifier, tableowner, tablename);
        } catch (SQLException se) {
            meta = new StructImpl();
        }
        SQL sql = createSQL(meta);
        if (sql != null) {
            lucee.runtime.type.Query query = new QueryImpl(pageContext, dc, sql, -1, -1, null, "query");
            if (pageContext.getConfig().debug()) {
                String dsn = ds instanceof DataSource ? ((DataSource) ds).getName() : Caster.toString(ds);
                boolean logdb = ((ConfigImpl) pageContext.getConfig()).hasDebugOptions(ConfigImpl.DEBUG_DATABASE);
                if (logdb) {
                    boolean debugUsage = DebuggerImpl.debugQueryUsage(pageContext, query);
                    pageContext.getDebugger().addQuery(debugUsage ? query : null, dsn, "", sql, query.getRecordcount(), pageContext.getCurrentPageSource(), query.getExecutionTime());
                }
            }
            // log
            Log log = pageContext.getConfig().getLog("datasource");
            if (log.getLogLevel() >= Log.LEVEL_INFO) {
                log.info("insert tag", "executed [" + sql.toString().trim() + "] in " + DecimalFormat.call(pageContext, query.getExecutionTime() / 1000000D) + " ms");
            }
        }
        return EVAL_PAGE;
    } catch (PageException pe) {
        pageContext.getConfig().getLog("datasource").error("insert tag", pe);
        throw pe;
    } finally {
        manager.releaseConnection(pageContext, dc);
    }
}
Also used : PageException(lucee.runtime.exp.PageException) DatasourceConnection(lucee.runtime.db.DatasourceConnection) SQLException(java.sql.SQLException) Log(lucee.commons.io.log.Log) DataSourceManager(lucee.runtime.db.DataSourceManager) DataSource(lucee.runtime.db.DataSource) Struct(lucee.runtime.type.Struct) SQL(lucee.runtime.db.SQL) QueryImpl(lucee.runtime.type.QueryImpl) StructImpl(lucee.runtime.type.StructImpl) ConfigImpl(lucee.runtime.config.ConfigImpl)

Example 7 with DataSourceManager

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

the class Transaction method doCatch.

@Override
public void doCatch(Throwable t) throws Throwable {
    ExceptionUtil.rethrowIfNecessary(t);
    if (innerTag || ignore)
        throw t;
    DataSourceManager manager = pageContext.getDataSourceManager();
    try {
        manager.rollback();
    } catch (DatabaseException e) {
    // print.printST(e);
    }
    throw t;
}
Also used : DataSourceManager(lucee.runtime.db.DataSourceManager) DatabaseException(lucee.runtime.exp.DatabaseException)

Example 8 with DataSourceManager

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

the class Admin method _doVerifyDatasource.

private void _doVerifyDatasource(String name, String username, String password) throws PageException {
    DataSourceManager manager = pageContext.getDataSourceManager();
    manager.releaseConnection(pageContext, manager.getConnection(pageContext, name, username, password));
}
Also used : DataSourceManager(lucee.runtime.db.DataSourceManager)

Example 9 with DataSourceManager

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

the class DataSourceServiceImpl method verifyDatasource.

@Override
public boolean verifyDatasource(String name) throws SQLException, SecurityException {
    checkReadAccess();
    lucee.runtime.db.DataSource d = _getDatasource(name);
    PageContext pc = pc();
    DataSourceManager manager = pc.getDataSourceManager();
    try {
        manager.releaseConnection(pc, manager.getConnection(pc, name, d.getUsername(), d.getPassword()));
        return true;
    } catch (PageException e) {
        return false;
    }
}
Also used : PageException(lucee.runtime.exp.PageException) PageContext(lucee.runtime.PageContext) DataSourceManager(lucee.runtime.db.DataSourceManager)

Aggregations

DataSourceManager (lucee.runtime.db.DataSourceManager)9 PageException (lucee.runtime.exp.PageException)5 SQLException (java.sql.SQLException)4 DataSource (lucee.runtime.db.DataSource)4 DatasourceConnection (lucee.runtime.db.DatasourceConnection)4 Log (lucee.commons.io.log.Log)3 ConfigImpl (lucee.runtime.config.ConfigImpl)3 DatabaseException (lucee.runtime.exp.DatabaseException)3 QueryImpl (lucee.runtime.type.QueryImpl)3 Struct (lucee.runtime.type.Struct)3 StructImpl (lucee.runtime.type.StructImpl)3 SQL (lucee.runtime.db.SQL)2 ApplicationException (lucee.runtime.exp.ApplicationException)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 CallableStatement (java.sql.CallableStatement)1 ResultSet (java.sql.ResultSet)1 Iterator (java.util.Iterator)1 Entry (java.util.Map.Entry)1 PageContext (lucee.runtime.PageContext)1