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

HPS-SVN December 2014

Subject:

r1695 - /java/trunk/conditions/src/main/java/org/hps/conditions/database/DatabaseConditionsManager.java

From:

[log in to unmask]

Reply-To:

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

Date:

Thu, 11 Dec 2014 19:36:12 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (102 lines)

Author: [log in to unmask]
Date: Thu Dec 11 11:36:08 2014
New Revision: 1695

Log:
Allow connection parameters to be directly set on the manager.  Improve the insert method for collections.  Modifications to logging levels and messages.

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

Modified: java/trunk/conditions/src/main/java/org/hps/conditions/database/DatabaseConditionsManager.java
 =============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/database/DatabaseConditionsManager.java	(original)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/database/DatabaseConditionsManager.java	Thu Dec 11 11:36:08 2014
@@ -401,6 +401,10 @@
             throw new IllegalArgumentException("The connection properties file does not exist: " + connectionPropertiesFile.getPath());
         connectionParameters = ConnectionParameters.fromProperties(file);
     }
+    
+    public void setConnectionParameters(ConnectionParameters connectionParameters) {
+        this.connectionParameters = connectionParameters;
+    }
 
     /**
      * Set the connection parameters from an embedded resource.
@@ -416,6 +420,7 @@
      * @param tableName The name of the table.
      * @return The next collection ID.
      */
+    // TODO: If there are no records in the table, this method should simply return 1.  (for first collection)
     public int getNextCollectionID(String tableName) {
         TableMetaData tableData = findTableMetaData(tableName);
         if (tableData == null)
@@ -612,17 +617,26 @@
         this.tag = tag;
     }
 
-    public <ObjectType extends ConditionsObject> void insertCollection(AbstractConditionsObjectCollection<ObjectType> collection) throws SQLException {
+    public <ObjectType extends ConditionsObject> void insertCollection(AbstractConditionsObjectCollection<ObjectType> collection) throws SQLException, ConditionsObjectException {
         if (collection == null) {
             throw new IllegalArgumentException("The collection is null.");
         }
         if (collection.size() == 0) {
             throw new IllegalArgumentException("The collection is empty.");
         }
-        if (collection.getTableMetaData() == null) {
-            throw new RuntimeException("The collection does not have table meta data.");
-        }
+
         TableMetaData tableMetaData = collection.getTableMetaData();
+        if (tableMetaData == null) {            
+            List<TableMetaData> tableMetaDataList = this.findTableMetaData(collection.getClass()); 
+            if (tableMetaDataList.size() == 0) {
+                throw new ConditionsObjectException("The conditions object collection is missing table meta data and none could be found by the conditions manager.");
+            } else {
+                // Use a default meta data object from the manager.
+                tableMetaData = tableMetaDataList.get(0);
+                collection.setTableMetaData(tableMetaData);
+                logger.fine("using default table meta data with table " + tableMetaData.getTableName() + " for collection of type " + collection.getClass().getCanonicalName());
+            }
+        }
         if (collection.getCollectionId() == -1) {
             try {
                 collection.setCollectionId(this.getNextCollectionID(tableMetaData.getTableName()));
@@ -636,13 +650,14 @@
         try {
             connection.setAutoCommit(false);
             logger.finest("starting insert transaction");
-            String sql = QueryBuilder.buildPreparedInsert(collection.iterator().next());
+            String sql = QueryBuilder.buildPreparedInsert(tableMetaData.getTableName(), collection.iterator().next());
             PreparedStatement preparedStatement = 
                 connection.prepareStatement(sql);
             logger.finest("using prepared statement: " + sql);
             logger.finest("preparing updates");
+            int collectionId = collection.getCollectionId();
             for (ConditionsObject object : collection) {
-                preparedStatement.setObject(1, object.getCollectionId());
+                preparedStatement.setObject(1, collectionId);
                 int parameterIndex = 2;
                 for (Entry<String,Object> entry : object.getFieldValues().entrySet()) {
                     preparedStatement.setObject(parameterIndex, entry.getValue());
@@ -654,6 +669,8 @@
             connection.commit();
             logger.finest("committed transaction");
         } catch (Exception e) {
+            e.printStackTrace();
+            logger.warning(e.getMessage());
             logger.warning("rolling back transaction");
             connection.rollback();
             logger.warning("transaction was rolled back");
@@ -696,6 +713,10 @@
     
     public static String getDefaultEngRunDetectorName() {
         return DEFAULT_ENG_RUN_DETECTOR;
+    }
+    
+    public void addTableMetaData(TableMetaData tableMetaData) {
+        this.tableMetaData.add(tableMetaData);
     }
 
     /**

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