[Schmitzm-commits] r2128 - trunk/schmitzm-core/src/main/java/de/schmitzm/versionnumber

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Fri Nov 9 15:36:57 CET 2012


Author: mojays
Date: 2012-11-09 15:36:56 +0100 (Fri, 09 Nov 2012)
New Revision: 2128

Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/versionnumber/ReleaseControl.java
Log:
ReleaseControl: method to simply determine release number from database

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/versionnumber/ReleaseControl.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/versionnumber/ReleaseControl.java	2012-11-09 14:17:19 UTC (rev 2127)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/versionnumber/ReleaseControl.java	2012-11-09 14:36:56 UTC (rev 2128)
@@ -135,8 +135,44 @@
     this.confictMess = confictMess;
   }
 
+  /**
+   * Determines the required version number from database table.
+   * @param connURL  database connection URL
+   * @param user     database user used for database connection
+   * @param password password used for database connection
+   */
+  public String getRequiredReleaseNumber(String connURL, String user, String password) throws SQLException {
+    Connection conn = DriverManager.getConnection(connURL, user, password);
+    try {
+      return getRequiredReleaseNumber(conn);
+    } finally {
+      conn.close();
+    }
+  }
 
   /**
+   * Determines the required version number from database table.
+   * @param conn  database connection
+   */
+  public String getRequiredReleaseNumber(Connection conn) throws SQLException {
+    String    expProgrVersion = "";
+    Statement stmt = conn.createStatement();
+    try {
+      ResultSet rs = stmt.executeQuery("SELECT "+getRequiredReleaseColName()+" FROM "+getParametersTableName());
+      if ( rs.next() )
+        expProgrVersion = rs.getString(getRequiredReleaseColName());
+      rs.close();
+    } catch (SQLException err) {
+      LOGGER.warn("Parameters table '"+getParametersTableName()+"' does not exist. Try to create table...");
+      // Error executing the query -> table does not exist
+      // -> create table
+      createParametersTable(conn);
+    }
+    return expProgrVersion;
+  }
+  
+
+  /**
    * Checks whether the current application version fits the given expected
    * version.<br>
    * <b>Note:</b> If the release number of the running application is not
@@ -179,19 +215,7 @@
    * @param conn  database connection
    */
   public void checkApplicationRelease(Connection conn) throws SQLException {
-      String    expProgrVersion = "";
-      Statement stmt = conn.createStatement();
-      try {
-        ResultSet rs = stmt.executeQuery("SELECT "+getRequiredReleaseColName()+" FROM "+getParametersTableName());
-        if ( rs.next() )
-          expProgrVersion = rs.getString(getRequiredReleaseColName());
-        rs.close();
-      } catch (SQLException err) {
-        LOGGER.warn("Parameters table '"+getParametersTableName()+"' does not exist. Try to create table...");
-        // Error executing the query -> table does not exist
-        // -> create table
-        createParametersTable(conn);
-      }
+      String  expProgrVersion = getRequiredReleaseNumber(conn);
       if ( !checkApplicationRelease(expProgrVersion) ) {
         String mess = LangUtil.replaceParameters(getConfictMess(), expProgrVersion, getApplicationReleaseNumber());
         throw new ReleaseException(mess);



More information about the Schmitzm-commits mailing list