Print

Print


Commit in hps-java/src/main/java/org/lcsim/hps/conditions on MAIN
ConnectionParameters.java+20-41.2 -> 1.3
add ability to read database configuration from a properties file

hps-java/src/main/java/org/lcsim/hps/conditions
ConnectionParameters.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- ConnectionParameters.java	18 Sep 2013 02:33:16 -0000	1.2
+++ ConnectionParameters.java	18 Sep 2013 21:02:38 -0000	1.3
@@ -11,11 +11,11 @@
  * return a Connection object based on these parameters.
  * 
  * @author jeremym
- * @version $Id: ConnectionParameters.java,v 1.2 2013/09/18 02:33:16 jeremy Exp $
+ * @version $Id: ConnectionParameters.java,v 1.3 2013/09/18 21:02:38 jeremy Exp $
  */
 public final class ConnectionParameters {
     
-    /* Default values for the MySQL database at SLAC. */
+    /** Default values for the MySQL test database at SLAC. */
     private String user = "rd_hps_cond_ro";
     private String password = "2jumpinphotons.";
     private int port = 3306;
@@ -23,7 +23,7 @@
     private String database = "rd_hps_cond";
 
     /**
-     * No argument constructor using defaults.
+     * No argument constructor that uses the defaults.
      */
     ConnectionParameters() {
     }
@@ -35,9 +35,10 @@
      * @param hostname The hostname.
      * @param port The port number.
      */
-    ConnectionParameters(String user, String password, String hostname, int port) {
+    ConnectionParameters(String user, String password, String database, String hostname, int port) {
         this.user = user;
         this.password = password;
+        this.database = database;
         this.hostname = hostname;
         this.port = port;
     }
@@ -100,4 +101,19 @@
         }
         return connection;
     }
+    
+    /**
+     * Create ConnectionParameters from data in a properties file.
+     * @param properties The properties file.
+     * @return The ConnectionParameters created from the properties file.
+     */
+    public static final ConnectionParameters fromProperties(Properties properties) 
+    {        
+        String user = properties.get("hps.conditions.db.user").toString();
+        String password = properties.getProperty("hps.conditions.db.password").toString();
+        String database = properties.getProperty("hps.conditions.db.database").toString();
+        String hostname = properties.getProperty("hps.conditions.db.hostname").toString();
+        int port = Integer.parseInt(properties.getProperty("hps.conditions.db.port").toString());
+        return new ConnectionParameters(user, password, database, hostname, port);
+    }    
 }
\ No newline at end of file
CVSspam 0.2.12


Use REPLY-ALL to reply to list

To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1