use of lucee.runtime.config.ConfigImpl in project Lucee by lucee.
the class CFMLFactoryImpl method stopThread.
public void stopThread(String threadId, String stopType) {
// synchronized (runningPcs) {
Iterator<PageContextImpl> it = runningPcs.values().iterator();
PageContext pc;
while (it.hasNext()) {
pc = it.next();
Log log = ((ConfigImpl) pc.getConfig()).getLog("application");
try {
String id = Hash.call(pc, pc.getId() + ":" + pc.getStartTime());
if (id.equals(threadId)) {
stopType = stopType.trim();
// Throwable t;
if ("abort".equalsIgnoreCase(stopType) || "cfabort".equalsIgnoreCase(stopType))
throw new RuntimeException("type [" + stopType + "] is no longer supported");
// t=new Abort(Abort.SCOPE_REQUEST);
// else t=new RequestTimeoutException(pc.getThread(),"request has been forced to stop.");
SystemUtil.stop(pc, log, true);
SystemUtil.sleep(10);
break;
}
} catch (PageException e1) {
}
}
// }
}
use of lucee.runtime.config.ConfigImpl in project Lucee by lucee.
the class CustomTagUtil method loadInitFile.
public static InitFile loadInitFile(PageContext pc, String name, InitFile defaultValue) throws PageException {
ConfigImpl config = (ConfigImpl) pc.getConfig();
String[] filenames = getFileNames(config, name);
boolean doCache = config.useCTPathCache();
boolean doCustomTagDeepSearch = config.doCustomTagDeepSearch();
PageSource ps = null;
InitFile initFile;
// CACHE
// check local
String localCacheName = null;
Mapping[] actms = pc.getApplicationContext().getCustomTagMappings();
Mapping[] cctms = config.getCustomTagMappings();
if (doCache) {
if (pc.getConfig().doLocalCustomTag()) {
localCacheName = pc.getCurrentPageSource().getDisplayPath().replace('\\', '/');
localCacheName = "local:" + localCacheName.substring(0, localCacheName.lastIndexOf('/') + 1).concat(name);
initFile = config.getCTInitFile(pc, localCacheName);
if (initFile != null)
return initFile;
}
// cache application mapping
if (actms != null)
for (int i = 0; i < actms.length; i++) {
initFile = config.getCTInitFile(pc, "application:" + actms[i].hashCode() + "/" + name);
if (initFile != null)
return initFile;
}
// cache config mapping
if (cctms != null)
for (int i = 0; i < cctms.length; i++) {
initFile = config.getCTInitFile(pc, "config:" + cctms[i].hashCode() + "/" + name);
if (initFile != null)
return initFile;
}
}
// search local
if (pc.getConfig().doLocalCustomTag()) {
for (int i = 0; i < filenames.length; i++) {
PageSource[] arr = ((PageContextImpl) pc).getRelativePageSources(filenames[i]);
// ps=pc.getRelativePageSource(filenames[i]);
ps = MappingImpl.isOK(arr);
if (ps != null) {
initFile = new InitFile(pc, ps, filenames[i]);
if (doCache)
config.putCTInitFile(localCacheName, initFile);
return initFile;
}
}
}
// search application custom tag mapping
if (actms != null) {
for (int i = 0; i < filenames.length; i++) {
ps = getMapping(actms, filenames[i], doCustomTagDeepSearch);
if (ps != null) {
initFile = new InitFile(pc, ps, filenames[i]);
if (doCache)
config.putCTInitFile("application:" + ps.getMapping().hashCode() + "/" + name, initFile);
return initFile;
}
}
}
// search custom tag mappings
for (int i = 0; i < filenames.length; i++) {
ps = getMapping(cctms, filenames[i], doCustomTagDeepSearch);
if (ps != null) {
initFile = new InitFile(pc, ps, filenames[i]);
if (doCache)
config.putCTInitFile("config:" + ps.getMapping().hashCode() + "/" + name, initFile);
return initFile;
}
}
return defaultValue;
}
use of lucee.runtime.config.ConfigImpl in project Lucee by lucee.
the class HSQLDBHandler method __execute.
public static QueryImpl __execute(PageContext pc, SQL sql, int maxrows, int fetchsize, TimeSpan timeout, Stopwatch stopwatch, Set<String> tables, boolean doSimpleTypes) throws PageException {
ArrayList<String> usedTables = new ArrayList<String>();
synchronized (lock) {
QueryImpl nqr = null;
ConfigImpl config = (ConfigImpl) pc.getConfig();
DatasourceConnectionPool pool = config.getDatasourceConnectionPool();
DatasourceConnection dc = pool.getDatasourceConnection(config, config.getDataSource(QOQ_DATASOURCE_NAME), "sa", "");
Connection conn = dc.getConnection();
try {
DBUtil.setAutoCommitEL(conn, false);
// sql.setSQLString(HSQLUtil.sqlToZQL(sql.getSQLString(),false));
try {
Iterator<String> it = tables.iterator();
// int len=tables.size();
while (it.hasNext()) {
// tables.get(i).toString();
String tableName = it.next().toString();
String modTableName = tableName.replace('.', '_');
String modSql = StringUtil.replace(sql.getSQLString(), tableName, modTableName, false);
sql.setSQLString(modSql);
addTable(conn, pc, modTableName, Caster.toQuery(pc.getVariable(tableName)), doSimpleTypes, usedTables);
}
DBUtil.setReadOnlyEL(conn, true);
try {
nqr = new QueryImpl(pc, dc, sql, maxrows, fetchsize, timeout, "query", null, false, false);
} finally {
DBUtil.setReadOnlyEL(conn, false);
DBUtil.commitEL(conn);
DBUtil.setAutoCommitEL(conn, true);
}
} catch (SQLException e) {
DatabaseException de = new DatabaseException("there is a problem to execute sql statement on query", null, sql, null);
de.setDetail(e.getMessage());
throw de;
}
} finally {
removeAll(conn, usedTables);
DBUtil.setAutoCommitEL(conn, true);
pool.releaseDatasourceConnection(dc);
// manager.releaseConnection(dc);
}
nqr.setExecutionTime(stopwatch.time());
return nqr;
}
}
use of lucee.runtime.config.ConfigImpl in project Lucee by lucee.
the class DebugEntryTemplatePartComparator method writeOut.
@Override
public void writeOut(PageContext pc) throws IOException {
// stop();
if (!output)
return;
String addr = pc.getHttpServletRequest().getRemoteAddr();
lucee.runtime.config.DebugEntry debugEntry = ((ConfigImpl) pc.getConfig()).getDebugEntry(addr, null);
if (debugEntry == null) {
// pc.forceWrite(pc.getConfig().getDefaultDumpWriter().toString(pc,toDumpData(pc, 9999,DumpUtil.toDumpProperties()),true));
return;
}
Struct args = new StructImpl();
args.setEL(KeyConstants._custom, debugEntry.getCustom());
try {
args.setEL(KeyConstants._debugging, pc.getDebugger().getDebuggingData(pc));
} catch (PageException e1) {
}
try {
String path = debugEntry.getPath();
PageSource[] arr = ((PageContextImpl) pc).getPageSources(path);
Page p = PageSourceImpl.loadPage(pc, arr, null);
// patch for old path
String fullname = debugEntry.getFullname();
if (p == null) {
if (path != null) {
boolean changed = false;
if (path.endsWith("/Modern.cfc") || path.endsWith("\\Modern.cfc")) {
path = "/lucee-server-context/admin/debug/Modern.cfc";
fullname = "lucee-server-context.admin.debug.Modern";
changed = true;
} else if (path.endsWith("/Classic.cfc") || path.endsWith("\\Classic.cfc")) {
path = "/lucee-server-context/admin/debug/Classic.cfc";
fullname = "lucee-server-context.admin.debug.Classic";
changed = true;
} else if (path.endsWith("/Comment.cfc") || path.endsWith("\\Comment.cfc")) {
path = "/lucee-server-context/admin/debug/Comment.cfc";
fullname = "lucee-server-context.admin.debug.Comment";
changed = true;
}
if (changed)
pc.write("<span style='color:red'>Please update your debug template defintions in the Lucee admin by going into the detail view and hit the \"update\" button.</span>");
}
arr = ((PageContextImpl) pc).getPageSources(path);
p = PageSourceImpl.loadPage(pc, arr);
}
pc.addPageSource(p.getPageSource(), true);
try {
Component c = pc.loadComponent(fullname);
c.callWithNamedValues(pc, "output", args);
} finally {
pc.removeLastPageSource(true);
}
} catch (PageException e) {
pc.handlePageException(e);
}
}
use of lucee.runtime.config.ConfigImpl in project Lucee by lucee.
the class DebugEntryTemplatePartComparator method getDebuggingData.
@Override
public Struct getDebuggingData(PageContext pc, boolean addAddionalInfo) throws DatabaseException {
Struct debugging = new StructImpl();
// datasources
debugging.setEL(KeyConstants._datasources, ((ConfigImpl) pc.getConfig()).getDatasourceConnectionPool().meta());
// queries
List<QueryEntry> queries = getQueries();
Struct qryExe = new StructImpl();
ListIterator<QueryEntry> qryIt = queries.listIterator();
Collection.Key[] cols = new Collection.Key[] { KeyConstants._name, KeyConstants._time, KeyConstants._sql, KeyConstants._src, KeyConstants._count, KeyConstants._datasource, KeyConstants._usage, CACHE_TYPE };
String[] types = new String[] { "VARCHAR", "DOUBLE", "VARCHAR", "VARCHAR", "DOUBLE", "VARCHAR", "ANY", "VARCHAR" };
Query qryQueries = null;
try {
qryQueries = new QueryImpl(cols, types, queries.size(), "query");
} catch (DatabaseException e) {
qryQueries = new QueryImpl(cols, queries.size(), "query");
}
int row = 0;
try {
QueryEntry qe;
while (qryIt.hasNext()) {
row++;
qe = qryIt.next();
qryQueries.setAt(KeyConstants._name, row, qe.getName() == null ? "" : qe.getName());
qryQueries.setAt(KeyConstants._time, row, Long.valueOf(qe.getExecutionTime()));
qryQueries.setAt(KeyConstants._sql, row, qe.getSQL().toString());
qryQueries.setAt(KeyConstants._src, row, qe.getSrc());
qryQueries.setAt(KeyConstants._count, row, Integer.valueOf(qe.getRecordcount()));
qryQueries.setAt(KeyConstants._datasource, row, qe.getDatasource());
qryQueries.setAt(CACHE_TYPE, row, qe.getCacheType());
Struct usage = getUsage(qe);
if (usage != null)
qryQueries.setAt(KeyConstants._usage, row, usage);
Object o = qryExe.get(KeyImpl.init(qe.getSrc()), null);
if (o == null)
qryExe.setEL(KeyImpl.init(qe.getSrc()), Long.valueOf(qe.getExecutionTime()));
else
qryExe.setEL(KeyImpl.init(qe.getSrc()), Long.valueOf(((Long) o).longValue() + qe.getExecutionTime()));
}
} catch (PageException dbe) {
}
// Pages
// src,load,app,query,total
row = 0;
ArrayList<DebugEntryTemplate> arrPages = toArray();
int len = arrPages.size();
Query qryPage = new QueryImpl(new Collection.Key[] { KeyConstants._id, KeyConstants._count, KeyConstants._min, KeyConstants._max, KeyConstants._avg, KeyConstants._app, KeyConstants._load, KeyConstants._query, KeyConstants._total, KeyConstants._src }, len, "query");
try {
DebugEntryTemplate de;
// PageSource ps;
for (int i = 0; i < len; i++) {
row++;
de = arrPages.get(i);
// ps = de.getPageSource();
qryPage.setAt(KeyConstants._id, row, de.getId());
qryPage.setAt(KeyConstants._count, row, _toString(de.getCount()));
qryPage.setAt(KeyConstants._min, row, _toString(de.getMin()));
qryPage.setAt(KeyConstants._max, row, _toString(de.getMax()));
qryPage.setAt(KeyConstants._avg, row, _toString(de.getExeTime() / de.getCount()));
qryPage.setAt(KeyConstants._app, row, _toString(de.getExeTime() - de.getQueryTime()));
qryPage.setAt(KeyConstants._load, row, _toString(de.getFileLoadTime()));
qryPage.setAt(KeyConstants._query, row, _toString(de.getQueryTime()));
qryPage.setAt(KeyConstants._total, row, _toString(de.getFileLoadTime() + de.getExeTime()));
qryPage.setAt(KeyConstants._src, row, de.getSrc());
}
} catch (PageException dbe) {
}
// Pages Parts
List<DebugEntryTemplatePart> filteredPartEntries = null;
boolean hasParts = partEntries != null && !partEntries.isEmpty() && !arrPages.isEmpty();
int qrySize = 0;
if (hasParts) {
String slowestTemplate = arrPages.get(0).getPath();
filteredPartEntries = new ArrayList();
java.util.Collection<DebugEntryTemplatePartImpl> col = partEntries.values();
for (DebugEntryTemplatePart detp : col) {
if (detp.getPath().equals(slowestTemplate))
filteredPartEntries.add(detp);
}
qrySize = Math.min(filteredPartEntries.size(), MAX_PARTS);
}
Query qryPart = new QueryImpl(new Collection.Key[] { KeyConstants._id, KeyConstants._count, KeyConstants._min, KeyConstants._max, KeyConstants._avg, KeyConstants._total, KeyConstants._path, KeyConstants._start, KeyConstants._end, KeyConstants._startLine, KeyConstants._endLine, KeyConstants._snippet }, qrySize, "query");
if (hasParts) {
row = 0;
Collections.sort(filteredPartEntries, DEBUG_ENTRY_TEMPLATE_PART_COMPARATOR);
DebugEntryTemplatePart[] parts = new DebugEntryTemplatePart[qrySize];
if (filteredPartEntries.size() > MAX_PARTS)
parts = filteredPartEntries.subList(0, MAX_PARTS).toArray(parts);
else
parts = filteredPartEntries.toArray(parts);
try {
DebugEntryTemplatePart de;
// PageSource ps;
for (int i = 0; i < parts.length; i++) {
row++;
de = parts[i];
qryPart.setAt(KeyConstants._id, row, de.getId());
qryPart.setAt(KeyConstants._count, row, _toString(de.getCount()));
qryPart.setAt(KeyConstants._min, row, _toString(de.getMin()));
qryPart.setAt(KeyConstants._max, row, _toString(de.getMax()));
qryPart.setAt(KeyConstants._avg, row, _toString(de.getExeTime() / de.getCount()));
qryPart.setAt(KeyConstants._start, row, _toString(de.getStartPosition()));
qryPart.setAt(KeyConstants._end, row, _toString(de.getEndPosition()));
qryPart.setAt(KeyConstants._total, row, _toString(de.getExeTime()));
qryPart.setAt(KeyConstants._path, row, de.getPath());
if (de instanceof DebugEntryTemplatePartImpl) {
qryPart.setAt(KeyConstants._startLine, row, _toString(((DebugEntryTemplatePartImpl) de).getStartLine()));
qryPart.setAt(KeyConstants._endLine, row, _toString(((DebugEntryTemplatePartImpl) de).getEndLine()));
qryPart.setAt(KeyConstants._snippet, row, ((DebugEntryTemplatePartImpl) de).getSnippet());
}
}
} catch (PageException dbe) {
}
}
// exceptions
len = exceptions == null ? 0 : exceptions.size();
Array arrExceptions = new ArrayImpl();
if (len > 0) {
Iterator<CatchBlock> it = exceptions.iterator();
row = 0;
while (it.hasNext()) {
arrExceptions.appendEL(it.next());
}
}
// output log
// Query qryOutputLog=getOutputText();
// timers
len = timers == null ? 0 : timers.size();
Query qryTimers = new QueryImpl(new Collection.Key[] { KeyConstants._label, KeyConstants._time, KeyConstants._template }, len, "timers");
if (len > 0) {
try {
Iterator<DebugTimerImpl> it = timers.iterator();
DebugTimer timer;
row = 0;
while (it.hasNext()) {
timer = it.next();
row++;
qryTimers.setAt(KeyConstants._label, row, timer.getLabel());
qryTimers.setAt(KeyConstants._template, row, timer.getTemplate());
qryTimers.setAt(KeyConstants._time, row, Caster.toDouble(timer.getTime()));
}
} catch (PageException dbe) {
}
}
// dumps
len = dumps == null ? 0 : dumps.size();
if (!((ConfigImpl) pc.getConfig()).hasDebugOptions(ConfigImpl.DEBUG_DUMP))
len = 0;
Query qryDumps = new QueryImpl(new Collection.Key[] { KeyConstants._output, KeyConstants._template, KeyConstants._line }, len, "dumps");
if (len > 0) {
try {
Iterator<DebugDump> it = dumps.iterator();
DebugDump dd;
row = 0;
while (it.hasNext()) {
dd = it.next();
row++;
qryDumps.setAt(KeyConstants._output, row, dd.getOutput());
if (!StringUtil.isEmpty(dd.getTemplate()))
qryDumps.setAt(KeyConstants._template, row, dd.getTemplate());
if (dd.getLine() > 0)
qryDumps.setAt(KeyConstants._line, row, new Double(dd.getLine()));
}
} catch (PageException dbe) {
}
}
// traces
len = traces == null ? 0 : traces.size();
if (!((ConfigImpl) pc.getConfig()).hasDebugOptions(ConfigImpl.DEBUG_TRACING))
len = 0;
Query qryTraces = new QueryImpl(new Collection.Key[] { KeyConstants._type, KeyConstants._category, KeyConstants._text, KeyConstants._template, KeyConstants._line, KeyConstants._action, KeyConstants._varname, KeyConstants._varvalue, KeyConstants._time }, len, "traces");
if (len > 0) {
try {
Iterator<DebugTraceImpl> it = traces.iterator();
DebugTraceImpl trace;
row = 0;
while (it.hasNext()) {
trace = it.next();
row++;
qryTraces.setAt(KeyConstants._type, row, DebugTraceImpl.toType(trace.getType(), "INFO"));
if (!StringUtil.isEmpty(trace.getCategory()))
qryTraces.setAt(KeyConstants._category, row, trace.getCategory());
if (!StringUtil.isEmpty(trace.getText()))
qryTraces.setAt(KeyConstants._text, row, trace.getText());
if (!StringUtil.isEmpty(trace.getTemplate()))
qryTraces.setAt(KeyConstants._template, row, trace.getTemplate());
if (trace.getLine() > 0)
qryTraces.setAt(KeyConstants._line, row, new Double(trace.getLine()));
if (!StringUtil.isEmpty(trace.getAction()))
qryTraces.setAt(KeyConstants._action, row, trace.getAction());
if (!StringUtil.isEmpty(trace.getVarName()))
qryTraces.setAt(KeyImpl.init("varname"), row, trace.getVarName());
if (!StringUtil.isEmpty(trace.getVarValue()))
qryTraces.setAt(KeyImpl.init("varvalue"), row, trace.getVarValue());
qryTraces.setAt(KeyConstants._time, row, new Double(trace.getTime()));
}
} catch (PageException dbe) {
}
}
// scope access
len = implicitAccesses == null ? 0 : implicitAccesses.size();
Query qryImplicitAccesseses = new QueryImpl(new Collection.Key[] { KeyConstants._template, KeyConstants._line, KeyConstants._scope, KeyConstants._count, KeyConstants._name }, len, "implicitAccess");
if (len > 0) {
try {
Iterator<ImplicitAccessImpl> it = implicitAccesses.values().iterator();
ImplicitAccessImpl das;
row = 0;
while (it.hasNext()) {
das = it.next();
row++;
qryImplicitAccesseses.setAt(KeyConstants._template, row, das.getTemplate());
qryImplicitAccesseses.setAt(KeyConstants._line, row, new Double(das.getLine()));
qryImplicitAccesseses.setAt(KeyConstants._scope, row, das.getScope());
qryImplicitAccesseses.setAt(KeyConstants._count, row, new Double(das.getCount()));
qryImplicitAccesseses.setAt(KeyConstants._name, row, das.getName());
}
} catch (PageException dbe) {
}
}
Query history = new QueryImpl(new Collection.Key[] {}, 0, "history");
try {
history.addColumn(KeyConstants._id, historyId);
history.addColumn(KeyConstants._level, historyLevel);
} catch (PageException e) {
}
if (addAddionalInfo) {
debugging.setEL(KeyConstants._cgi, pc.cgiScope());
debugging.setEL(KeyImpl.init("starttime"), new DateTimeImpl(starttime, false));
debugging.setEL(KeyConstants._id, pc.getId());
}
debugging.setEL(KeyConstants._pages, qryPage);
debugging.setEL(PAGE_PARTS, qryPart);
debugging.setEL(KeyConstants._queries, qryQueries);
debugging.setEL(KeyConstants._timers, qryTimers);
debugging.setEL(KeyConstants._traces, qryTraces);
debugging.setEL("dumps", qryDumps);
debugging.setEL(IMPLICIT_ACCESS, qryImplicitAccesseses);
// debugging.setEL(OUTPUT_LOG,qryOutputLog);
debugging.setEL(KeyConstants._history, history);
debugging.setEL(KeyConstants._exceptions, arrExceptions);
return debugging;
}
Aggregations