use of lucee.runtime.db.JDBCDriver in project Lucee by lucee.
the class XMLConfigWebFactory method loadDataSources.
/**
* loads datasource settings from XMl DOM
*
* @param configServer
* @param config
* @param doc
* @throws BundleException
* @throws ClassNotFoundException
*/
private static void loadDataSources(ConfigServerImpl configServer, ConfigImpl config, Document doc, Log log) {
// load JDBC Driver defintion
{
Element jdbc = getChildByName(doc.getDocumentElement(), "jdbc");
Element[] drivers = getChildren(jdbc, "driver");
Map<String, JDBCDriver> map = new HashMap<String, JDBCDriver>();
// first add the server drivers, so they can be overwritten
if (configServer != null) {
JDBCDriver[] sds = configServer.getJDBCDrivers();
for (JDBCDriver sd : sds) {
map.put(sd.cd.toString(), sd);
}
}
ClassDefinition cd;
String label;
for (Element driver : drivers) {
cd = getClassDefinition(driver, "", config.getIdentification());
label = getAttr(driver, "label");
// check if label exists
if (StringUtil.isEmpty(label)) {
log.error("Datasource", "missing label for jdbc driver [" + cd.getClassName() + "]");
continue;
}
// check if it is a bundle
if (!cd.isBundle()) {
log.error("Datasource", "jdbc driver [" + label + "] does not describe a bundle");
continue;
}
map.put(cd.toString(), new JDBCDriver(label, cd));
}
config.setJDBCDrivers(map.values().toArray(new JDBCDriver[map.size()]));
}
// When set to true, makes JDBC use a representation for DATE data that
// is compatible with the Oracle8i database.
System.setProperty("oracle.jdbc.V8Compatible", "true");
boolean hasCS = configServer != null;
Map<String, DataSource> datasources = new HashMap<String, DataSource>();
// Copy Parent datasources as readOnly
if (hasCS) {
Map<String, DataSource> ds = configServer.getDataSourcesAsMap();
Iterator<Entry<String, DataSource>> it = ds.entrySet().iterator();
Entry<String, DataSource> entry;
while (it.hasNext()) {
entry = it.next();
if (!entry.getKey().equals(QOQ_DATASOURCE_NAME))
datasources.put(entry.getKey(), entry.getValue().cloneReadOnly());
}
}
// Default query of query DB
try {
setDatasource(config, datasources, QOQ_DATASOURCE_NAME, new ClassDefinitionImpl("org.hsqldb.jdbcDriver", "hsqldb", "1.8.0", config.getIdentification()), "hypersonic-hsqldb", "", -1, "jdbc:hsqldb:.", "sa", "", DEFAULT_MAX_CONNECTION, -1, 60000, true, true, DataSource.ALLOW_ALL, false, false, null, new StructImpl(), "", ParamSyntax.DEFAULT, false, false);
} catch (Exception e) {
log.error("Datasource", e);
}
SecurityManager sm = config.getSecurityManager();
short access = sm.getAccess(SecurityManager.TYPE_DATASOURCE);
int accessCount = -1;
if (access == SecurityManager.VALUE_YES)
accessCount = -1;
else if (access == SecurityManager.VALUE_NO)
accessCount = 0;
else if (access >= SecurityManager.VALUE_1 && access <= SecurityManager.VALUE_10) {
accessCount = access - SecurityManager.NUMBER_OFFSET;
}
// Databases
Element databases = getChildByName(doc.getDocumentElement(), "data-sources");
// if(databases==null)databases=doc.createElement("data-sources");
// PSQ
String strPSQ = getAttr(databases, "psq");
if (StringUtil.isEmpty(strPSQ)) {
// prior version was buggy, was the opposite
strPSQ = getAttr(databases, "preserve-single-quote");
if (!StringUtil.isEmpty(strPSQ)) {
Boolean b = Caster.toBoolean(strPSQ, null);
if (b != null)
strPSQ = b.booleanValue() ? "false" : "true";
}
}
if (access != SecurityManager.VALUE_NO && !StringUtil.isEmpty(strPSQ)) {
config.setPSQL(toBoolean(strPSQ, true));
} else if (hasCS)
config.setPSQL(configServer.getPSQL());
// Data Sources
Element[] dataSources = getChildren(databases, "data-source");
if (accessCount == -1)
accessCount = dataSources.length;
if (dataSources.length < accessCount)
accessCount = dataSources.length;
// if(hasAccess) {
ClassDefinition cd;
for (int i = 0; i < accessCount; i++) {
Element dataSource = dataSources[i];
if (dataSource.hasAttribute("database")) {
try {
cd = getClassDefinition(dataSource, "", config.getIdentification());
if (!cd.isBundle()) {
JDBCDriver jdbc = config.getJDBCDriverByClassName(cd.getClassName(), null);
if (jdbc != null)
cd = jdbc.cd;
}
setDatasource(config, datasources, getAttr(dataSource, "name"), cd, getAttr(dataSource, "host"), getAttr(dataSource, "database"), Caster.toIntValue(getAttr(dataSource, "port"), -1), getAttr(dataSource, "dsn"), getAttr(dataSource, "username"), ConfigWebUtil.decrypt(getAttr(dataSource, "password")), Caster.toIntValue(getAttr(dataSource, "connectionLimit"), DEFAULT_MAX_CONNECTION), Caster.toIntValue(getAttr(dataSource, "connectionTimeout"), -1), Caster.toLongValue(getAttr(dataSource, "metaCacheTimeout"), 60000), toBoolean(getAttr(dataSource, "blob"), true), toBoolean(getAttr(dataSource, "clob"), true), Caster.toIntValue(getAttr(dataSource, "allow"), DataSource.ALLOW_ALL), toBoolean(getAttr(dataSource, "validate"), false), toBoolean(getAttr(dataSource, "storage"), false), getAttr(dataSource, "timezone"), toStruct(getAttr(dataSource, "custom")), getAttr(dataSource, "dbdriver"), ParamSyntax.toParamSyntax(dataSource, ParamSyntax.DEFAULT), toBoolean(getAttr(dataSource, "literal-timestamp-with-tsoffset"), false), toBoolean(getAttr(dataSource, "always-set-timeout"), false));
} catch (Exception e) {
log.error("Datasource", e);
}
}
}
// }
config.setDataSources(datasources);
}
use of lucee.runtime.db.JDBCDriver in project Lucee by lucee.
the class Admin method doGetJDBCDrivers.
private void doGetJDBCDrivers() throws PageException {
JDBCDriver[] drivers = config.getJDBCDrivers();
lucee.runtime.type.Query qry = new QueryImpl(new Key[] { KeyConstants._label, KeyConstants._class, KeyConstants._bundleName, KeyConstants._bundleVersion }, drivers.length, "jdbc");
JDBCDriver driver;
for (int row = 0; row < drivers.length; row++) {
driver = drivers[row];
qry.setAt(KeyConstants._label, row, driver.label);
qry.setAt(KeyConstants._class, row, driver.cd.getClassName());
qry.setAt(KeyConstants._bundleName, row, driver.cd.getName());
qry.setAt(KeyConstants._bundleVersion, row, driver.cd.getVersion().toString());
}
pageContext.setVariable(getString("admin", action, "returnVariable"), qry);
}
Aggregations