diff --git a/core/src/main/java/lucee/commons/lang/ClassUtil.java b/core/src/main/java/lucee/commons/lang/ClassUtil.java index 5f94f52aac..f9a7eb4a81 100644 --- a/core/src/main/java/lucee/commons/lang/ClassUtil.java +++ b/core/src/main/java/lucee/commons/lang/ClassUtil.java @@ -346,8 +346,8 @@ public static Class loadClass(ClassLoader cl, String className) throws ClassExce * @return matching Class */ private static Class _loadClass(ClassLoading cl, String className, Class defaultValue, Set exceptions) { + if (StringUtil.isEmpty(className, true)) return defaultValue; className = className.trim(); - if (StringUtil.isEmpty(className)) return defaultValue; Class clazz = checkPrimaryTypesBytecodeDef(className, null); if (clazz != null) return clazz; diff --git a/core/src/main/java/lucee/runtime/config/ConfigWebFactory.java b/core/src/main/java/lucee/runtime/config/ConfigWebFactory.java index 791433f9f6..3a09fb1f74 100644 --- a/core/src/main/java/lucee/runtime/config/ConfigWebFactory.java +++ b/core/src/main/java/lucee/runtime/config/ConfigWebFactory.java @@ -2322,14 +2322,24 @@ else if (access >= SecurityManager.VALUE_1 && access <= SecurityManager.VALUE_10 jdbc = config.getJDBCDriverById(getAttr(dataSource, "id"), null); if (jdbc != null && jdbc.cd != null) { cd = jdbc.cd; + } + else { + cd = getClassDefinition(dataSource, "", config.getIdentification()); + } + // we have no class + if (!cd.hasClass()) { + jdbc = config.getJDBCDriverById(getAttr(dataSource, "type"), null); + if (jdbc != null && jdbc.cd != null) { + cd = jdbc.cd; + } } - else cd = getClassDefinition(dataSource, "", config.getIdentification()); // we only have a class - if (!cd.isBundle()) { + else if (!cd.isBundle()) { jdbc = config.getJDBCDriverByClassName(cd.getClassName(), null); if (jdbc != null && jdbc.cd != null && jdbc.cd.isBundle()) cd = jdbc.cd; } + // still no bundle! if (!cd.isBundle()) cd = patchJDBCClass(config, cd); int idle = Caster.toIntValue(getAttr(dataSource, "idleTimeout"), -1); @@ -2337,10 +2347,23 @@ else if (access >= SecurityManager.VALUE_1 && access <= SecurityManager.VALUE_10 int defLive = 15; if (idle > 0) defLive = idle * 5;// for backward compatibility + String dsn = getAttr(dataSource, "connectionString"); + if (StringUtil.isEmpty(dsn, true)) dsn = getAttr(dataSource, "dsn"); + if (StringUtil.isEmpty(dsn, true)) dsn = getAttr(dataSource, "connStr"); + if (StringUtil.isEmpty(dsn, true)) dsn = getAttr(dataSource, "url"); + if (StringUtil.isEmpty(dsn, true)) { + if (jdbc == null && cd.hasClass()) { + jdbc = config.getJDBCDriverByClassName(cd.getClassName(), null); + } + if (jdbc != null) { + dsn = jdbc.connStr; + } + + } setDatasource(config, datasources, e.getKey().getString(), cd, getAttr(dataSource, "host"), getAttr(dataSource, "database"), - Caster.toIntValue(getAttr(dataSource, "port"), -1), getAttr(dataSource, "dsn"), getAttr(dataSource, "username"), - ConfigWebUtil.decrypt(getAttr(dataSource, "password")), null, Caster.toIntValue(getAttr(dataSource, "connectionLimit"), DEFAULT_MAX_CONNECTION), - idle, Caster.toIntValue(getAttr(dataSource, "liveTimeout"), defLive), Caster.toIntValue(getAttr(dataSource, "minIdle"), 0), + Caster.toIntValue(getAttr(dataSource, "port"), -1), dsn, getAttr(dataSource, "username"), ConfigWebUtil.decrypt(getAttr(dataSource, "password")), + null, Caster.toIntValue(getAttr(dataSource, "connectionLimit"), DEFAULT_MAX_CONNECTION), idle, + Caster.toIntValue(getAttr(dataSource, "liveTimeout"), defLive), Caster.toIntValue(getAttr(dataSource, "minIdle"), 0), Caster.toIntValue(getAttr(dataSource, "maxIdle"), 0), Caster.toIntValue(getAttr(dataSource, "maxTotal"), 0), Caster.toLongValue(getAttr(dataSource, "metaCacheTimeout"), 60000), toBoolean(getAttr(dataSource, "blob"), true), toBoolean(getAttr(dataSource, "clob"), true), Caster.toIntValue(getAttr(dataSource, "allow"), DataSource.ALLOW_ALL), diff --git a/core/src/main/java/lucee/runtime/db/JDBCDriver.java b/core/src/main/java/lucee/runtime/db/JDBCDriver.java index 54c3aea3b9..d06a716a05 100644 --- a/core/src/main/java/lucee/runtime/db/JDBCDriver.java +++ b/core/src/main/java/lucee/runtime/db/JDBCDriver.java @@ -37,11 +37,26 @@ public class JDBCDriver { public JDBCDriver(String label, String id, String connStr, ClassDefinition cd) { this.label = label; - this.id = StringUtil.isEmpty(id) ? null : id.trim(); - this.connStr = StringUtil.isEmpty(connStr) ? null : connStr.trim(); + this.id = StringUtil.isEmpty(id, true) ? null : id.trim(); + this.connStr = StringUtil.isEmpty(connStr, true) ? getById(id) : connStr.trim(); this.cd = cd; } + private static String getById(String id) { + // FUTURE PATCH add to driver itself + if ("hsqldb".equalsIgnoreCase(id)) return "jdbc:hsqldb:file:{path}{database}"; + if ("exasol".equalsIgnoreCase(id)) return "jdbc:exa:{host}:{port}"; + if ("teradata".equalsIgnoreCase(id)) return "jdbc:teradata://{host}"; + if ("jtds".equalsIgnoreCase(id)) return "jdbc:jtds:sqlserver://{host}:{port}/{database}"; + if ("h2".equalsIgnoreCase(id)) return "jdbc:h2:{path}{database};MODE={mode}"; + if ("mysql".equalsIgnoreCase(id)) return "jdbc:mysql://{host}:{port}/{database}"; + if ("postgresql".equalsIgnoreCase(id)) return "jdbc:postgresql://{host}:{port}/{database}"; + if ("mssql".equalsIgnoreCase(id)) return "jdbc:sqlserver://{host}:{port}"; + if ("oracle".equalsIgnoreCase(id)) return "jdbc:oracle:{drivertype}:@{host}:{port}:{database}"; + if ("derby".equalsIgnoreCase(id)) return "jdbc:derby:{mode}:{path}{database}"; + return null; + } + public static String extractClassName(Bundle bundle) throws IOException { URL url = bundle.getResource("/META-INF/services/java.sql.Driver"); diff --git a/loader/build.xml b/loader/build.xml index cf74eab2f8..171d90b33b 100644 --- a/loader/build.xml +++ b/loader/build.xml @@ -2,7 +2,7 @@ - + diff --git a/loader/pom.xml b/loader/pom.xml index f58d6a0f02..5f8a963644 100644 --- a/loader/pom.xml +++ b/loader/pom.xml @@ -3,7 +3,7 @@ org.lucee lucee - 6.0.3.3-SNAPSHOT + 6.0.4.1-SNAPSHOT jar Lucee Loader Build