use of lucee.runtime.exp.DatabaseException in project Lucee by lucee.
the class QuerySort method _call.
private static boolean _call(PageContext pc, Query query, String columnNames, String directions) throws PageException {
// column names
String[] arrColumnNames = ListUtil.trimItems(ListUtil.listToStringArray(columnNames, ','));
int[] dirs = new int[arrColumnNames.length];
// directions
if (!StringUtil.isEmpty(directions)) {
String[] arrDirections = ListUtil.trimItems(ListUtil.listToStringArray(directions, ','));
if (arrColumnNames.length != arrDirections.length)
throw new DatabaseException("column names and directions has not the same count", null, null, null);
String direction;
for (int i = 0; i < dirs.length; i++) {
direction = arrDirections[i].toLowerCase();
dirs[i] = 0;
if (direction.equals("asc"))
dirs[i] = Query.ORDER_ASC;
else if (direction.equals("desc"))
dirs[i] = Query.ORDER_DESC;
else {
throw new DatabaseException("argument direction of function querySort must be \"asc\" or \"desc\", now \"" + direction + "\"", null, null, null);
}
}
} else {
for (int i = 0; i < dirs.length; i++) {
dirs[i] = Query.ORDER_ASC;
}
}
for (int i = arrColumnNames.length - 1; i >= 0; i--) query.sort(KeyImpl.init(arrColumnNames[i]), dirs[i]);
return true;
}
use of lucee.runtime.exp.DatabaseException 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.exp.DatabaseException 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.exp.DatabaseException 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.exp.DatabaseException in project Lucee by lucee.
the class Schedule method doList.
/**
* @throws PageException
*/
private void doList() throws PageException {
// if(tr ue) throw new PageRuntimeException("qqq");
ScheduleTask[] tasks = scheduler.getAllScheduleTasks();
final String v = "VARCHAR";
String[] cols = new String[] { "task", "path", "file", "startdate", "starttime", "enddate", "endtime", "url", "port", "interval", "timeout", "username", "password", "proxyserver", "proxyport", "proxyuser", "proxypassword", "resolveurl", "publish", "valid", "paused", "autoDelete" };
String[] types = new String[] { v, v, v, "DATE", "OTHER", "DATE", "OTHER", v, v, v, v, v, v, v, v, v, v, v, "BOOLEAN", v, "BOOLEAN", "BOOLEAN" };
lucee.runtime.type.Query query = new QueryImpl(cols, types, tasks.length, "query");
try {
for (int i = 0; i < tasks.length; i++) {
int row = i + 1;
ScheduleTask task = tasks[i];
query.setAt(KeyConstants._task, row, task.getTask());
if (task.getResource() != null) {
query.setAt(KeyConstants._path, row, task.getResource().getParent());
query.setAt(KeyConstants._file, row, task.getResource().getName());
}
query.setAt("publish", row, Caster.toBoolean(task.isPublish()));
query.setAt("startdate", row, task.getStartDate());
query.setAt("starttime", row, task.getStartTime());
query.setAt("enddate", row, task.getEndDate());
query.setAt("endtime", row, task.getEndTime());
query.setAt(KeyConstants._url, row, printUrl(task.getUrl()));
query.setAt(KeyConstants._port, row, Caster.toString(HTTPUtil.getPort(task.getUrl())));
query.setAt("interval", row, task.getStringInterval());
query.setAt("timeout", row, Caster.toString(task.getTimeout() / 1000));
query.setAt("valid", row, Caster.toString(task.isValid()));
if (task.hasCredentials()) {
query.setAt("username", row, task.getCredentials().getUsername());
query.setAt("password", row, task.getCredentials().getPassword());
}
ProxyData pd = task.getProxyData();
if (ProxyDataImpl.isValid(pd)) {
query.setAt("proxyserver", row, pd.getServer());
if (pd.getPort() > 0)
query.setAt("proxyport", row, Caster.toString(pd.getPort()));
if (ProxyDataImpl.hasCredentials(pd)) {
query.setAt("proxyuser", row, pd.getUsername());
query.setAt("proxypassword", row, pd.getPassword());
}
}
query.setAt("resolveurl", row, Caster.toString(task.isResolveURL()));
query.setAt("paused", row, Caster.toBoolean(task.isPaused()));
query.setAt("autoDelete", row, Caster.toBoolean(((ScheduleTaskImpl) task).isAutoDelete()));
}
pageContext.setVariable(result, query);
} catch (DatabaseException e) {
}
}
Aggregations