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 40dda1e3..913a63cb 100644 --- a/boost-common/src/main/java/boost/common/boosters/JDBCBoosterConfig.java +++ b/boost-common/src/main/java/boost/common/boosters/JDBCBoosterConfig.java @@ -27,15 +27,16 @@ @BoosterCoordinates(AbstractBoosterConfig.BOOSTERS_GROUP_ID + ":jdbc") public class JDBCBoosterConfig extends AbstractBoosterConfig { - 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"; - 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 POSTGRESQL_DRIVER_CLASS_NAME = "org.postgresql.Driver"; + public static String DERBY_DRIVER_NAME = "derby"; + public static String DB2_DRIVER_NAME = "db2"; + public static String MYSQL_DRIVER_NAME = "mysql"; + public static String POSTGRESQL_DRIVER_NAME = "postgresql"; + public static String DERBY_GROUP_ID = "org.apache.derby"; public static String DERBY_ARTIFACT_ID = "derby"; public static String DB2_GROUP_ID = "com.ibm.db2.jcc"; @@ -51,6 +52,7 @@ public class JDBCBoosterConfig extends AbstractBoosterConfig { public static String DRIVER_NAME = "driverName"; public static String DRIVER_JAR = "driverJar"; + BoostLoggerI logger; protected Properties boostConfigProperties; private String dependency; private Map driverInfo; @@ -58,6 +60,8 @@ public class JDBCBoosterConfig extends AbstractBoosterConfig { public JDBCBoosterConfig(BoosterConfigParams params, BoostLoggerI logger) throws BoostException { super(params.getProjectDependencies().get(getCoordinates(JDBCBoosterConfig.class))); + this.logger = logger; + Map projectDependencies = params.getProjectDependencies(); this.boostConfigProperties = params.getBoostProperties(); @@ -67,7 +71,7 @@ public JDBCBoosterConfig(BoosterConfigParams params, BoostLoggerI logger) throws String version = projectDependencies.get(DERBY_GROUP_ID + ":" + DERBY_ARTIFACT_ID); dependency = DERBY_GROUP_ID + ":" + DERBY_ARTIFACT_ID + ":" + version; - driverInfo.put(DRIVER_NAME, DERBY_ARTIFACT_ID); + 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"); @@ -75,7 +79,7 @@ public JDBCBoosterConfig(BoosterConfigParams params, BoostLoggerI logger) throws String version = projectDependencies.get(DB2_GROUP_ID + ":" + DB2_ARTIFACT_ID); dependency = DB2_GROUP_ID + ":" + DB2_ARTIFACT_ID + ":" + version; - driverInfo.put(DRIVER_NAME, DB2_ARTIFACT_ID); + 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"); @@ -83,7 +87,7 @@ public JDBCBoosterConfig(BoosterConfigParams params, BoostLoggerI logger) throws String version = projectDependencies.get(MYSQL_GROUP_ID + ":" + MYSQL_ARTIFACT_ID); dependency = MYSQL_GROUP_ID + ":" + MYSQL_ARTIFACT_ID + ":" + version; - driverInfo.put(DRIVER_NAME, MYSQL_ARTIFACT_ID); + 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"); @@ -91,14 +95,14 @@ public JDBCBoosterConfig(BoosterConfigParams params, BoostLoggerI logger) throws String version = projectDependencies.get(POSTGRESQL_GROUP_ID + ":" + POSTGRESQL_ARTIFACT_ID); dependency = POSTGRESQL_GROUP_ID + ":" + POSTGRESQL_ARTIFACT_ID + ":" + version; - driverInfo.put(DRIVER_NAME, POSTGRESQL_ARTIFACT_ID); + 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 { dependency = DERBY_GROUP_ID + ":" + DERBY_ARTIFACT_ID + ":" + DERBY_DEFAULT_VERSION; - driverInfo.put(DRIVER_NAME, DERBY_ARTIFACT_ID); + 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"); } @@ -116,29 +120,41 @@ 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 (dependency.contains(DERBY_GROUP_ID)) { + // Verify correct property configuration + if (dependency.contains(DERBY_GROUP_ID)) { + if (!datasourceProperties.containsKey(BoostProperties.DATASOURCE_DATABASE_NAME)) { datasourceProperties.put(BoostProperties.DATASOURCE_DATABASE_NAME, DERBY_DB); + } + if (!datasourceProperties.containsKey(BoostProperties.DATASOURCE_CREATE_DATABASE)) { datasourceProperties.put(BoostProperties.DATASOURCE_CREATE_DATABASE, "create"); + } + } else { + // Check connection properties + if (!datasourceProperties.containsKey(BoostProperties.DATASOURCE_URL)) { + // No URL was specified. Check if individual properties were + // set. + if (!datasourceProperties.containsKey(BoostProperties.DATASOURCE_DATABASE_NAME) + && !datasourceProperties.containsKey(BoostProperties.DATASOURCE_SERVER_NAME) + && !datasourceProperties.containsKey(BoostProperties.DATASOURCE_PORT_NUMBER)) { + + logger.warn("No DB connection properties were provided for the " + driverInfo.get(DRIVER_NAME) + + "database. " + " The " + BoostProperties.DATASOURCE_URL + + " property will need to be set at runtime."); + + datasourceProperties.put(BoostProperties.DATASOURCE_URL, ""); + } + } - } else if (dependency.contains(DB2_GROUP_ID)) { - datasourceProperties.put(BoostProperties.DATASOURCE_URL, - "jdbc:db2://localhost:" + DB2_DEFAULT_PORT_NUMBER); + // Check authentication properties + if (!datasourceProperties.containsKey(BoostProperties.DATASOURCE_USER) + && !datasourceProperties.containsKey(BoostProperties.DATASOURCE_PASSWORD)) { - } else if (dependency.contains(MYSQL_GROUP_ID)) { - datasourceProperties.put(BoostProperties.DATASOURCE_URL, - "jdbc:mysql://localhost:" + MYSQL_DEFAULT_PORT_NUMBER); + logger.warn("No authentication properties were provided for the " + driverInfo.get(DRIVER_NAME) + + "database. " + " The " + BoostProperties.DATASOURCE_USER + " and " + + BoostProperties.DATASOURCE_PASSWORD + " properties will need to be set at runtime."); - } else if (dependency.contains(POSTGRESQL_GROUP_ID)) { - datasourceProperties.put(BoostProperties.DATASOURCE_URL, - "jdbc:postgresql://localhost:" + POSTGRESQL_DEFAULT_PORT_NUMBER); + datasourceProperties.put(BoostProperties.DATASOURCE_USER, ""); + datasourceProperties.put(BoostProperties.DATASOURCE_PASSWORD, ""); } } return datasourceProperties; 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 4981f7d6..b72ffa6d 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 @@ -315,13 +315,13 @@ public void addDataSource(Map driverInfo, Properties datasourceP String datasourcePropertiesElement = null; String driverName = driverInfo.get(JDBCBoosterConfig.DRIVER_NAME); - if (driverName.equals(JDBCBoosterConfig.DERBY_ARTIFACT_ID)) { + if (driverName.equals(JDBCBoosterConfig.DERBY_DRIVER_NAME)) { datasourcePropertiesElement = PROPERTIES_DERBY_EMBEDDED; - } else if (driverName.equals(JDBCBoosterConfig.DB2_ARTIFACT_ID)) { + } else if (driverName.equals(JDBCBoosterConfig.DB2_DRIVER_NAME)) { datasourcePropertiesElement = PROPERTIES_DB2_JCC; - } else if (driverName.equals(JDBCBoosterConfig.MYSQL_ARTIFACT_ID)) { + } else if (driverName.equals(JDBCBoosterConfig.MYSQL_DRIVER_NAME)) { datasourcePropertiesElement = PROPERTIES; - } else if (driverName.equals(JDBCBoosterConfig.POSTGRESQL_ARTIFACT_ID)) { + } else if (driverName.equals(JDBCBoosterConfig.POSTGRESQL_DRIVER_NAME)) { datasourcePropertiesElement = PROPERTIES_POSTGRESQL; } 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 d589a1dc..96e853ae 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 @@ -240,9 +240,16 @@ public void testAddDatasource_DB2() throws Exception { 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", DB2_URL, + ConfigFileUtils.findVariableInXml(variablesXml, BoostProperties.DATASOURCE_URL)); - assertEquals("The variable set for " + BoostProperties.DATASOURCE_URL + " is not correct", DB2_URL, urlFound); + // No user set. + assertEquals("The variable set for " + BoostProperties.DATASOURCE_USER + " is not correct", "", + ConfigFileUtils.findVariableInXml(variablesXml, BoostProperties.DATASOURCE_USER)); + + // No password set. + assertEquals("The variable set for " + BoostProperties.DATASOURCE_PASSWORD + " is not correct", "", + ConfigFileUtils.findVariableInXml(variablesXml, BoostProperties.DATASOURCE_PASSWORD)); } /** @@ -318,9 +325,16 @@ public void testAddJdbcBoosterConfig_MySQL() throws Exception { 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", MYSQL_URL, + ConfigFileUtils.findVariableInXml(variablesXml, BoostProperties.DATASOURCE_URL)); + + // No user set. + assertEquals("The variable set for " + BoostProperties.DATASOURCE_USER + " is not correct", "", + ConfigFileUtils.findVariableInXml(variablesXml, BoostProperties.DATASOURCE_USER)); - assertEquals("The variable set for " + BoostProperties.DATASOURCE_URL + " is not correct", MYSQL_URL, urlFound); + // No password set. + assertEquals("The variable set for " + BoostProperties.DATASOURCE_PASSWORD + " is not correct", "", + ConfigFileUtils.findVariableInXml(variablesXml, BoostProperties.DATASOURCE_PASSWORD)); } /** @@ -397,10 +411,16 @@ public void testAddJdbcBoosterConfig_PostgreSQL() throws Exception { 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); + ConfigFileUtils.findVariableInXml(variablesXml, BoostProperties.DATASOURCE_URL)); + + // No user set. + assertEquals("The variable set for " + BoostProperties.DATASOURCE_USER + " is not correct", "", + ConfigFileUtils.findVariableInXml(variablesXml, BoostProperties.DATASOURCE_USER)); + + // No password set. + assertEquals("The variable set for " + BoostProperties.DATASOURCE_PASSWORD + " is not correct", "", + ConfigFileUtils.findVariableInXml(variablesXml, BoostProperties.DATASOURCE_PASSWORD)); } } 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 e87a89fb..6154c667 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 @@ -274,7 +274,7 @@ public void addDataSource(Map driverInfo, Properties boostDbProp StringBuilder jdbcUrl = new StringBuilder(); jdbcUrl.append("jdbc:" + driverName); - if (driverName.equals(JDBCBoosterConfig.DERBY_ARTIFACT_ID)) { + 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);