diff --git a/boost-common/src/main/java/boost/common/boosters/JDBCBoosterConfig.java b/boost-common/src/main/java/boost/common/boosters/JDBCBoosterConfig.java index 4373edc2..65fa0ca7 100644 --- a/boost-common/src/main/java/boost/common/boosters/JDBCBoosterConfig.java +++ b/boost-common/src/main/java/boost/common/boosters/JDBCBoosterConfig.java @@ -13,6 +13,7 @@ import static boost.common.config.ConfigConstants.*; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; @@ -25,24 +26,41 @@ @BoosterCoordinates(AbstractBoosterConfig.BOOSTERS_GROUP_ID + ":jdbc") public class JDBCBoosterConfig extends AbstractBoosterConfig { - - public static String DERBY = "derby"; - public static String DB2 = "db2"; - public static String MYSQL = "mysql"; - + + public static final String DB2_DEFAULT_PORT_NUMBER = "50000"; + public static final String MYSQL_DEFAULT_PORT_NUMBER = "3306"; + public static final String POSTGRESQL_DEFAULT_PORT_NUMBER = "5432"; + + //Assumption in TomEE is that "driverName" = part of URL prefix as in "jdbc::..." for DataSource URL + // Maybe a better name than "driverName would be URL prefix portion or something. + public static String DERBY_DRIVER_CLASS_NAME = "org.apache.derby.jdbc.EmbeddedDriver"; public static String DB2_DRIVER_CLASS_NAME = "com.ibm.db2.jcc.DB2Driver"; public static String MYSQL_DRIVER_CLASS_NAME = "com.mysql.cj.jdbc.Driver"; - - public static String DERBY_DEPENDENCY = "org.apache.derby:derby"; - public static String DB2_DEPENDENCY = "com.ibm.db2.jcc:db2jcc"; - public static String MYSQL_DEPENDENCY = "mysql:mysql-connector-java"; - - private static String DERBY_DEFAULT = "org.apache.derby:derby:10.14.2.0"; + public static String POSTGRESQL_DRIVER_CLASS_NAME = "org.postgresql.Driver"; + + public static String DERBY_GROUP_ID = "org.apache.derby"; + public static String DERBY_ARTIFACT_ID = "derby"; + public static String DERBY_DRIVER_NAME = "derby"; + public static String DB2_GROUP_ID = "com.ibm.db2.jcc"; + public static String DB2_ARTIFACT_ID = "db2jcc"; + public static String DB2_DRIVER_NAME = "db2"; + public static String MYSQL_GROUP_ID = "mysql"; + public static String MYSQL_ARTIFACT_ID = "mysql-connector-java"; + public static String MYSQL_DRIVER_NAME = "mysql"; + public static String POSTGRESQL_GROUP_ID = "org.postgresql"; + public static String POSTGRESQL_ARTIFACT_ID = "postgresql"; + public static String POSTGRESQL_DRIVER_NAME = "postgresql"; + + public static String DERBY_DEFAULT_VERSION = "10.14.2.0"; + + public static String DRIVER_CLASS_NAME = "driverClassName"; + public static String DRIVER_NAME = "driverName"; + public static String DRIVER_JAR = "driverJar"; protected Properties boostConfigProperties; private String dependency; - private String productName; + private Map driverInfo; public JDBCBoosterConfig(BoosterConfigParams params, BoostLoggerI logger) throws BoostException { super(params.getProjectDependencies().get(getCoordinates(JDBCBoosterConfig.class))); @@ -50,25 +68,46 @@ public JDBCBoosterConfig(BoosterConfigParams params, BoostLoggerI logger) throws Map projectDependencies = params.getProjectDependencies(); this.boostConfigProperties = params.getBoostProperties(); - // Determine JDBC driver dependency - if (projectDependencies.containsKey(JDBCBoosterConfig.DERBY_DEPENDENCY)) { - String derbyVersion = projectDependencies.get(JDBCBoosterConfig.DERBY_DEPENDENCY); - this.dependency = JDBCBoosterConfig.DERBY_DEPENDENCY + ":" + derbyVersion; - this.productName = DERBY; + driverInfo = new HashMap(); + + if (projectDependencies.containsKey(DERBY_GROUP_ID + ":" + DERBY_ARTIFACT_ID)) { + String version = projectDependencies.get(DERBY_GROUP_ID + ":" + DERBY_ARTIFACT_ID); + dependency = DERBY_GROUP_ID + ":" + DERBY_ARTIFACT_ID + ":" + version; + + driverInfo.put(DRIVER_NAME, DERBY_DRIVER_NAME); + driverInfo.put(DRIVER_CLASS_NAME, DERBY_DRIVER_CLASS_NAME); + driverInfo.put(DRIVER_JAR, DERBY_ARTIFACT_ID + "-" + version + ".jar"); + + } else if (projectDependencies.containsKey(DB2_GROUP_ID + ":" + DB2_ARTIFACT_ID)) { + String version = projectDependencies.get(DB2_GROUP_ID + ":" + DB2_ARTIFACT_ID); + dependency = DB2_GROUP_ID + ":" + DB2_ARTIFACT_ID + ":" + version; - } else if (projectDependencies.containsKey(JDBCBoosterConfig.DB2_DEPENDENCY)) { - String db2Version = projectDependencies.get(JDBCBoosterConfig.DB2_DEPENDENCY); - this.dependency = JDBCBoosterConfig.DB2_DEPENDENCY + ":" + db2Version; - this.productName = DB2; + driverInfo.put(DRIVER_NAME, DB2_DRIVER_NAME); + driverInfo.put(DRIVER_CLASS_NAME, DB2_DRIVER_CLASS_NAME); + driverInfo.put(DRIVER_JAR, DB2_ARTIFACT_ID + "-" + version + ".jar"); - } else if (projectDependencies.containsKey(JDBCBoosterConfig.MYSQL_DEPENDENCY)) { - String mysqlVersion = projectDependencies.get(JDBCBoosterConfig.MYSQL_DEPENDENCY); - this.dependency = JDBCBoosterConfig.MYSQL_DEPENDENCY + ":" + mysqlVersion; - this.productName = MYSQL; + } else if (projectDependencies.containsKey(MYSQL_GROUP_ID + ":" + MYSQL_ARTIFACT_ID)) { + String version = projectDependencies.get(MYSQL_GROUP_ID + ":" + MYSQL_ARTIFACT_ID); + dependency = MYSQL_GROUP_ID + ":" + MYSQL_ARTIFACT_ID + ":" + version; + + driverInfo.put(DRIVER_NAME, MYSQL_DRIVER_NAME); + driverInfo.put(DRIVER_CLASS_NAME, MYSQL_DRIVER_CLASS_NAME); + driverInfo.put(DRIVER_JAR, MYSQL_ARTIFACT_ID + "-" + version + ".jar"); + + } else if (projectDependencies.containsKey(POSTGRESQL_GROUP_ID + ":" + POSTGRESQL_ARTIFACT_ID)) { + String version = projectDependencies.get(POSTGRESQL_GROUP_ID + ":" + POSTGRESQL_ARTIFACT_ID); + dependency = POSTGRESQL_GROUP_ID + ":" + POSTGRESQL_ARTIFACT_ID + ":" + version; + + driverInfo.put(DRIVER_NAME, POSTGRESQL_DRIVER_NAME); + driverInfo.put(DRIVER_CLASS_NAME, POSTGRESQL_DRIVER_CLASS_NAME); + driverInfo.put(DRIVER_JAR, POSTGRESQL_ARTIFACT_ID + "-" + version + ".jar"); } else { - this.dependency = DERBY_DEFAULT; - this.productName = DERBY; + dependency = DERBY_GROUP_ID + ":" + DERBY_ARTIFACT_ID + ":" + DERBY_DEFAULT_VERSION; + + driverInfo.put(DRIVER_NAME, DERBY_DRIVER_NAME); + driverInfo.put(DRIVER_CLASS_NAME, DERBY_DRIVER_CLASS_NAME); + driverInfo.put(DRIVER_JAR, DERBY_ARTIFACT_ID + "-" + DERBY_DEFAULT_VERSION + ".jar"); } } @@ -84,23 +123,28 @@ public Properties getDatasourceProperties() { } } + // TODO: Are defaults adding any value here? Should we just eliminate them? if (!datasourceProperties.containsKey(BoostProperties.DATASOURCE_URL) && !datasourceProperties.containsKey(BoostProperties.DATASOURCE_DATABASE_NAME) && !datasourceProperties.containsKey(BoostProperties.DATASOURCE_SERVER_NAME) && !datasourceProperties.containsKey(BoostProperties.DATASOURCE_PORT_NUMBER)) { // No db connection properties have been specified. Set defaults. - if (productName.equals(DERBY)) { + if (dependency.contains(DERBY_GROUP_ID)) { datasourceProperties.put(BoostProperties.DATASOURCE_DATABASE_NAME, DERBY_DB); datasourceProperties.put(BoostProperties.DATASOURCE_CREATE_DATABASE, "create"); - } else if (productName.equals(DB2)) { + } else if (dependency.contains(DB2_GROUP_ID)) { datasourceProperties.put(BoostProperties.DATASOURCE_URL, "jdbc:db2://localhost:" + DB2_DEFAULT_PORT_NUMBER); - } else if (productName.equals(MYSQL)) { + } else if (dependency.contains(MYSQL_GROUP_ID)) { datasourceProperties.put(BoostProperties.DATASOURCE_URL, "jdbc:mysql://localhost:" + MYSQL_DEFAULT_PORT_NUMBER); + + } else if (dependency.contains(POSTGRESQL_GROUP_ID)) { + datasourceProperties.put(BoostProperties.DATASOURCE_URL, + "jdbc:postgresql://localhost:" + POSTGRESQL_DEFAULT_PORT_NUMBER); } } return datasourceProperties; @@ -114,7 +158,8 @@ public List getDependencies() { return deps; } - public String getProductName() { - return productName; + public Map getDriverInfo() { + return driverInfo; } } + diff --git a/boost-common/src/main/java/boost/common/config/ConfigConstants.java b/boost-common/src/main/java/boost/common/config/ConfigConstants.java index 65cce403..099f5ab0 100644 --- a/boost-common/src/main/java/boost/common/config/ConfigConstants.java +++ b/boost-common/src/main/java/boost/common/config/ConfigConstants.java @@ -53,6 +53,7 @@ public final class ConfigConstants { public static final String FILESET = "fileset"; public static final String PROPERTIES_DERBY_EMBEDDED = "properties.derby.embedded"; public static final String PROPERTIES_DB2_JCC = "properties.db2.jcc"; + public static final String PROPERTIES_POSTGRESQL = "properties.postgresql"; public static final String PROPERTIES = "properties"; public static final String CONTAINER_AUTH_DATA_REF = "containerAuthDataRef"; public static final String URL = "url"; @@ -63,11 +64,6 @@ public final class ConfigConstants { public static final String JDBC_LIBRARY_1 = "Library1"; public static final String DERBY_DB = "DerbyDB"; public static final String DATASOURCE_AUTH_DATA = "datasourceAuth"; - public static final String DERBY_JAR = "derby*.jar"; - public static final String DB2_JAR = "db2jcc*.jar"; - public static final String MYSQL_JAR = "mysql*.jar"; - public static final String DB2_DEFAULT_PORT_NUMBER = "50000"; - public static final String MYSQL_DEFAULT_PORT_NUMBER = "3306"; // Authentication configuration element/attribute names public static final String AUTH_DATA = "authData"; diff --git a/boost-maven/boost-runtimes/runtime-openliberty/src/main/java/boost/runtimes/openliberty/LibertyServerConfigGenerator.java b/boost-maven/boost-runtimes/runtime-openliberty/src/main/java/boost/runtimes/openliberty/LibertyServerConfigGenerator.java index e4abf253..899c5402 100644 --- a/boost-maven/boost-runtimes/runtime-openliberty/src/main/java/boost/runtimes/openliberty/LibertyServerConfigGenerator.java +++ b/boost-maven/boost-runtimes/runtime-openliberty/src/main/java/boost/runtimes/openliberty/LibertyServerConfigGenerator.java @@ -312,19 +312,18 @@ public boolean isEncoded(String property) { return property.contains("{aes}") || property.contains("{hash}") || property.contains("{xor}"); } - public void addDataSource(String productName, Properties datasourceProperties) throws Exception { - String driverJar = null; + public void addDataSource(Map driverInfo, Properties datasourceProperties) throws Exception { String datasourcePropertiesElement = null; - if (productName.equals(JDBCBoosterConfig.DERBY)) { - driverJar = DERBY_JAR; + String driverName = driverInfo.get(JDBCBoosterConfig.DRIVER_NAME); + if (driverName.equals(JDBCBoosterConfig.DERBY_DRIVER_NAME)) { datasourcePropertiesElement = PROPERTIES_DERBY_EMBEDDED; - } else if (productName.equals(JDBCBoosterConfig.DB2)) { - driverJar = DB2_JAR; + } else if (driverName.equals(JDBCBoosterConfig.DB2_DRIVER_NAME)) { datasourcePropertiesElement = PROPERTIES_DB2_JCC; - } else if (productName.equals(JDBCBoosterConfig.MYSQL)) { - driverJar = MYSQL_JAR; + } else if (driverName.equals(JDBCBoosterConfig.MYSQL_DRIVER_NAME)) { datasourcePropertiesElement = PROPERTIES; + } else if (driverName.equals(JDBCBoosterConfig.POSTGRESQL_DRIVER_NAME)) { + datasourcePropertiesElement = PROPERTIES_POSTGRESQL; } // Add library @@ -332,7 +331,7 @@ public void addDataSource(String productName, Properties datasourceProperties) t lib.setAttribute("id", JDBC_LIBRARY_1); Element fileLoc = serverXml.createElement(FILESET); fileLoc.setAttribute("dir", RESOURCES); - fileLoc.setAttribute("includes", driverJar); + fileLoc.setAttribute("includes", driverInfo.get(JDBCBoosterConfig.DRIVER_JAR)); lib.appendChild(fileLoc); serverRoot.appendChild(lib); diff --git a/boost-maven/boost-runtimes/runtime-openliberty/src/main/java/boost/runtimes/openliberty/boosters/LibertyJDBCBoosterConfig.java b/boost-maven/boost-runtimes/runtime-openliberty/src/main/java/boost/runtimes/openliberty/boosters/LibertyJDBCBoosterConfig.java index 309f5fbf..548d55f2 100644 --- a/boost-maven/boost-runtimes/runtime-openliberty/src/main/java/boost/runtimes/openliberty/boosters/LibertyJDBCBoosterConfig.java +++ b/boost-maven/boost-runtimes/runtime-openliberty/src/main/java/boost/runtimes/openliberty/boosters/LibertyJDBCBoosterConfig.java @@ -47,7 +47,7 @@ public String getFeature() { @Override public void addServerConfig(LibertyServerConfigGenerator libertyServerConfigGenerator) throws BoostException { try { - libertyServerConfigGenerator.addDataSource(getProductName(), getDatasourceProperties()); + libertyServerConfigGenerator.addDataSource(getDriverInfo(), getDatasourceProperties()); } catch (Exception e) { throw new BoostException("Error when configuring JDBC data source.", e); } diff --git a/boost-maven/boost-runtimes/runtime-openliberty/src/test/java/io/openliberty/boost/runtimes/config/LibertyServerConfigGeneratorTest.java b/boost-maven/boost-runtimes/runtime-openliberty/src/test/java/io/openliberty/boost/runtimes/config/LibertyServerConfigGeneratorTest.java index 4ce2da41..7405072e 100644 --- a/boost-maven/boost-runtimes/runtime-openliberty/src/test/java/io/openliberty/boost/runtimes/config/LibertyServerConfigGeneratorTest.java +++ b/boost-maven/boost-runtimes/runtime-openliberty/src/test/java/io/openliberty/boost/runtimes/config/LibertyServerConfigGeneratorTest.java @@ -54,6 +54,7 @@ public class LibertyServerConfigGeneratorTest { BoostLoggerI logger = CommonLogger.getInstance(); private final String MYSQL_URL = "jdbc:mysql://localhost:3306/testdb"; + private final String POSTGRESQL_URL = "jdbc:postgresql://localhost:5432/testdb"; private final String DB2_URL = "jdbc:db2://localhost:50000/testdb"; /** @@ -116,7 +117,9 @@ public void testAddDatasource_Derby() throws Exception { Element fileset = getDirectChildrenByTag(library, FILESET).get(0); assertEquals("Fileset dir attribute is not correct", RESOURCES, fileset.getAttribute("dir")); - assertEquals("Fileset includes attribute is not correct", DERBY_JAR, fileset.getAttribute("includes")); + + String derbyJar = JDBCBoosterConfig.DERBY_ARTIFACT_ID + "-" + JDBCBoosterConfig.DERBY_DEFAULT_VERSION + ".jar"; + assertEquals("Fileset includes attribute is not correct", derbyJar, fileset.getAttribute("includes")); // Check that the element is correctly configured List dataSourceList = getDirectChildrenByTag(serverRoot, DATASOURCE); @@ -178,7 +181,7 @@ public void testAddDatasource_DB2() throws Exception { outputDir.getRoot().getAbsolutePath(), null, logger); Map jdbcDependency = BoosterUtil.getJDBCDependency(); - jdbcDependency.put(JDBCBoosterConfig.DB2_DEPENDENCY, "the db2 dependency version"); + jdbcDependency.put(JDBCBoosterConfig.DB2_GROUP_ID + ":" + JDBCBoosterConfig.DB2_ARTIFACT_ID, "1.0"); Properties boostProperties = new Properties(); boostProperties.put(BoostProperties.DATASOURCE_URL, DB2_URL); @@ -205,7 +208,9 @@ public void testAddDatasource_DB2() throws Exception { Element fileset = getDirectChildrenByTag(library, FILESET).get(0); assertEquals("Fileset dir attribute is not correct", RESOURCES, fileset.getAttribute("dir")); - assertEquals("Fileset includes attribute is not correct", DB2_JAR, fileset.getAttribute("includes")); + + String db2Jar = JDBCBoosterConfig.DB2_ARTIFACT_ID + "-1.0.jar"; + assertEquals("Fileset includes attribute is not correct", db2Jar, fileset.getAttribute("includes")); // Check that the element is correctly configured List dataSourceList = getDirectChildrenByTag(serverRoot, DATASOURCE); @@ -257,7 +262,7 @@ public void testAddJdbcBoosterConfig_MySQL() throws Exception { outputDir.getRoot().getAbsolutePath(), null, logger); Map jdbcDependency = BoosterUtil.getJDBCDependency(); - jdbcDependency.put(JDBCBoosterConfig.MYSQL_DEPENDENCY, "the mysql dependency version"); + jdbcDependency.put(JDBCBoosterConfig.MYSQL_GROUP_ID + ":" + JDBCBoosterConfig.MYSQL_ARTIFACT_ID, "1.0"); Properties boostProperties = new Properties(); boostProperties.put(BoostProperties.DATASOURCE_URL, MYSQL_URL); @@ -283,7 +288,9 @@ public void testAddJdbcBoosterConfig_MySQL() throws Exception { Element fileset = getDirectChildrenByTag(library, FILESET).get(0); assertEquals("Fileset dir attribute is not correct", RESOURCES, fileset.getAttribute("dir")); - assertEquals("Fileset includes attribute is not correct", MYSQL_JAR, fileset.getAttribute("includes")); + + String mysqlJar = JDBCBoosterConfig.MYSQL_ARTIFACT_ID + "-1.0.jar"; + assertEquals("Fileset includes attribute is not correct", mysqlJar, fileset.getAttribute("includes")); // Check that the element is correctly configured List dataSourceList = getDirectChildrenByTag(serverRoot, DATASOURCE); @@ -319,5 +326,85 @@ public void testAddJdbcBoosterConfig_MySQL() throws Exception { "The variable set for " + BoostProperties.DATASOURCE_URL + " is not correct", MYSQL_URL, urlFound); } + + /** + * Test that the server.xml and boostrap.properties are fully configured + * with the MySQL datasource + * + * @throws ParserConfigurationException + * @throws TransformerException + * @throws IOException + */ + @Test + public void testAddJdbcBoosterConfig_PostgreSQL() throws Exception { + + LibertyServerConfigGenerator serverConfig = new LibertyServerConfigGenerator( + outputDir.getRoot().getAbsolutePath(), null, logger); + + Map jdbcDependency = BoosterUtil.getJDBCDependency(); + jdbcDependency.put(JDBCBoosterConfig.POSTGRESQL_GROUP_ID + ":" + JDBCBoosterConfig.POSTGRESQL_ARTIFACT_ID, "1.0"); + + Properties boostProperties = new Properties(); + boostProperties.put(BoostProperties.DATASOURCE_URL, POSTGRESQL_URL); + + BoosterConfigParams params = new BoosterConfigParams(jdbcDependency, boostProperties); + LibertyJDBCBoosterConfig jdbcConfig = new LibertyJDBCBoosterConfig(params, logger); + jdbcConfig.addServerConfig(serverConfig); + serverConfig.writeToServer(); + + File serverXml = new File(outputDir.getRoot().getAbsolutePath() + "/server.xml"); + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + Document doc = dBuilder.parse(serverXml); + + Element serverRoot = doc.getDocumentElement(); + + // Check that the element is correctly configured + List libraryList = getDirectChildrenByTag(serverRoot, LIBRARY); + assertEquals("Didn't find one and only one library", 1, libraryList.size()); + + Element library = libraryList.get(0); + assertEquals("Library id is not correct", JDBC_LIBRARY_1, library.getAttribute("id")); + + Element fileset = getDirectChildrenByTag(library, FILESET).get(0); + assertEquals("Fileset dir attribute is not correct", RESOURCES, fileset.getAttribute("dir")); + + String postgresqlJar = JDBCBoosterConfig.POSTGRESQL_ARTIFACT_ID + "-1.0.jar"; + assertEquals("Fileset includes attribute is not correct", postgresqlJar, fileset.getAttribute("includes")); + + // Check that the element is correctly configured + List dataSourceList = getDirectChildrenByTag(serverRoot, DATASOURCE); + assertEquals("Didn't find one and only one dataSource", 1, dataSourceList.size()); + + Element dataSource = dataSourceList.get(0); + assertEquals("DataSource id is not correct", DEFAULT_DATASOURCE, dataSource.getAttribute("id")); + assertEquals("DataSource jdbcDriverRef is not correct", JDBC_DRIVER_1, + dataSource.getAttribute(JDBC_DRIVER_REF)); + + List propertiesList = getDirectChildrenByTag(dataSource, PROPERTIES_POSTGRESQL); + assertEquals("Didn't find one and only one properties", 1, propertiesList.size()); + + Element properties = propertiesList.get(0); + assertEquals("The url attribute is not correct", BoostUtil.makeVariable(BoostProperties.DATASOURCE_URL), + properties.getAttribute(URL)); + + // Check that the element is correctly configured + List jdbcDriverList = getDirectChildrenByTag(serverRoot, JDBC_DRIVER); + assertEquals("Didn't find one and only one jdbcDriver", 1, jdbcDriverList.size()); + + Element jdbcDriver = jdbcDriverList.get(0); + assertEquals("JdbcDriver id is not correct", JDBC_DRIVER_1, jdbcDriver.getAttribute("id")); + assertEquals("JdbcDriver libraryRef is not correct", JDBC_LIBRARY_1, jdbcDriver.getAttribute(LIBRARY_REF)); + + // Check variables.xml content + String variablesXml = outputDir.getRoot().getAbsolutePath() + LibertyServerConfigGenerator.CONFIG_DROPINS_DIR + "/variables.xml"; + + String urlFound = ConfigFileUtils.findVariableInXml(variablesXml, + BoostProperties.DATASOURCE_URL); + + assertEquals( + "The variable set for " + BoostProperties.DATASOURCE_URL + " is not correct", + POSTGRESQL_URL, urlFound); + } } diff --git a/boost-maven/boost-runtimes/runtime-tomee/src/main/java/boost/runtimes/tomee/TomeeServerConfigGenerator.java b/boost-maven/boost-runtimes/runtime-tomee/src/main/java/boost/runtimes/tomee/TomeeServerConfigGenerator.java index edae89a3..a33750cf 100644 --- a/boost-maven/boost-runtimes/runtime-tomee/src/main/java/boost/runtimes/tomee/TomeeServerConfigGenerator.java +++ b/boost-maven/boost-runtimes/runtime-tomee/src/main/java/boost/runtimes/tomee/TomeeServerConfigGenerator.java @@ -79,7 +79,7 @@ public TomeeServerConfigGenerator(String configPath, BoostLoggerI logger) throws public void addServerConfig(AbstractBoosterConfig boosterConfig) throws Exception { if (boosterConfig instanceof JDBCBoosterConfig) { - addDataSource(((JDBCBoosterConfig)boosterConfig).getProductName(), ((JDBCBoosterConfig)boosterConfig).getDatasourceProperties()); + addDataSource(((JDBCBoosterConfig)boosterConfig).getDriverInfo(), ((JDBCBoosterConfig)boosterConfig).getDatasourceProperties()); } } @@ -215,7 +215,7 @@ public void addKeystore(Map keystoreProps, Map k // No keystore support yet } - public void addDataSource(String productName, Properties boostDbProperties) throws Exception { + public void addDataSource(Map driverInfo, Properties boostDbProperties) throws Exception { // Read tomee.xml File tomeeXml = new File(configPath + "/" + TOMEE_XML); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); @@ -231,15 +231,7 @@ public void addDataSource(String productName, Properties boostDbProperties) thro tomee.appendChild(resource); // Add driver class name - String driverClassName = ""; - if (productName.equals(JDBCBoosterConfig.DERBY)) { - driverClassName = JDBCBoosterConfig.DERBY_DRIVER_CLASS_NAME; - } else if (productName.equals(JDBCBoosterConfig.DB2)) { - driverClassName = JDBCBoosterConfig.DB2_DRIVER_CLASS_NAME; - } else if (productName.equals(JDBCBoosterConfig.MYSQL)) { - driverClassName = JDBCBoosterConfig.MYSQL_DRIVER_CLASS_NAME; - } - Text jdbcDriverText = doc.createTextNode(JDBC_DRIVER_PROPERTY + " = " + driverClassName + System.lineSeparator()); + Text jdbcDriverText = doc.createTextNode(JDBC_DRIVER_PROPERTY + " = " + driverInfo.get(JDBCBoosterConfig.DRIVER_CLASS_NAME) + System.lineSeparator()); resource.appendChild(jdbcDriverText); @@ -278,10 +270,11 @@ public void addDataSource(String productName, Properties boostDbProperties) thro } else { // Build the url + String driverName = driverInfo.get(JDBCBoosterConfig.DRIVER_NAME); StringBuilder jdbcUrl = new StringBuilder(); - jdbcUrl.append("jdbc:" + productName); + jdbcUrl.append("jdbc:" + driverName); - if (productName.equals(JDBCBoosterConfig.DERBY)) { + if (driverName.equals(JDBCBoosterConfig.DERBY_DRIVER_NAME)) { // Derby's URL is slightly different than MySQL and DB2 String databaseName = (String) boostDbProperties.remove(BoostProperties.DATASOURCE_DATABASE_NAME);