use of lucee.runtime.db.DatasourceConnection in project Lucee by lucee.
the class DatasourceResourceProvider method getCore.
private Core getCore(ConnectionData data) throws PageException {
Core core = (Core) cores.get(data.datasourceName);
if (core == null) {
DatasourceConnection dc = getManager().getConnection(ThreadLocalPageContext.get(), data.getDatasourceName(), data.getUsername(), data.getPassword());
try {
dc.getConnection().setAutoCommit(false);
dc.getConnection().setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
if ("com.microsoft.jdbc.sqlserver.SQLServerDriver".equals(dc.getDatasource().getClassDefinition().getClassName()))
core = new MSSQL(dc, data.getPrefix());
else if ("com.microsoft.sqlserver.jdbc.SQLServerDriver".equals(dc.getDatasource().getClassDefinition().getClassName()))
core = new MSSQL(dc, data.getPrefix());
else if ("net.sourceforge.jtds.jdbc.Driver".equals(dc.getDatasource().getClassDefinition().getClassName()))
core = new MSSQL(dc, data.getPrefix());
else if ("org.gjt.mm.mysql.Driver".equals(dc.getDatasource().getClassDefinition().getClassName()))
core = new MySQL(dc, data.getPrefix());
else
throw new ApplicationException("there is no DatasourceResource driver for this database [" + data.getPrefix() + "]");
cores.put(data.datasourceName, core);
} catch (SQLException e) {
throw new DatabaseException(e, dc);
} finally {
release(dc);
// manager.releaseConnection(CONNECTION_ID,dc);
}
}
return core;
}
use of lucee.runtime.db.DatasourceConnection in project Lucee by lucee.
the class DatasourceResourceProvider method delete.
public void delete(ConnectionData data, int fullPathHash, String path, String name) throws IOException {
Attr attr = getAttr(data, fullPathHash, path, name);
if (attr == null)
throw new IOException("can't delete resource " + path + name + ", resource does not exist");
DatasourceConnection dc = null;
try {
dc = getDatasourceConnection(data);
getCore(data).delete(dc, data.getPrefix(), attr);
} catch (SQLException e) {
throw new IOException(e.getMessage());
} catch (PageException e) {
throw new PageRuntimeException(e);
} finally {
removeFromCache(data, path, name);
release(dc);
// manager.releaseConnection(CONNECTION_ID,dc);
}
}
use of lucee.runtime.db.DatasourceConnection in project Lucee by lucee.
the class DatasourceResourceProvider method getAttrs.
public Attr[] getAttrs(ConnectionData data, int pathHash, String path) throws PageException {
if (StringUtil.isEmpty(data.getDatasourceName()))
return null;
// Attr[] attrs = getFromCache(data, path);
// if(attrs!=null) return attrs;
DatasourceConnection dc = null;
try {
dc = getDatasourceConnection(data);
List list = getCore(data).getAttrs(dc, data.getPrefix(), pathHash, path);
if (list != null) {
Iterator it = list.iterator();
Attr[] rtn = new Attr[list.size()];
int index = 0;
while (it.hasNext()) {
rtn[index] = (Attr) it.next();
putToCache(data, rtn[index].getParent(), rtn[index].getName(), rtn[index]);
index++;
}
// putToCache(data, path, rtn);
return rtn;
}
} catch (SQLException e) {
throw new DatabaseException(e, dc);
} finally {
release(dc);
// manager.releaseConnection(CONNECTION_ID,dc);
}
return null;
}
use of lucee.runtime.db.DatasourceConnection in project Lucee by lucee.
the class DBInfo method doStartTag.
@Override
public int doStartTag() throws PageException {
Object ds = 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 {
if (type == TYPE_TABLE_COLUMNS)
typeColumns(dc.getConnection().getMetaData());
else if (type == TYPE_DBNAMES)
typeDBNames(dc.getConnection().getMetaData());
else if (type == TYPE_FOREIGNKEYS)
typeForeignKeys(dc.getConnection().getMetaData());
else if (type == TYPE_INDEX)
typeIndex(dc.getConnection().getMetaData());
else if (type == TYPE_PROCEDURES)
typeProcedures(dc.getConnection().getMetaData());
else if (type == TYPE_PROCEDURE_COLUMNS)
typeProcedureColumns(dc.getConnection().getMetaData());
else if (type == TYPE_TERMS)
typeTerms(dc.getConnection().getMetaData());
else if (type == TYPE_TABLES)
typeTables(dc.getConnection().getMetaData());
else if (type == TYPE_VERSION)
typeVersion(dc.getConnection().getMetaData());
else if (type == TYPE_USERS)
typeUsers(dc.getConnection().getMetaData());
} catch (SQLException sqle) {
throw new DatabaseException(sqle, dc);
} finally {
manager.releaseConnection(pageContext, dc);
}
return SKIP_BODY;
}
use of lucee.runtime.db.DatasourceConnection 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);
}
}
Aggregations