Search in sources :

Example 1 with DatasourceManagerImpl

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

the class Query method executeDatasoure.

private QueryResult executeDatasoure(SQL sql, boolean createUpdateData, TimeZone tz) throws PageException {
    DatasourceManagerImpl manager = (DatasourceManagerImpl) pageContext.getDataSourceManager();
    DatasourceConnection dc = manager.getConnection(pageContext, datasource, username, password);
    try {
        if (lazy && !createUpdateData && cachedWithin == null && cachedAfter == null && result == null) {
            if (returntype != RETURN_TYPE_QUERY)
                throw new DatabaseException("only return type query is allowed when lazy is set to true", null, sql, dc);
            return new SimpleQuery(pageContext, dc, sql, maxrows, blockfactor, timeout, getName(), getPageSource().getDisplayPath(), tz);
        }
        if (returntype == RETURN_TYPE_ARRAY)
            return QueryImpl.toArray(pageContext, dc, sql, maxrows, blockfactor, timeout, getName(), getPageSource().getDisplayPath(), createUpdateData, true);
        if (returntype == RETURN_TYPE_STRUCT) {
            if (columnName == null)
                throw new ApplicationException("attribute columnKey is required when return type is set to struct");
            return QueryImpl.toStruct(pageContext, dc, sql, columnName, maxrows, blockfactor, timeout, getName(), getPageSource().getDisplayPath(), createUpdateData, true);
        }
        return new QueryImpl(pageContext, dc, sql, maxrows, blockfactor, timeout, getName(), getPageSource().getDisplayPath(), createUpdateData, true);
    } finally {
        manager.releaseConnection(pageContext, dc);
    }
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) ApplicationException(lucee.runtime.exp.ApplicationException) DatasourceConnection(lucee.runtime.db.DatasourceConnection) SimpleQuery(lucee.runtime.type.query.SimpleQuery) DatasourceManagerImpl(lucee.runtime.db.DatasourceManagerImpl) DatabaseException(lucee.runtime.exp.DatabaseException)

Example 2 with DatasourceManagerImpl

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

the class Transaction method doStartTag.

@Override
public int doStartTag() throws PageException {
    DataSourceManager manager = pageContext.getDataSourceManager();
    // first transaction
    if (manager.isAutoCommit()) {
        // if(!hasBody)throw new DatabaseException("transaction tag with no end Tag can only be used inside a transaction tag",null,null,null);
        manager.begin(isolation);
        return EVAL_BODY_INCLUDE;
    }
    // inside transaction
    innerTag = true;
    switch(action) {
        /* nested transaction no longer throw a exception, they are simply ignored
        case ACTION_NONE:
        	throw new DatabaseException("you can't have a nested transaction with no action defined",null,null,null);
        case ACTION_BEGIN:
            throw new DatabaseException("you can't start a transaction inside a transaction tag",null,null,null);
        */
        case ACTION_NONE:
        case ACTION_BEGIN:
            ignore = true;
            break;
        case ACTION_COMMIT:
            manager.commit();
            break;
        case ACTION_ROLLBACK:
            manager.rollback();
            break;
        case ACTION_SET_SAVEPOINT:
            ((DatasourceManagerImpl) manager).savepoint();
            break;
    }
    return EVAL_BODY_INCLUDE;
}
Also used : DataSourceManager(lucee.runtime.db.DataSourceManager) DatasourceManagerImpl(lucee.runtime.db.DatasourceManagerImpl)

Example 3 with DatasourceManagerImpl

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

the class PageContextImpl method getORMSession.

@Override
public ORMSession getORMSession(boolean create) throws PageException {
    if (ormSession == null || !ormSession.isValid()) {
        if (!create)
            return null;
        ormSession = config.getORMEngine(this).createSession(this);
    }
    DatasourceManagerImpl manager = (DatasourceManagerImpl) getDataSourceManager();
    manager.add(this, ormSession);
    return ormSession;
}
Also used : DatasourceManagerImpl(lucee.runtime.db.DatasourceManagerImpl)

Example 4 with DatasourceManagerImpl

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

the class DBUtilImpl method releaseDatasourceConnection.

public void releaseDatasourceConnection(PageContext pc, DatasourceConnection dc, boolean managed) {
    pc = ThreadLocalPageContext.get(pc);
    if (managed) {
        if (pc == null)
            throw new PageRuntimeException(new ApplicationException("missing PageContext to access the Database Connection Manager"));
        DatasourceManagerImpl manager = (DatasourceManagerImpl) pc.getDataSourceManager();
        manager.releaseConnection(pc, dc);
        return;
    }
    releaseDatasourceConnection(ThreadLocalPageContext.getConfig(pc), dc);
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) DatasourceManagerImpl(lucee.runtime.db.DatasourceManagerImpl)

Example 5 with DatasourceManagerImpl

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

the class DatasourceResourceProvider method getManager.

private DatasourceManagerImpl getManager() {
    if (_manager == null) {
        Config config = ThreadLocalPageContext.getConfig();
        _manager = new DatasourceManagerImpl((ConfigImpl) config);
    }
    return _manager;
}
Also used : Config(lucee.runtime.config.Config) DatasourceManagerImpl(lucee.runtime.db.DatasourceManagerImpl) ConfigImpl(lucee.runtime.config.ConfigImpl)

Aggregations

DatasourceManagerImpl (lucee.runtime.db.DatasourceManagerImpl)5 ApplicationException (lucee.runtime.exp.ApplicationException)2 Config (lucee.runtime.config.Config)1 ConfigImpl (lucee.runtime.config.ConfigImpl)1 DataSourceManager (lucee.runtime.db.DataSourceManager)1 DatasourceConnection (lucee.runtime.db.DatasourceConnection)1 DatabaseException (lucee.runtime.exp.DatabaseException)1 PageRuntimeException (lucee.runtime.exp.PageRuntimeException)1 QueryImpl (lucee.runtime.type.QueryImpl)1 SimpleQuery (lucee.runtime.type.query.SimpleQuery)1