use of lucee.runtime.db.DataSourceImpl in project Lucee by lucee.
the class Query method doStartTag.
@Override
public int doStartTag() throws PageException {
// default datasource
if (datasource == null && (dbtype == null || !dbtype.equals("query"))) {
Object obj = pageContext.getApplicationContext().getDefDataSource();
if (StringUtil.isEmpty(obj)) {
boolean isCFML = pageContext.getRequestDialect() == CFMLEngine.DIALECT_CFML;
throw new ApplicationException("attribute [datasource] is required when attribute [dbtype] is not [query] and no default datasource is defined", "you can define a default datasource as attribute [defaultdatasource] of the tag " + (isCFML ? Constants.CFML_APPLICATION_TAG_NAME : Constants.LUCEE_APPLICATION_TAG_NAME) + " or as data member of the " + (isCFML ? Constants.CFML_APPLICATION_EVENT_HANDLER : Constants.LUCEE_APPLICATION_EVENT_HANDLER) + " (this.defaultdatasource=\"mydatasource\";)");
}
datasource = obj instanceof DataSource ? (DataSource) obj : pageContext.getDataSource(Caster.toString(obj));
}
// timeout
if (datasource instanceof DataSourceImpl && ((DataSourceImpl) datasource).getAlwaysSetTimeout()) {
TimeSpan remaining = PageContextUtil.remainingTime(pageContext, true);
if (this.timeout == null || ((int) this.timeout.getSeconds()) <= 0 || timeout.getSeconds() > remaining.getSeconds()) {
// not set
this.timeout = remaining;
}
}
// timezone
if (timezone != null || (datasource != null && (timezone = datasource.getTimeZone()) != null)) {
tmpTZ = pageContext.getTimeZone();
pageContext.setTimeZone(timezone);
}
PageContextImpl pci = ((PageContextImpl) pageContext);
// cache within
if (StringUtil.isEmpty(cachedWithin)) {
Object tmp = (pageContext).getCachedWithin(ConfigWeb.CACHEDWITHIN_QUERY);
if (tmp != null)
setCachedwithin(tmp);
}
// literal timestamp with TSOffset
if (datasource instanceof DataSourceImpl)
literalTimestampWithTSOffset = ((DataSourceImpl) datasource).getLiteralTimestampWithTSOffset();
else
literalTimestampWithTSOffset = false;
previousLiteralTimestampWithTSOffset = pci.getTimestampWithTSOffset();
pci.setTimestampWithTSOffset(literalTimestampWithTSOffset);
return EVAL_BODY_BUFFERED;
}
use of lucee.runtime.db.DataSourceImpl in project Lucee by lucee.
the class Admin method doGetDatasource.
/**
* @throws PageException
*/
private void doGetDatasource() throws PageException {
String name = getString("admin", action, "name");
Map ds = config.getDataSourcesAsMap();
Iterator it = ds.keySet().iterator();
while (it.hasNext()) {
String key = (String) it.next();
if (key.equalsIgnoreCase(name)) {
DataSource d = (DataSource) ds.get(key);
Struct sct = new StructImpl();
ClassDefinition cd = d.getClassDefinition();
sct.setEL(KeyConstants._name, key);
sct.setEL(KeyConstants._host, d.getHost());
sct.setEL("classname", cd.getClassName());
sct.setEL("class", cd.getClassName());
sct.setEL("bundleName", cd.getName());
sct.setEL("bundleVersion", cd.getVersionAsString());
sct.setEL("dsn", d.getDsnOriginal());
sct.setEL("database", d.getDatabase());
sct.setEL("port", d.getPort() < 1 ? "" : Caster.toString(d.getPort()));
sct.setEL("dsnTranslated", d.getDsnTranslated());
sct.setEL("timezone", toStringTimeZone(d.getTimeZone()));
sct.setEL("password", d.getPassword());
sct.setEL("passwordEncrypted", ConfigWebUtil.encrypt(d.getPassword()));
sct.setEL("username", d.getUsername());
sct.setEL("readonly", Caster.toBoolean(d.isReadOnly()));
sct.setEL("select", Boolean.valueOf(d.hasAllow(DataSource.ALLOW_SELECT)));
sct.setEL("delete", Boolean.valueOf(d.hasAllow(DataSource.ALLOW_DELETE)));
sct.setEL("update", Boolean.valueOf(d.hasAllow(DataSource.ALLOW_UPDATE)));
sct.setEL("insert", Boolean.valueOf(d.hasAllow(DataSource.ALLOW_INSERT)));
sct.setEL("create", Boolean.valueOf(d.hasAllow(DataSource.ALLOW_CREATE)));
sct.setEL("insert", Boolean.valueOf(d.hasAllow(DataSource.ALLOW_INSERT)));
sct.setEL("drop", Boolean.valueOf(d.hasAllow(DataSource.ALLOW_DROP)));
sct.setEL("grant", Boolean.valueOf(d.hasAllow(DataSource.ALLOW_GRANT)));
sct.setEL("revoke", Boolean.valueOf(d.hasAllow(DataSource.ALLOW_REVOKE)));
sct.setEL("alter", Boolean.valueOf(d.hasAllow(DataSource.ALLOW_ALTER)));
sct.setEL("connectionLimit", d.getConnectionLimit() < 1 ? "" : Caster.toString(d.getConnectionLimit()));
sct.setEL("connectionTimeout", d.getConnectionTimeout() < 1 ? "" : Caster.toString(d.getConnectionTimeout()));
sct.setEL("metaCacheTimeout", Caster.toDouble(d.getMetaCacheTimeout()));
sct.setEL("custom", d.getCustoms());
sct.setEL("blob", Boolean.valueOf(d.isBlob()));
sct.setEL("clob", Boolean.valueOf(d.isClob()));
sct.setEL("validate", Boolean.valueOf(d.validate()));
sct.setEL("storage", Boolean.valueOf(d.isStorage()));
if (d instanceof DataSourceImpl) {
DataSourceImpl di = ((DataSourceImpl) d);
sct.setEL("literalTimestampWithTSOffset", Boolean.valueOf(di.getLiteralTimestampWithTSOffset()));
sct.setEL("alwaysSetTimeout", Boolean.valueOf(di.getAlwaysSetTimeout()));
sct.setEL("dbdriver", Caster.toString(di.getDbDriver(), ""));
}
pageContext.setVariable(getString("admin", action, "returnVariable"), sct);
return;
}
}
throw new ApplicationException("there is no datasource with name [" + name + "]");
}
use of lucee.runtime.db.DataSourceImpl in project Lucee by lucee.
the class Admin method doUpdateDatasource.
/**
* @throws PageException
*/
private void doUpdateDatasource() throws PageException {
int allow = (getBoolV("allowed_select", false) ? DataSource.ALLOW_SELECT : 0) + (getBoolV("allowed_insert", false) ? DataSource.ALLOW_INSERT : 0) + (getBoolV("allowed_update", false) ? DataSource.ALLOW_UPDATE : 0) + (getBoolV("allowed_delete", false) ? DataSource.ALLOW_DELETE : 0) + (getBoolV("allowed_alter", false) ? DataSource.ALLOW_ALTER : 0) + (getBoolV("allowed_drop", false) ? DataSource.ALLOW_DROP : 0) + (getBoolV("allowed_revoke", false) ? DataSource.ALLOW_REVOKE : 0) + (getBoolV("allowed_grant", false) ? DataSource.ALLOW_GRANT : 0) + (getBoolV("allowed_create", false) ? DataSource.ALLOW_CREATE : 0);
if (allow == 0)
allow = DataSource.ALLOW_ALL;
String cn = getString("admin", action, "classname");
if ("com.microsoft.jdbc.sqlserver.SQLServerDriver".equals(cn)) {
cn = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
}
ClassDefinition cd = new ClassDefinitionImpl(cn, getString("bundleName", null), getString("bundleVersion", null), config.getIdentification());
// customParameterSyntax
Struct sct = getStruct("customParameterSyntax", null);
ParamSyntax ps = (sct != null && sct.containsKey("delimiter") && sct.containsKey("separator")) ? ParamSyntax.toParamSyntax(sct) : ParamSyntax.DEFAULT;
//
boolean literalTimestampWithTSOffset = getBoolV("literalTimestampWithTSOffset", false);
boolean alwaysSetTimeout = getBoolV("alwaysSetTimeout", false);
String dsn = getString("admin", action, "dsn");
String name = getString("admin", action, "name");
String newName = getString("admin", action, "newName");
String username = getString("admin", action, "dbusername");
String password = getString("admin", action, "dbpassword");
String host = getString("host", "");
String timezone = getString("timezone", "");
String database = getString("database", "");
int port = getInt("port", -1);
int connLimit = getInt("connectionLimit", -1);
int connTimeout = getInt("connectionTimeout", -1);
long metaCacheTimeout = getLong("metaCacheTimeout", 60000);
boolean blob = getBoolV("blob", false);
boolean clob = getBoolV("clob", false);
boolean validate = getBoolV("validate", false);
boolean storage = getBoolV("storage", false);
boolean verify = getBoolV("verify", true);
Struct custom = getStruct("custom", new StructImpl());
String dbdriver = getString("dbdriver", "");
// config.getDatasourceConnectionPool().remove(name);
DataSource ds = null;
try {
ds = new DataSourceImpl(config, null, name, cd, host, dsn, database, port, username, password, connLimit, connTimeout, metaCacheTimeout, blob, clob, allow, custom, false, validate, storage, null, dbdriver, ps, literalTimestampWithTSOffset, alwaysSetTimeout, config.getLog("application"));
} catch (Exception e) {
throw Caster.toPageException(e);
}
if (verify)
_doVerifyDatasource(ds, username, password);
// print.out("limit:"+connLimit);
admin.updateDataSource(name, newName, cd, dsn, username, password, host, database, port, connLimit, connTimeout, metaCacheTimeout, blob, clob, allow, validate, storage, timezone, custom, dbdriver, ps, literalTimestampWithTSOffset, alwaysSetTimeout);
store();
adminSync.broadcast(attributes, config);
}
use of lucee.runtime.db.DataSourceImpl in project Lucee by lucee.
the class AppListenerUtil method toDataSource.
public static DataSource toDataSource(Config config, String name, Struct data, Log log) throws PageException {
String user = Caster.toString(data.get(KeyConstants._username, null), null);
String pass = Caster.toString(data.get(KeyConstants._password, ""), "");
if (StringUtil.isEmpty(user)) {
user = null;
pass = null;
} else {
user = user.trim();
pass = pass.trim();
}
// first check for {class:... , connectionString:...}
Object oConnStr = data.get(CONNECTION_STRING, null);
if (oConnStr != null) {
String className = Caster.toString(data.get(KeyConstants._class));
if ("com.microsoft.jdbc.sqlserver.SQLServerDriver".equals(className)) {
className = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
}
ClassDefinition cd = new ClassDefinitionImpl(className, Caster.toString(data.get(KeyConstants._bundleName, null), null), Caster.toString(data.get(KeyConstants._bundleVersion, null), null), ThreadLocalPageContext.getConfig().getIdentification());
try {
return ApplicationDataSource.getInstance(config, name, cd, Caster.toString(oConnStr), user, pass, Caster.toBooleanValue(data.get(BLOB, null), false), Caster.toBooleanValue(data.get(CLOB, null), false), Caster.toIntValue(data.get(CONNECTION_LIMIT, null), -1), Caster.toIntValue(data.get(CONNECTION_TIMEOUT, null), 1), Caster.toLongValue(data.get(META_CACHE_TIMEOUT, null), 60000L), Caster.toTimeZone(data.get(TIMEZONE, null), null), Caster.toIntValue(data.get(ALLOW, null), DataSource.ALLOW_ALL), Caster.toBooleanValue(data.get(STORAGE, null), false), Caster.toBooleanValue(data.get(READ_ONLY, null), false), log);
} catch (Exception cnfe) {
throw Caster.toPageException(cnfe);
}
}
// then for {type:... , host:... , ...}
String type = Caster.toString(data.get(KeyConstants._type));
DataSourceDefintion dbt = DBUtil.getDataSourceDefintionForType(type, null);
if (dbt == null)
throw new ApplicationException("no datasource type [" + type + "] found");
try {
return new DataSourceImpl(config, null, name, dbt.classDefinition, Caster.toString(data.get(KeyConstants._host)), dbt.connectionString, Caster.toString(data.get(DATABASE)), Caster.toIntValue(data.get(KeyConstants._port, null), -1), user, pass, Caster.toIntValue(data.get(CONNECTION_LIMIT, null), -1), Caster.toIntValue(data.get(CONNECTION_TIMEOUT, null), 1), Caster.toLongValue(data.get(META_CACHE_TIMEOUT, null), 60000L), Caster.toBooleanValue(data.get(BLOB, null), false), Caster.toBooleanValue(data.get(CLOB, null), false), DataSource.ALLOW_ALL, Caster.toStruct(data.get(KeyConstants._custom, null), null, false), Caster.toBooleanValue(data.get(READ_ONLY, null), false), true, Caster.toBooleanValue(data.get(STORAGE, null), false), Caster.toTimeZone(data.get(TIMEZONE, null), null), "", ParamSyntax.toParamSyntax(data, ParamSyntax.DEFAULT), Caster.toBooleanValue(data.get("literalTimestampWithTSOffset", null), false), Caster.toBooleanValue(data.get("alwaysSetTimeout", null), false), log);
} catch (Exception cnfe) {
throw Caster.toPageException(cnfe);
}
}
Aggregations