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  November 2014

HPS-SVN November 2014

Subject:

r1396 - in /java/trunk/conditions/src/main/java/org/hps/conditions: DatabaseConditionsManager.java cli/LoadCommand.java

From:

[log in to unmask]

Reply-To:

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

Date:

Sun, 2 Nov 2014 02:39:00 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (118 lines)

Author: [log in to unmask]
Date: Sat Nov  1 19:38:58 2014
New Revision: 1396

Log:
Move utility method to conditions manager.

Modified:
    java/trunk/conditions/src/main/java/org/hps/conditions/DatabaseConditionsManager.java
    java/trunk/conditions/src/main/java/org/hps/conditions/cli/LoadCommand.java

Modified: java/trunk/conditions/src/main/java/org/hps/conditions/DatabaseConditionsManager.java
 =============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/DatabaseConditionsManager.java	(original)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/DatabaseConditionsManager.java	Sat Nov  1 19:38:58 2014
@@ -26,8 +26,6 @@
 import org.lcsim.conditions.ConditionsConverter;
 import org.lcsim.conditions.ConditionsManager;
 import org.lcsim.conditions.ConditionsManagerImplementation;
-import org.lcsim.conditions.ConditionsReader;
-import org.lcsim.conditions.readers.BaseClasspathConditionsReader;
 import org.lcsim.geometry.Detector;
 import org.lcsim.util.loop.DetectorConditionsConverter;
 
@@ -269,6 +267,33 @@
         logger.fine("new collection ID " + collectionId + " created for table " + tableName);
         return collectionId;
     }
+    
+    /**
+     * This method will return true if the given collection ID already exists in the table.
+     * @param tableName The name of the table.
+     * @param collectionID The collection ID value.
+     * @return True if collection exists.
+     */
+    public boolean collectionExists(String tableName, int collectionID) {
+        String sql = "SELECT * FROM " + tableName + " where collection_id = " + collectionID;
+        ResultSet resultSet = selectQuery(sql);
+        try {
+            resultSet.last();
+        } catch (SQLException e) {
+            e.printStackTrace();
+        }
+        int rowCount = 0;
+        try {
+            rowCount = resultSet.getRow();
+        } catch (SQLException e) {
+            e.printStackTrace();
+        }
+        if (rowCount != 0) {
+            return true;
+        } else {
+            return false;
+        }
+    }
 
     /**
      * Get the list of table meta data.
@@ -297,6 +322,7 @@
      * @param type The collection class.
      * @return The table meta data.
      */
+    // FIXME: This should return a list in case of multiple conditions defined with same type.
     public TableMetaData findTableMetaData(Class type) {
         for (TableMetaData meta : tableMetaData) {
             if (meta.getCollectionClass().equals(type)) {

Modified: java/trunk/conditions/src/main/java/org/hps/conditions/cli/LoadCommand.java
 =============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/cli/LoadCommand.java	(original)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/cli/LoadCommand.java	Sat Nov  1 19:38:58 2014
@@ -67,7 +67,7 @@
         int collectionID;
         if (commandLine.getOptionValue("c") != null) {
             collectionID = Integer.parseInt(commandLine.getOptionValue("c"));
-            if (collectionExists(conditionsManager, tableName, collectionID)) {
+            if (conditionsManager.collectionExists(tableName, collectionID)) {
                 throw new IllegalArgumentException("The user supplied collection ID " + collectionID + " already exists in this table.");
             }            
         } else {
@@ -89,7 +89,7 @@
         File inputFile = new File(fileName);
         BufferedReader reader = null;
         try {
-            reader = new BufferedReader(new FileReader(inputFile));           
+            reader = new BufferedReader(new FileReader(inputFile));
             String headerLine = reader.readLine();
             if (headerLine == null) {
                 throw new IllegalArgumentException("The file is empty.");
@@ -118,26 +118,5 @@
                 }
             }
         }        
-    }
-    
-    boolean collectionExists(DatabaseConditionsManager conditionsManager, String tableName, int collectionID) {
-        String sql = "SELECT * FROM " + tableName + " where collection_id = " + collectionID;
-        ResultSet resultSet = conditionsManager.selectQuery(sql);
-        try {
-            resultSet.last();
-        } catch (SQLException e) {
-            e.printStackTrace();
-        }
-        int rowCount = 0;
-        try {
-            rowCount = resultSet.getRow();
-        } catch (SQLException e) {
-            e.printStackTrace();
-        }
-        if (rowCount != 0) {
-            return true;
-        } else {
-            return false;
-        }
-    }
+    }    
 }

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