88 * Contributors:
99 * IBM Corporation - initial API and implementation
1010 *******************************************************************************/
11- package io .openliberty .boost .common .boosters ;
11+ package io .openliberty .boost .common .boosters . liberty ;
1212
1313import io .openliberty .boost .common .config .BoostProperties ;
1414import io .openliberty .boost .common .BoostException ;
1515import io .openliberty .boost .common .BoostLoggerI ;
1616import io .openliberty .boost .common .boosters .AbstractBoosterConfig .BoosterCoordinates ;
1717import io .openliberty .boost .common .utils .BoostUtil ;
1818
19- import static io .openliberty .boost .common .config .ConfigConstants .*;
19+ import static io .openliberty .boost .common .config .LibertyConfigConstants .*;
2020
2121import java .util .Map ;
2222import java .util .Properties ;
2525import org .w3c .dom .Element ;
2626import org .w3c .dom .NodeList ;
2727
28- @ BoosterCoordinates (AbstractBoosterConfig .BOOSTERS_GROUP_ID + ":jdbc" )
29- public class JDBCBoosterConfig extends AbstractBoosterConfig {
28+ @ BoosterCoordinates (AbstractBoosterLibertyConfig .BOOSTERS_GROUP_ID + ":jdbc" )
29+ public class JDBCBoosterLibertyConfig extends AbstractBoosterLibertyConfig {
3030
3131 public static String DERBY_DEPENDENCY = "org.apache.derby:derby" ;
3232 public static String DB2_DEPENDENCY = "com.ibm.db2.jcc:db2jcc" ;
@@ -39,22 +39,22 @@ public class JDBCBoosterConfig extends AbstractBoosterConfig {
3939
4040 private Properties serverProperties ;
4141
42- public JDBCBoosterConfig (Map <String , String > dependencies , BoostLoggerI logger ) throws BoostException {
42+ public JDBCBoosterLibertyConfig (Map <String , String > dependencies , BoostLoggerI logger ) throws BoostException {
4343
4444 // Check for user defined database dependencies
4545 String configuredDatabaseDep = null ;
4646
47- if (dependencies .containsKey (JDBCBoosterConfig .DERBY_DEPENDENCY )) {
48- String derbyVersion = dependencies .get (JDBCBoosterConfig .DERBY_DEPENDENCY );
49- configuredDatabaseDep = JDBCBoosterConfig .DERBY_DEPENDENCY + ":" + derbyVersion ;
50-
51- } else if (dependencies .containsKey (JDBCBoosterConfig .DB2_DEPENDENCY )) {
52- String db2Version = dependencies .get (JDBCBoosterConfig .DB2_DEPENDENCY );
53- configuredDatabaseDep = JDBCBoosterConfig .DB2_DEPENDENCY + ":" + db2Version ;
54-
55- } else if (dependencies .containsKey (JDBCBoosterConfig .MYSQL_DEPENDENCY )) {
56- String mysqlVersion = dependencies .get (JDBCBoosterConfig .MYSQL_DEPENDENCY );
57- configuredDatabaseDep = JDBCBoosterConfig .MYSQL_DEPENDENCY + ":" + mysqlVersion ;
47+ if (dependencies .containsKey (JDBCBoosterLibertyConfig .DERBY_DEPENDENCY )) {
48+ String derbyVersion = dependencies .get (JDBCBoosterLibertyConfig .DERBY_DEPENDENCY );
49+ configuredDatabaseDep = JDBCBoosterLibertyConfig .DERBY_DEPENDENCY + ":" + derbyVersion ;
50+
51+ } else if (dependencies .containsKey (JDBCBoosterLibertyConfig .DB2_DEPENDENCY )) {
52+ String db2Version = dependencies .get (JDBCBoosterLibertyConfig .DB2_DEPENDENCY );
53+ configuredDatabaseDep = JDBCBoosterLibertyConfig .DB2_DEPENDENCY + ":" + db2Version ;
54+
55+ } else if (dependencies .containsKey (JDBCBoosterLibertyConfig .MYSQL_DEPENDENCY )) {
56+ String mysqlVersion = dependencies .get (JDBCBoosterLibertyConfig .MYSQL_DEPENDENCY );
57+ configuredDatabaseDep = JDBCBoosterLibertyConfig .MYSQL_DEPENDENCY + ":" + mysqlVersion ;
5858 }
5959
6060 Properties boostConfigProperties = BoostProperties .getConfiguredBoostProperties (logger );
@@ -86,41 +86,49 @@ private void init(Properties boostConfigProperties, String configuredDatabaseDep
8686 // Set server properties
8787 this .serverProperties = new Properties ();
8888
89- // Initialize defaults and required properties for each datasource vendor
89+ // Initialize defaults and required properties for each datasource
90+ // vendor
9091 if (this .dependency .startsWith (DERBY_DEPENDENCY )) {
91- // Embedded Derby requires a database name. Set a default for this and create it.
92+ // Embedded Derby requires a database name. Set a default for this
93+ // and create it.
9294 this .serverProperties .put (BoostProperties .DATASOURCE_DATABASE_NAME , DERBY_DB );
9395 this .serverProperties .put (BoostProperties .DATASOURCE_CREATE_DATABASE , "create" );
94-
96+
9597 } else if (this .dependency .startsWith (DB2_DEPENDENCY )) {
96- // For DB2, since we are expecting the database to exist, there is no
97- // default value we can set for databaseName that would be of any use.
98- // Likewise, for user and password, there isn't anything we could set
99- // here that would make sense. Since these properties are required,
100- // set empty strings as there values to create place holders. If they
101- // are not overridden by the user at package time, they can be overridden
102- // at runtime.
103- this .serverProperties .put (BoostProperties .DATASOURCE_DATABASE_NAME , "" );
104- this .serverProperties .put (BoostProperties .DATASOURCE_USER , "" );
105- this .serverProperties .put (BoostProperties .DATASOURCE_PASSWORD , "" );
98+ // For DB2, since we are expecting the database to exist, there is
99+ // no
100+ // default value we can set for databaseName that would be of any
101+ // use.
102+ // Likewise, for user and password, there isn't anything we could
103+ // set
104+ // here that would make sense. Since these properties are required,
105+ // set empty strings as there values to create place holders. If
106+ // they
107+ // are not overridden by the user at package time, they can be
108+ // overridden
109+ // at runtime.
110+ this .serverProperties .put (BoostProperties .DATASOURCE_DATABASE_NAME , "" );
111+ this .serverProperties .put (BoostProperties .DATASOURCE_USER , "" );
112+ this .serverProperties .put (BoostProperties .DATASOURCE_PASSWORD , "" );
106113 this .serverProperties .put (BoostProperties .DATASOURCE_SERVER_NAME , LOCALHOST );
107- this .serverProperties .put (BoostProperties .DATASOURCE_PORT_NUMBER , DB2_DEFAULT_PORT_NUMBER );
108-
114+ this .serverProperties .put (BoostProperties .DATASOURCE_PORT_NUMBER , DB2_DEFAULT_PORT_NUMBER );
115+
109116 } else if (this .dependency .startsWith (MYSQL_DEPENDENCY )) {
110- // Same set of minimum requirements for MySQL
111- this .serverProperties .put (BoostProperties .DATASOURCE_DATABASE_NAME , "" );
112- this .serverProperties .put (BoostProperties .DATASOURCE_USER , "" );
113- this .serverProperties .put (BoostProperties .DATASOURCE_PASSWORD , "" );
117+ // Same set of minimum requirements for MySQL
118+ this .serverProperties .put (BoostProperties .DATASOURCE_DATABASE_NAME , "" );
119+ this .serverProperties .put (BoostProperties .DATASOURCE_USER , "" );
120+ this .serverProperties .put (BoostProperties .DATASOURCE_PASSWORD , "" );
114121 this .serverProperties .put (BoostProperties .DATASOURCE_SERVER_NAME , LOCALHOST );
115- this .serverProperties .put (BoostProperties .DATASOURCE_PORT_NUMBER , MYSQL_DEFAULT_PORT_NUMBER );
116- }
117-
118- // Find and add all "boost.db." properties. This will override any default values
122+ this .serverProperties .put (BoostProperties .DATASOURCE_PORT_NUMBER , MYSQL_DEFAULT_PORT_NUMBER );
123+ }
124+
125+ // Find and add all "boost.db." properties. This will override any
126+ // default values
119127 for (String key : boostConfigProperties .stringPropertyNames ()) {
120- if ( key .startsWith (BoostProperties .DATASOURCE_PREFIX )) {
121- String value = (String ) boostConfigProperties .get (key );
122- this .serverProperties .put (key , value );
123- }
128+ if (key .startsWith (BoostProperties .DATASOURCE_PREFIX )) {
129+ String value = (String ) boostConfigProperties .get (key );
130+ this .serverProperties .put (key , value );
131+ }
124132 }
125133 }
126134
@@ -145,14 +153,14 @@ public String getDependency() {
145153 public void addServerConfig (Document doc ) {
146154
147155 if (dependency .startsWith (DERBY_DEPENDENCY )) {
148- addDatasourceConfig (doc , PROPERTIES_DERBY_EMBEDDED , DERBY_JAR );
156+ addDatasourceConfig (doc , PROPERTIES_DERBY_EMBEDDED , DERBY_JAR );
149157
150158 } else if (dependency .startsWith (DB2_DEPENDENCY )) {
151- addDatasourceConfig (doc , PROPERTIES_DB2_JCC , DB2_JAR );
152-
159+ addDatasourceConfig (doc , PROPERTIES_DB2_JCC , DB2_JAR );
160+
153161 } else if (dependency .startsWith (MYSQL_DEPENDENCY )) {
154- // Use generic <properties> element for MySQL
155- addDatasourceConfig (doc , PROPERTIES , MYSQL_JAR );
162+ // Use generic <properties> element for MySQL
163+ addDatasourceConfig (doc , PROPERTIES , MYSQL_JAR );
156164 }
157165 }
158166
@@ -194,27 +202,30 @@ private void addDatasourceConfig(Document doc, String datasourcePropertiesElemen
194202 jdbcDriver .setAttribute ("id" , JDBC_DRIVER_1 );
195203 jdbcDriver .setAttribute (LIBRARY_REF , JDBC_LIBRARY_1 );
196204 serverRoot .appendChild (jdbcDriver );
197-
205+
198206 // Add container authentication
199- if (this .serverProperties .containsKey (BoostProperties .DATASOURCE_USER ) && this .serverProperties .containsKey (BoostProperties .DATASOURCE_PASSWORD )) {
200- dataSource .setAttribute (CONTAINER_AUTH_DATA_REF , DATASOURCE_AUTH_DATA );
201-
202- Element containerAuthData = doc .createElement (AUTH_DATA );
203- containerAuthData .setAttribute ("id" , DATASOURCE_AUTH_DATA );
204- containerAuthData .setAttribute (USER , BoostUtil .makeVariable (BoostProperties .DATASOURCE_USER ));
205- containerAuthData .setAttribute (PASSWORD , BoostUtil .makeVariable (BoostProperties .DATASOURCE_PASSWORD ));
206- serverRoot .appendChild (containerAuthData );
207+ if (this .serverProperties .containsKey (BoostProperties .DATASOURCE_USER )
208+ && this .serverProperties .containsKey (BoostProperties .DATASOURCE_PASSWORD )) {
209+ dataSource .setAttribute (CONTAINER_AUTH_DATA_REF , DATASOURCE_AUTH_DATA );
210+
211+ Element containerAuthData = doc .createElement (AUTH_DATA );
212+ containerAuthData .setAttribute ("id" , DATASOURCE_AUTH_DATA );
213+ containerAuthData .setAttribute (USER , BoostUtil .makeVariable (BoostProperties .DATASOURCE_USER ));
214+ containerAuthData .setAttribute (PASSWORD , BoostUtil .makeVariable (BoostProperties .DATASOURCE_PASSWORD ));
215+ serverRoot .appendChild (containerAuthData );
207216 }
208217 }
209-
218+
210219 private void addDatasourceProperties (Element properties ) {
211- for (String property : this .serverProperties .stringPropertyNames ()) {
212- // We are using container authentication. Do not include user or password here
213- if ( !property .equals (BoostProperties .DATASOURCE_USER ) && !property .equals (BoostProperties .DATASOURCE_PASSWORD )) {
214-
215- String attribute = property .replace (BoostProperties .DATASOURCE_PREFIX , "" );
216- properties .setAttribute (attribute , BoostUtil .makeVariable (property ));
217- }
220+ for (String property : this .serverProperties .stringPropertyNames ()) {
221+ // We are using container authentication. Do not include user or
222+ // password here
223+ if (!property .equals (BoostProperties .DATASOURCE_USER )
224+ && !property .equals (BoostProperties .DATASOURCE_PASSWORD )) {
225+
226+ String attribute = property .replace (BoostProperties .DATASOURCE_PREFIX , "" );
227+ properties .setAttribute (attribute , BoostUtil .makeVariable (property ));
228+ }
218229 }
219230 }
220231}
0 commit comments