use of lucee.runtime.db.DataSource 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.DataSource 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);
}
}
use of lucee.runtime.db.DataSource in project Lucee by lucee.
the class QueryUtil method checkSQLRestriction.
/**
* check if there is a sql restriction
* @param dc
* @param sql
* @throws PageException
*/
public static void checkSQLRestriction(DatasourceConnection dc, SQL sql) throws PageException {
Array sqlparts = ListUtil.listToArrayRemoveEmpty(SQLUtil.removeLiterals(sql.getSQLString()), " \t" + System.getProperty("line.separator"));
// print.ln(List.toStringArray(sqlparts));
DataSource ds = dc.getDatasource();
if (!ds.hasAllow(DataSource.ALLOW_ALTER))
checkSQLRestriction(dc, "alter", sqlparts, sql);
if (!ds.hasAllow(DataSource.ALLOW_CREATE))
checkSQLRestriction(dc, "create", sqlparts, sql);
if (!ds.hasAllow(DataSource.ALLOW_DELETE))
checkSQLRestriction(dc, "delete", sqlparts, sql);
if (!ds.hasAllow(DataSource.ALLOW_DROP))
checkSQLRestriction(dc, "drop", sqlparts, sql);
if (!ds.hasAllow(DataSource.ALLOW_GRANT))
checkSQLRestriction(dc, "grant", sqlparts, sql);
if (!ds.hasAllow(DataSource.ALLOW_INSERT))
checkSQLRestriction(dc, "insert", sqlparts, sql);
if (!ds.hasAllow(DataSource.ALLOW_REVOKE))
checkSQLRestriction(dc, "revoke", sqlparts, sql);
if (!ds.hasAllow(DataSource.ALLOW_SELECT))
checkSQLRestriction(dc, "select", sqlparts, sql);
if (!ds.hasAllow(DataSource.ALLOW_UPDATE))
checkSQLRestriction(dc, "update", sqlparts, sql);
}
use of lucee.runtime.db.DataSource in project Lucee by lucee.
the class DBUtilImpl method getDatasourceConnection.
public DatasourceConnection getDatasourceConnection(PageContext pc, String datasourceName, String user, String pass, boolean managed) throws PageException {
DataSource datasource = null;
pc = ThreadLocalPageContext.get(pc);
if (pc != null) {
// default datasource
if ("__default__".equalsIgnoreCase(datasourceName)) {
Object obj = pc.getApplicationContext().getDefDataSource();
if (obj instanceof String)
datasourceName = (String) obj;
else
datasource = (DataSource) obj;
}
// get datasource from application context
if (datasource == null)
datasource = pc.getApplicationContext().getDataSource(datasourceName, null);
}
// get datasource from config
if (datasource == null) {
Config config = ThreadLocalPageContext.getConfig(pc);
datasource = config.getDataSource(datasourceName);
}
return getDatasourceConnection(pc, datasource, user, pass, managed);
}
use of lucee.runtime.db.DataSource in project Lucee by lucee.
the class ScopeContext method hasExistingCFSessionScope.
private boolean hasExistingCFSessionScope(PageContext pc) {
ApplicationContext appContext = pc.getApplicationContext();
// get Context
Map<String, Scope> context = getSubMap(cfSessionContexts, appContext.getName());
// get Session
String storage = appContext.getSessionstorage();
if (StringUtil.isEmpty(storage, true))
storage = "memory";
else if ("ram".equalsIgnoreCase(storage))
storage = "memory";
else if ("registry".equalsIgnoreCase(storage))
storage = "file";
else
storage = storage.toLowerCase();
Session session = (Session) context.get(pc.getCFID());
if (!(session instanceof StorageScope) || session.isExpired() || !((StorageScope) session).getStorage().equalsIgnoreCase(storage)) {
if ("memory".equals(storage))
return false;
else if ("file".equals(storage))
return SessionFile.hasInstance(appContext.getName(), pc);
else if ("cookie".equals(storage))
return SessionCookie.hasInstance(appContext.getName(), pc);
else {
DataSource ds = pc.getConfig().getDataSource(storage, null);
if (ds != null && ds.isStorage()) {
if (INVIDUAL_STORAGE_KEYS) {
return IKStorageScopeSupport.hasInstance(Scope.SCOPE_SESSION, new IKHandlerDatasource(), appContext.getName(), storage, pc);
} else {
if (SessionDatasource.hasInstance(storage, pc))
return true;
}
}
if (INVIDUAL_STORAGE_KEYS)
return IKStorageScopeSupport.hasInstance(Scope.SCOPE_SESSION, new IKHandlerCache(), appContext.getName(), storage, pc);
return SessionCache.hasInstance(storage, appContext.getName(), pc);
}
}
return true;
}
Aggregations