LISTSERV mailing list manager LISTSERV 16.5

Help for HPS-SVN Archives


HPS-SVN Archives

HPS-SVN Archives


HPS-SVN@LISTSERV.SLAC.STANFORD.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

HPS-SVN Home

HPS-SVN Home

HPS-SVN  May 2015

HPS-SVN May 2015

Subject:

r2889 - /java/trunk/conditions/src/main/java/org/hps/conditions/database/ConnectionParameters.java

From:

[log in to unmask]

Reply-To:

Notification of commits to the hps svn repository <[log in to unmask]>

Date:

Mon, 4 May 2015 06:47:11 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (339 lines)

Author: [log in to unmask]
Date: Sun May  3 23:46:56 2015
New Revision: 2889

Log:
Add additional constructor.

Modified:
    java/trunk/conditions/src/main/java/org/hps/conditions/database/ConnectionParameters.java

Modified: java/trunk/conditions/src/main/java/org/hps/conditions/database/ConnectionParameters.java
 =============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/database/ConnectionParameters.java	(original)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/database/ConnectionParameters.java	Sun May  3 23:46:56 2015
@@ -23,34 +23,101 @@
     public static final int DEFAULT_PORT = 3306;
 
     /**
+     * Configure the connection parameters from a properties file.
+     *
+     * @param file the properties file
+     * @return the connection parameters
+     */
+    public static ConnectionParameters fromProperties(final File file) {
+        FileInputStream fin = null;
+        try {
+            fin = new FileInputStream(file);
+        } catch (final FileNotFoundException e) {
+            throw new IllegalArgumentException(file.getPath() + " does not exist.", e);
+        }
+        return fromProperties(fin);
+    }
+
+    /**
+     * Configure the connection parameters from an <code>InputStream</code> of properties.
+     *
+     * @param in the InputStream of the properties
+     * @return the connection parameters
+     * @throws RuntimeException if the InputStream is invalid
+     */
+    private static ConnectionParameters fromProperties(final InputStream in) {
+        final Properties properties = new Properties();
+        try {
+            properties.load(in);
+        } catch (final IOException e) {
+            throw new RuntimeException(e);
+        }
+        final String user = properties.getProperty("user");
+        final String password = properties.getProperty("password");
+        final String database = properties.getProperty("database");
+        final String hostname = properties.getProperty("hostname");
+        int port = DEFAULT_PORT;
+        if (properties.containsKey("port")) {
+            port = Integer.parseInt(properties.getProperty("port"));
+        }
+        return new ConnectionParameters(user, password, database, hostname, port);
+    }
+
+    /**
+     * Configure the connection parameters from an embedded classpath resource which should be a properties file.
+     *
+     * @param resource the resource path
+     * @return the connection parameters
+     */
+    public static ConnectionParameters fromResource(final String resource) {
+        return fromProperties(ConnectionParameters.class.getResourceAsStream(resource));
+    }
+
+    /**
+     * The database name.
+     */
+    private String database;
+
+    /**
+     * The host name.
+     */
+    private String hostname;
+
+    /**
+     * The user's password.
+     */
+    private String password;
+
+    /**
+     * The port.
+     */
+    private int port;
+
+    /**
      * The user name.
      */
     private String user;
 
     /**
-     * The user's password.
-     */
-    private String password;
-
-    /**
-     * The port.
-     */
-    private int port;
-
-    /**
-     * The host name.
-     */
-    private String hostname;
-
-    /**
-     * The database name.
-     */
-    private String database;
-
-    /**
      * Protected constructor for sub-classes.
      */
     protected ConnectionParameters() {
+    }
+
+    /**
+     * Class constructor using default MySQL port number.
+     *
+     * @param user the user name
+     * @param password the password
+     * @param hostname the hostname
+     * @param database the database name
+     */
+    public ConnectionParameters(final String user, final String password, final String database, final String hostname) {
+        this.user = user;
+        this.password = password;
+        this.database = database;
+        this.hostname = hostname;
+        this.port = DEFAULT_PORT;
     }
 
     /**
@@ -72,74 +139,6 @@
     }
 
     /**
-     * Get Properties object for this connection.
-     *
-     * @return the Properties for this connection
-     */
-    public Properties getConnectionProperties() {
-        final Properties p = new Properties();
-        p.put("user", user);
-        p.put("password", password);
-        return p;
-    }
-
-    /**
-     * Get the hostname.
-     *
-     * @return the hostname
-     */
-    String getHostname() {
-        return hostname;
-    }
-
-    /**
-     * Get the port number.
-     *
-     * @return the port number
-     */
-    int getPort() {
-        return port;
-    }
-
-    /**
-     * Get the name of the database.
-     *
-     * @return the name of the database
-     */
-    String getDatabase() {
-        return database;
-    }
-
-    /**
-     * Get the user name.
-     *
-     * @return the user name
-     */
-    String getUser() {
-        return user;
-    }
-
-    /**
-     * Get the password.
-     *
-     * @return the password
-     */
-    String getPassword() {
-        return password;
-    }
-
-    /**
-     * Get the connection string for these parameters.
-     * <p>
-     * This is public because the DQM database manager is using it.
-     *
-     * @return the connection string
-     */
-    public String getConnectionString() {
-        return "jdbc:mysql://" + hostname + ":" + port + "/";
-    }
-
-    /**
      * Create a database connection from these parameters. The caller becomes the "owner" and is responsible for closing
      * it when finished.
      *
@@ -151,60 +150,77 @@
         try {
             connection = DriverManager.getConnection(getConnectionString(), connectionProperties);
             connection.createStatement().execute("USE " + getDatabase());
-        } catch (SQLException x) {
+        } catch (final SQLException x) {
             throw new RuntimeException("Failed to connect to database: " + getConnectionString(), x);
         }
         return connection;
     }
 
     /**
-     * Configure the connection parameters from a properties file.
-     *
-     * @param file the properties file
-     * @return the connection parameters
-     */
-    public static ConnectionParameters fromProperties(final File file) {
-        FileInputStream fin = null;
-        try {
-            fin = new FileInputStream(file);
-        } catch (FileNotFoundException e) {
-            throw new IllegalArgumentException(file.getPath() + " does not exist.", e);
-        }
-        return fromProperties(fin);
-    }
-
-    /**
-     * Configure the connection parameters from an embedded classpath resource which should be a properties file.
-     *
-     * @param resource the resource path
-     * @return the connection parameters
-     */
-    public static ConnectionParameters fromResource(final String resource) {
-        return fromProperties(ConnectionParameters.class.getResourceAsStream(resource));
-    }
-
-    /**
-     * Configure the connection parameters from an <code>InputStream</code> of properties.
-     *
-     * @param in the InputStream of the properties
-     * @return the connection parameters
-     * @throws RuntimeException if the InputStream is invalid
-     */
-    private static ConnectionParameters fromProperties(final InputStream in) {
-        final Properties properties = new Properties();
-        try {
-            properties.load(in);
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
-        final String user = properties.getProperty("user");
-        final String password = properties.getProperty("password");
-        final String database = properties.getProperty("database");
-        final String hostname = properties.getProperty("hostname");
-        int port = DEFAULT_PORT;
-        if (properties.containsKey("port")) {
-            port = Integer.parseInt(properties.getProperty("port"));
-        }
-        return new ConnectionParameters(user, password, database, hostname, port);
+     * Get Properties object for this connection.
+     *
+     * @return the Properties for this connection
+     */
+    public Properties getConnectionProperties() {
+        final Properties p = new Properties();
+        p.put("user", this.user);
+        p.put("password", this.password);
+        return p;
+    }
+
+    /**
+     * Get the connection string for these parameters.
+     * <p>
+     * This is public because the DQM database manager is using it.
+     *
+     * @return the connection string
+     */
+    public String getConnectionString() {
+        return "jdbc:mysql://" + this.hostname + ":" + this.port + "/";
+    }
+
+    /**
+     * Get the name of the database.
+     *
+     * @return the name of the database
+     */
+    String getDatabase() {
+        return this.database;
+    }
+
+    /**
+     * Get the hostname.
+     *
+     * @return the hostname
+     */
+    String getHostname() {
+        return this.hostname;
+    }
+
+    /**
+     * Get the password.
+     *
+     * @return the password
+     */
+    String getPassword() {
+        return this.password;
+    }
+
+    /**
+     * Get the port number.
+     *
+     * @return the port number
+     */
+    int getPort() {
+        return this.port;
+    }
+
+    /**
+     * Get the user name.
+     *
+     * @return the user name
+     */
+    String getUser() {
+        return this.user;
     }
 }

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

November 2017
August 2017
July 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013

ATOM RSS1 RSS2



LISTSERV.SLAC.STANFORD.EDU

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager

Privacy Notice, Security Notice and Terms of Use