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  April 2015

HPS-SVN April 2015

Subject:

r2742 - in /java/branches/conditions-HPSJAVA-488: ./ src/main/java/org/hps/conditions/cli/ src/main/java/org/hps/conditions/database/

From:

[log in to unmask]

Reply-To:

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

Date:

Fri, 17 Apr 2015 21:58:46 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (1009 lines)

Author: [log in to unmask]
Date: Fri Apr 17 14:58:38 2015
New Revision: 2742

Log:
Merge trunk changes into conditions dev branch.

Modified:
    java/branches/conditions-HPSJAVA-488/   (props changed)
    java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/cli/AddCommand.java
    java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/cli/CommandLineTool.java
    java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/cli/LoadCommand.java
    java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/cli/PrintCommand.java
    java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/cli/TagCommand.java
    java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/database/DatabaseConditionsManager.java
    java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/database/QueryBuilder.java
    java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/database/TableMetaData.java

Modified: java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/cli/AddCommand.java
 =============================================================================
--- java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/cli/AddCommand.java	(original)
+++ java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/cli/AddCommand.java	Fri Apr 17 14:58:38 2015
@@ -1,7 +1,8 @@
 package org.hps.conditions.cli;
 
-import java.io.PrintStream;
 import java.util.Date;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.Option;
@@ -10,6 +11,7 @@
 import org.hps.conditions.api.ConditionsRecord;
 import org.hps.conditions.api.FieldValueMap;
 import org.hps.conditions.database.DatabaseConditionsManager;
+import org.lcsim.util.log.LogUtil;
 
 /**
  * This is a command for the conditions CLI that will add a conditions record, making a conditions set with a particular
@@ -20,9 +22,9 @@
 public class AddCommand extends AbstractCommand {
 
     /**
-     * For printing out messages.
+     * Setup logger.
      */
-    private final PrintStream ps = System.out;
+    private static final Logger LOGGER = LogUtil.create(AddCommand.class);
 
     /**
      * Define command line options.
@@ -50,10 +52,46 @@
     }
 
     /**
+     * Create a conditions record.
+     *
+     * @param runStart the run start
+     * @param runEnd the run end
+     * @param tableName the table name
+     * @param name the key name
+     * @param collectionId the collection ID
+     * @param createdBy the user name
+     * @param tag the conditions tag
+     * @param notes the text notes about the collection
+     * @return the new conditions record
+     */
+    // FIXME: Too many method parameters (max 7 is recommended).
+    private ConditionsRecord createConditionsRecord(final int runStart, final int runEnd, final String tableName,
+            final String name, final int collectionId, final String createdBy, final String tag, final String notes) {
+        final ConditionsRecord conditionsRecord = new ConditionsRecord();
+        final FieldValueMap fieldValues = new FieldValueMap();
+        fieldValues.put("run_start", runStart);
+        fieldValues.put("run_end", runEnd);
+        fieldValues.put("table_name", tableName);
+        fieldValues.put("name", name);
+        fieldValues.put("collection_id", collectionId);
+        fieldValues.put("created_by", createdBy);
+        if (tag != null) {
+            fieldValues.put("tag", tag);
+        }
+        if (notes != null) {
+            fieldValues.put("notes", notes);
+        }
+        conditionsRecord.setFieldValues(fieldValues);
+        fieldValues.put("created", new Date());
+        return conditionsRecord;
+    }
+
+    /**
      * Execute the command with the given arguments.
      *
      * @param arguments the command line arguments
      */
+    @Override
     final void execute(final String[] arguments) {
 
         final CommandLine commandLine = parse(arguments);
@@ -124,45 +162,10 @@
             }
             conditionsRecord.insert();
             manager.closeConnection(createdConnection);
-        } catch (ConditionsObjectException e) {
+        } catch (final ConditionsObjectException e) {
+            LOGGER.log(Level.SEVERE, "Error adding conditions record", e);
             throw new RuntimeException("An error occurred while adding a conditions record.", e);
         }
-        ps.println("successfully added conditions record ...");
-        ps.println(conditionsRecord);
-    }
-
-    /**
-     * Create a conditions record.
-     *
-     * @param runStart the run start
-     * @param runEnd the run end
-     * @param tableName the table name
-     * @param name the key name
-     * @param collectionId the collection ID
-     * @param createdBy the user name
-     * @param tag the conditions tag
-     * @param notes the text notes about the collection
-     * @return the new conditions record
-     */
-    // FIXME: Too many method parameters (max 7 is recommended).
-    private ConditionsRecord createConditionsRecord(final int runStart, final int runEnd, final String tableName,
-            final String name, final int collectionId, final String createdBy, final String tag, final String notes) {
-        final ConditionsRecord conditionsRecord = new ConditionsRecord();
-        final FieldValueMap fieldValues = new FieldValueMap();
-        fieldValues.put("run_start", runStart);
-        fieldValues.put("run_end", runEnd);
-        fieldValues.put("table_name", tableName);
-        fieldValues.put("name", name);
-        fieldValues.put("collection_id", collectionId);
-        fieldValues.put("created_by", createdBy);
-        if (tag != null) {
-            fieldValues.put("tag", tag);
-        }
-        if (notes != null) {
-            fieldValues.put("notes", notes);
-        }
-        conditionsRecord.setFieldValues(fieldValues);
-        fieldValues.put("created", new Date());
-        return conditionsRecord;
+        LOGGER.info("successfully added conditions record ..." + '\n' + conditionsRecord);
     }
 }

Modified: java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/cli/CommandLineTool.java
 =============================================================================
--- java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/cli/CommandLineTool.java	(original)
+++ java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/cli/CommandLineTool.java	Fri Apr 17 14:58:38 2015
@@ -14,7 +14,6 @@
 import org.apache.commons.cli.PosixParser;
 import org.hps.conditions.database.DatabaseConditionsManager;
 import org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException;
-import org.lcsim.util.log.DefaultLogFormatter;
 import org.lcsim.util.log.LogUtil;
 
 /**
@@ -26,18 +25,16 @@
  *
  * @author <a href="mailto:[log in to unmask]">Jeremy McCormick</a>
  */
-// FIXME: Print outs should use conditions manager's log settings and not boolean verbose flag.
 public class CommandLineTool {
 
     /**
      * Setup logging.
      */
-    private static final Logger LOGGER = LogUtil.create(CommandLineTool.class.getSimpleName(),
-            new DefaultLogFormatter(), Level.WARNING);
+    private static final Logger LOGGER = LogUtil.create(CommandLineTool.class);
 
     /**
      * Create a basic instance of this class.
-     * 
+     *
      * @return the instance of this class
      */
     private static CommandLineTool create() {
@@ -112,7 +109,7 @@
 
     /**
      * Register a sub-command handler.
-     * 
+     *
      * @param command the sub-command handler
      */
     private void registerCommand(final AbstractCommand command) {

Modified: java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/cli/LoadCommand.java
 =============================================================================
--- java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/cli/LoadCommand.java	(original)
+++ java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/cli/LoadCommand.java	Fri Apr 17 14:58:38 2015
@@ -7,12 +7,14 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.StringTokenizer;
+import java.util.logging.Logger;
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.Option;
 import org.apache.commons.cli.Options;
 import org.hps.conditions.database.DatabaseConditionsManager;
 import org.hps.conditions.database.QueryBuilder;
+import org.lcsim.util.log.LogUtil;
 
 /**
  * This is a sub-command to add conditions data using an input text file. The file should be ASCII text that is tab or
@@ -21,6 +23,7 @@
  * exist already in the table. Otherwise, the command will fail. By default, the next collection ID will be found by the
  * conditions manager.
  * <p>
+ *
  * <pre>
  * java -cp hps-distribution-bin.jar org.hps.conditions.cli.CommandLineTool \
  *     -p conditions_dev_local.properties load -t scratch_svt_gains -f ./scratch_svt_gains.txt -c 1
@@ -29,6 +32,11 @@
  * @author <a href="mailto:[log in to unmask]">Jeremy McCormick</a>
  */
 class LoadCommand extends AbstractCommand {
+
+    /**
+     * Setup logger.
+     */
+    private static final Logger LOGGER = LogUtil.create(LoadCommand.class);
 
     /**
      * Define command options.
@@ -62,7 +70,7 @@
         if (fileName == null) {
             throw new IllegalArgumentException("Missing file argument.");
         }
-        if (!(new File(fileName)).exists()) {
+        if (!new File(fileName).exists()) {
             throw new IllegalArgumentException("Input file does not exist: " + fileName);
         }
 
@@ -95,24 +103,24 @@
 
         final String insertSql = QueryBuilder.buildInsert(tableName, collectionID, columnNames, rows);
         if (getVerbose()) {
-            System.out.println(insertSql);
+            LOGGER.info(insertSql);
         }
         // FIXME: This call should go through an object API like ConditionsObjectCollection.insert rather than the
         // manager directly.
         final List<Integer> ids = conditionsManager.updateQuery(insertSql);
-        System.out.println("Inserted " + ids.size() + " new rows into table " + tableName + " with collection_id "
+        LOGGER.info("Inserted " + ids.size() + " new rows into table " + tableName + " with collection_id "
                 + collectionID);
         conditionsManager.closeConnection(openedConnection);
     }
 
     /**
      * Parse an input text file and add column names and row data to the input lists.
+     *
      * @param fileName the name of the text file
      * @param columnNames the list of columns (modified by this method)
      * @param rows the list of rows (modified by this method)
      */
-    private final void parseFile(final String fileName, final List<String> columnNames, 
-            final List<List<String>> rows) {
+    private final void parseFile(final String fileName, final List<String> columnNames, final List<List<String>> rows) {
         final File inputFile = new File(fileName);
         BufferedReader reader = null;
         try {
@@ -134,13 +142,13 @@
                 }
                 rows.add(row);
             }
-        } catch (Exception e) {
+        } catch (final Exception e) {
             throw new RuntimeException(e);
         } finally {
             if (reader != null) {
                 try {
                     reader.close();
-                } catch (IOException e) {
+                } catch (final IOException e) {
                     e.printStackTrace();
                 }
             }

Modified: java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/cli/PrintCommand.java
 =============================================================================
--- java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/cli/PrintCommand.java	(original)
+++ java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/cli/PrintCommand.java	Fri Apr 17 14:58:38 2015
@@ -8,6 +8,7 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
+import java.util.logging.Logger;
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.Option;
@@ -17,6 +18,7 @@
 import org.hps.conditions.api.ConditionsRecord.ConditionsRecordCollection;
 import org.hps.conditions.database.DatabaseConditionsManager;
 import org.hps.conditions.database.TableMetaData;
+import org.lcsim.util.log.LogUtil;
 
 /**
  * This sub-command of the conditions CLI prints conditions conditions table data by run number to the console or
@@ -27,34 +29,15 @@
 class PrintCommand extends AbstractCommand {
 
     /**
-     * Print stream for output.
-     */
-    private PrintStream ps = System.out;
-
-    /**
-     * Flag to print row IDs.
-     */
-    private boolean printIDs = false;
-
-    /**
-     * Flag to print out column headers.
-     */
-    private boolean printHeaders = true;
-
-    /**
-     * The field delimiter for print output.
-     */
-    private char fieldDelimiter = ' ';
-
-    /**
-     * Output file if printing to a file.
-     */
-    private File outputFile;
-    
+     * Setup logger.
+     */
+    private static final Logger LOGGER = LogUtil.create(PrintCommand.class);
+
     /**
      * Defines command options.
      */
     static Options options = new Options();
+
     static {
         options.addOption(new Option("h", false, "Show help for print command"));
         options.addOption(new Option("t", true, "Set the table name"));
@@ -66,6 +49,31 @@
     }
 
     /**
+     * The field delimiter for print output.
+     */
+    private char fieldDelimiter = ' ';
+
+    /**
+     * Output file if printing to a file.
+     */
+    private File outputFile;
+
+    /**
+     * Flag to print out column headers.
+     */
+    private boolean printHeaders = true;
+
+    /**
+     * Flag to print row IDs.
+     */
+    private boolean printIDs = false;
+
+    /**
+     * This is the <code>PrintStream</code> for printing the collections to the console or a file.
+     */
+    private PrintStream ps = System.out;
+
+    /**
      * Class constructor.
      */
     PrintCommand() {
@@ -77,6 +85,7 @@
      *
      * @param arguments the command line arguments
      */
+    @Override
     final void execute(final String[] arguments) {
 
         final CommandLine commandLine = parse(arguments);
@@ -107,27 +116,27 @@
             if (new File(path).exists()) {
                 throw new IllegalArgumentException("File already exists: " + path);
             }
-            outputFile = new File(path);
+            this.outputFile = new File(path);
             try {
-                ps = new PrintStream(new BufferedOutputStream(new FileOutputStream(outputFile, false)));
-            } catch (FileNotFoundException e) {
+                this.ps = new PrintStream(new BufferedOutputStream(new FileOutputStream(this.outputFile, false)));
+            } catch (final FileNotFoundException e) {
                 throw new IllegalArgumentException(e);
             }
         }
 
         // Print IDs in the output.
         if (commandLine.hasOption("i")) {
-            printIDs = true;
+            this.printIDs = true;
         }
 
         // Print header info. Option turns this off.
         if (commandLine.hasOption("h")) {
-            printHeaders = false;
+            this.printHeaders = false;
         }
 
         // Use tabs instead of spaces for field delimiter.
         if (commandLine.hasOption("d")) {
-            fieldDelimiter = '\t';
+            this.fieldDelimiter = '\t';
         }
 
         // List of conditions records to print.
@@ -135,11 +144,11 @@
 
         // Did the user specify a table to use?
         if (userConditionsKey == null) {
-            System.out.println("printing all conditions");
+            LOGGER.info("printing all conditions");
             // Use all table names if there was not one specified.
             conditionsRecords.addAll(conditionsManager.getConditionsRecords());
         } else {
-            System.out.println("printing conditions with name: " + userConditionsKey);
+            LOGGER.info("printing conditions with name: " + userConditionsKey);
             // Get records only for the user specified table name.
             conditionsRecords.addAll(conditionsManager.findConditionsRecords(userConditionsKey));
         }
@@ -152,12 +161,77 @@
 
         // Print the records and the data.
         printConditionsRecords(conditionsKeys);
-        ps.flush();
-        ps.close();
-
-        if (outputFile != null) {
-            System.out.println("wrote collection data to file " + outputFile.getPath());
-        }
+        this.ps.flush();
+        this.ps.close();
+
+        if (this.outputFile != null) {
+            LOGGER.info("wrote collection data to file " + this.outputFile.getPath());
+        }
+    }
+
+    /**
+     * Print a single collection.
+     *
+     * @param collection the collection to print
+     */
+    private void printCollection(final ConditionsObjectCollection<?> collection) {
+        final StringBuffer buffer = new StringBuffer();
+        for (final Object object : collection) {
+            for (final String columnName : collection.getTableMetaData().getFieldNames()) {
+                buffer.append(((ConditionsObject) object).getFieldValue(columnName));
+                buffer.append(this.fieldDelimiter);
+            }
+            buffer.setLength(buffer.length() - 1);
+            buffer.append('\n');
+        }
+        buffer.setLength(buffer.length() - 1);
+        this.ps.print(buffer.toString());
+        this.ps.flush();
+    }
+
+    /**
+     * Print the header for a collection. This is printed to the log rather than the <code>PrintStream</code>.
+     *
+     * @param collection the collection
+     */
+    private void printCollectionHeader(final ConditionsObjectCollection<?> collection) {
+        LOGGER.info('\n' + "--------------------------------------" + '\n' + collection.getConditionsRecord()
+                + "--------------------------------------");
+    }
+
+    /**
+     * Print the list of collections.
+     *
+     * @param collectionList the list of collections
+     */
+    private void printCollections(final List<ConditionsObjectCollection<?>> collectionList) {
+        // Loop over all the collections and print them.
+        for (final ConditionsObjectCollection<?> collection : collectionList) {
+            if (this.printHeaders) {
+                printCollectionHeader(collection);
+            }
+            printColumnNames(collection.getTableMetaData());
+            printCollection(collection);
+            this.ps.println();
+        }
+        this.ps.flush();
+    }
+
+    /**
+     * Print the column names for a table.
+     *
+     * @param tableMetaData the table meta data
+     */
+    private void printColumnNames(final TableMetaData tableMetaData) {
+        if (this.printIDs) {
+            this.ps.print("id");
+            this.ps.print(this.fieldDelimiter);
+        }
+        for (final String columnName : tableMetaData.getFieldNames()) {
+            this.ps.print(columnName);
+            this.ps.print(this.fieldDelimiter);
+        }
+        this.ps.println();
     }
 
     /**
@@ -169,13 +243,14 @@
 
         final DatabaseConditionsManager conditionsManager = DatabaseConditionsManager.getInstance();
 
-        System.out.print("printing conditions sets: ");
-        for (String conditionsKey : conditionsKeys) {
-            System.out.print(conditionsKey + " ");
-        }
-        System.out.println();
+        final StringBuffer sb = new StringBuffer();
+        for (final String conditionsKey : conditionsKeys) {
+            sb.append(conditionsKey + " ");
+        }
+        LOGGER.info("printing conditions sets: " + sb.toString());
+
         // Loop over the conditions keys from the conditions records.
-        for (String conditionsKey : conditionsKeys) {
+        for (final String conditionsKey : conditionsKeys) {
 
             // The list of collections to print.
             final List<ConditionsObjectCollection<?>> collectionList = new ArrayList<ConditionsObjectCollection<?>>();
@@ -199,68 +274,4 @@
             printCollections(collectionList);
         }
     }
-
-    /**
-     * Print the list of collections.
-     * @param collectionList the list of collections
-     */
-    private void printCollections(final List<ConditionsObjectCollection<?>> collectionList) {
-        // Loop over all the collections and print them.
-        for (ConditionsObjectCollection<?> collection : collectionList) {
-            if (printHeaders) {
-                printCollectionHeader(collection);
-            }
-            printColumnNames(collection.getTableMetaData());
-            printCollection(collection);
-            System.out.println();
-        }
-        ps.flush();
-    }
-
-    /**
-     * Print a single collection.
-     * @param collection the collection to print
-     */
-    private void printCollection(final ConditionsObjectCollection<?> collection) {
-        final StringBuffer buffer = new StringBuffer();
-        for (Object object : collection) {
-            for (String columnName : collection.getTableMetaData().getFieldNames()) {
-                buffer.append(((ConditionsObject) object).getFieldValue(columnName));
-                buffer.append(fieldDelimiter);
-            }
-            buffer.setLength(buffer.length() - 1);
-            buffer.append('\n');
-        }
-        buffer.setLength(buffer.length() - 1);
-        ps.print(buffer.toString());
-        ps.flush();
-    }
-
-    /**
-     * Print the header for a collection.
-     * @param collection the collection
-     */
-    private void printCollectionHeader(final ConditionsObjectCollection<?> collection) {
-        System.out.println("--------------------------------------");
-        System.out.print(collection.getConditionsRecord());
-        System.out.println("--------------------------------------");
-        System.out.println();
-        System.out.flush();
-    }
-
-    /**
-     * Print the column names for a table.
-     * @param tableMetaData the table meta data
-     */
-    private void printColumnNames(final TableMetaData tableMetaData) {
-        if (printIDs) {
-            ps.print("id");
-            ps.print(fieldDelimiter);
-        }
-        for (String columnName : tableMetaData.getFieldNames()) {
-            ps.print(columnName);
-            ps.print(fieldDelimiter);
-        }
-        ps.println();
-    }
 }

Modified: java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/cli/TagCommand.java
 =============================================================================
--- java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/cli/TagCommand.java	(original)
+++ java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/cli/TagCommand.java	Fri Apr 17 14:58:38 2015
@@ -5,6 +5,7 @@
 import java.util.LinkedHashSet;
 import java.util.Set;
 import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.Option;
@@ -16,6 +17,7 @@
 import org.hps.conditions.database.DatabaseConditionsManager;
 import org.hps.conditions.database.TableMetaData;
 import org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException;
+import org.lcsim.util.log.LogUtil;
 
 /**
  * Create a conditions system tag.
@@ -28,6 +30,11 @@
      * The default detector name (dummy detector).
      */
     private static final String DETECTOR_NAME = "HPS-dummy-detector";
+
+    /**
+     * Setup logger.
+     */
+    private static final Logger LOGGER = LogUtil.create(TagCommand.class);
 
     /**
      * Defines command options.
@@ -135,15 +142,15 @@
         }
 
         // Print out all the records that were found.
-        System.out.println("found ConditionsRecords for tag " + newTag + " ...");
+        LOGGER.info("found ConditionsRecords for tag " + newTag + " ...");
         for (final ConditionsRecord record : tagRecords) {
-            System.out.println(record.toString());
+            LOGGER.info(record.toString());
         }
 
         // Prompt user to verify with console input.
         boolean makeTag = true;
         if (!dontPrompt) {
-            System.out.println("Create conditions tag " + newTag + " in database?  (Y/N)");
+            LOGGER.info("Create conditions tag " + newTag + " in database?  (Y/N)");
             final String line = System.console().readLine();
             if (!line.equals("Y")) {
                 makeTag = false;

Modified: java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/database/DatabaseConditionsManager.java
 =============================================================================
--- java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/database/DatabaseConditionsManager.java	(original)
+++ java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/database/DatabaseConditionsManager.java	Fri Apr 17 14:58:38 2015
@@ -485,6 +485,18 @@
     }
 
     /**
+     * Get the JDBC connection.
+     *
+     * @return the JDBC connection
+     */
+    public Connection getConnection() {
+        if (!isConnected()) {
+            openConnection();
+        }
+        return this.connection;
+    }
+
+    /**
      * Get the current LCSim compact <code>Detector</code> object with the geometry and detector model.
      *
      * @return the detector object
@@ -714,8 +726,13 @@
                     .next());
             preparedStatement = this.connection.prepareStatement(sql);
             logger.fine("using prepared statement: " + sql);
+            final int collectionId = collection.getCollectionId();
             for (final ConditionsObject object : collection) {
-                int parameterIndex = 1;
+                preparedStatement.setObject(1, collectionId);
+                int parameterIndex = 2;
+                if (object instanceof ConditionsRecord) {
+                    parameterIndex = 1;
+                }
                 for (final Entry<String, Object> entry : object.getFieldValues().entrySet()) {
                     preparedStatement.setObject(parameterIndex, entry.getValue());
                     ++parameterIndex;

Modified: java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/database/QueryBuilder.java
 =============================================================================
--- java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/database/QueryBuilder.java	(original)
+++ java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/database/QueryBuilder.java	Fri Apr 17 14:58:38 2015
@@ -5,6 +5,7 @@
 import java.util.List;
 
 import org.hps.conditions.api.ConditionsObject;
+import org.hps.conditions.api.ConditionsRecord;
 import org.hps.conditions.api.FieldValueMap;
 
 /**
@@ -104,13 +105,20 @@
             throw new IllegalArgumentException("The ConditionsObject has no values set.");
         }
         final StringBuffer buffer = new StringBuffer();
-        buffer.append("INSERT INTO " + tableName + "(");
+        buffer.append("INSERT INTO " + tableName + "( ");
+        // FIXME: Hack for specific type.
+        if (!(object instanceof ConditionsRecord)) {
+            buffer.append("collection_id,");
+        }
         for (final String fieldName : object.getFieldValues().keySet()) {
             buffer.append(" " + fieldName + ",");
         }
         buffer.setLength(buffer.length() - 1);
-        buffer.append(") VALUES (");
-        for (int i = 0; i < object.getFieldValues().keySet().size(); i++) {
+        buffer.append(" ) VALUES ( ");
+        if (!(object instanceof ConditionsRecord)) {
+            buffer.append(" ?,");
+        }
+        for (int i = 0; i < object.getFieldValues().size(); i++) {
             buffer.append(" ?,");
         }
         buffer.setLength(buffer.length() - 1);

Modified: java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/database/TableMetaData.java
 =============================================================================
--- java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/database/TableMetaData.java	(original)
+++ java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/database/TableMetaData.java	Fri Apr 17 14:58:38 2015
@@ -1,7 +1,7 @@
 package org.hps.conditions.database;
 
 import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
@@ -13,12 +13,11 @@
 
 /**
  * <p>
- * This class provides meta data about a conditions table, including a list of
- * conditions data fields. The list of fields does not include the collection ID
- * or row ID, which are implicitly assumed to exist.
+ * This class provides meta data about a conditions table, including a list of conditions data fields. The list of
+ * fields does not include the collection ID or row ID, which are implicitly assumed to exist.
  * <p>
- * It also has references to the implementation classes which are used for the ORM
- * onto {@link ConditionsObject} and {@link ConditionsObjectCollection}.
+ * It also has references to the implementation classes which are used for the ORM onto {@link ConditionsObject} and
+ * {@link ConditionsObjectCollection}.
  *
  * @see org.hps.conditions.api.ConditionsObject
  * @see org.hps.conditions.api.BaseConditionsObjectCollection
@@ -27,37 +26,60 @@
 public final class TableMetaData {
 
     /**
+     * Find table meta data by object type.
+     *
+     * @param tableMetaDataList the list of table meta data e.g. from the registry
+     * @param objectType the type of the object
+     * @return the list of table meta data that have that object type
+     */
+    public static List<TableMetaData> findByObjectType(final List<TableMetaData> tableMetaDataList,
+            final Class<? extends ConditionsObject> objectType) {
+        final List<TableMetaData> list = new ArrayList<TableMetaData>();
+        for (final TableMetaData tableMetaData : tableMetaDataList) {
+            if (tableMetaData.getObjectClass().equals(objectType)) {
+
+                list.add(tableMetaData);
+            }
+        }
+        return list;
+    }
+
+    /**
+     * The collection class.
+     */
+    private Class<? extends BaseConditionsObjectCollection<?>> collectionClass;
+
+    /**
+     * The set of field names.
+     */
+    private Set<String> fieldNames = new LinkedHashSet<String>();
+
+    /**
+     * The map of field names to their types.
+     */
+    private Map<String, Class<?>> fieldTypes;
+
+    /**
+     * The conditions key named (unused???).
+     */
+    private String key;
+
+    /**
+     * The object class.
+     */
+    private Class<? extends ConditionsObject> objectClass;
+
+    /**
      * The table name.
      */
     private String tableName;
 
-    /**
-     * The conditions key named (unused???).
-     */
-    private String key;
-
-    /**
-     * The object class.
-     */
-    private Class<? extends ConditionsObject> objectClass;
-
-    /**
-     * The collection class.
-     */
-    private Class<? extends BaseConditionsObjectCollection<?>> collectionClass;
-
-    /**
-     * The set of field names.
-     */
-    private Set<String> fieldNames = new LinkedHashSet<String>();
-
-    /**
-     * The map of field names to their types.
-     */
-    private Map<String, Class<?>> fieldTypes;
+    public TableMetaData() {
+    }
 
     /**
      * Fully qualified constructor.
+     *
      * @param key the conditions key
      * @param tableName the table name
      * @param objectClass the object class
@@ -65,12 +87,8 @@
      * @param fieldNames the field names
      * @param fieldTypes the field types
      */
-    public TableMetaData(
-            final String key,
-            final String tableName,
-            final Class<? extends ConditionsObject> objectClass,
-            final Class<? extends BaseConditionsObjectCollection<?>> collectionClass,
-            final Set<String> fieldNames,
+    public TableMetaData(final String key, final String tableName, final Class<? extends ConditionsObject> objectClass,
+            final Class<? extends BaseConditionsObjectCollection<?>> collectionClass, final Set<String> fieldNames,
             final Map<String, Class<?>> fieldTypes) {
         if (key == null) {
             throw new IllegalArgumentException("key is null");
@@ -99,83 +117,83 @@
     }
 
     /**
+     * Get the type of collection this table maps onto.
+     *
+     * @return the collection class
+     */
+    public Class<? extends BaseConditionsObjectCollection<?>> getCollectionClass() {
+        return this.collectionClass;
+    }
+
+    /**
+     * Get the names of the fields. Types are implied from the database tables.
+     *
+     * @return the names of the fields
+     */
+    public String[] getFieldNames() {
+        return this.fieldNames.toArray(new String[] {});
+    }
+
+    /**
+     * Get the type of the field called <code>fieldName</code>.
+     *
+     * @return the type of the field
+     */
+    public Class<?> getFieldType(final String fieldName) {
+        return this.fieldTypes.get(fieldName);
+    }
+
+    /**
+     * Get the key of this conditions type. May be different from table name but is usually the same.
+     *
+     * @return the key name of the conditions type
+     */
+    public String getKey() {
+        return this.key;
+    }
+
+    /**
      * Get the type of object this table maps onto.
+     *
      * @return the type of object
      */
     public Class<? extends ConditionsObject> getObjectClass() {
-        return objectClass;
-    }
-
-    /**
-     * Get the type of collection this table maps onto.
-     * @return the collection class
-     */
-    public Class<? extends BaseConditionsObjectCollection<?>> getCollectionClass() {
-        return collectionClass;
-    }
-
-    /**
-     * Get the names of the fields. Types are implied from the database tables.
-     * @return the names of the fields
-     */
-    public String[] getFieldNames() {
-        return fieldNames.toArray(new String[] {});
-    }
-
-    /**
-     * Get the type of the field called <code>fieldName</code>.
-     * @return the type of the field
-     */
-    public Class<?> getFieldType(final String fieldName) {
-        return fieldTypes.get(fieldName);
+        return this.objectClass;
     }
 
     /**
      * Get the name of the table.
+     *
      * @return the name of the table
      */
     public String getTableName() {
-        return tableName;
-    }
-
-    /**
-     * Get the key of this conditions type. May be different from table name but
-     * is usually the same.
-     * @return the key name of the conditions type
-     */
-    public String getKey() {
-        return key;
-    }
-
-    /**
-     * Find table meta data by object type.
-     * @param tableMetaDataList the list of table meta data e.g. from the registry
-     * @param objectType the type of the object
-     * @return the list of table meta data that have that object type
-     */
-    public static List<TableMetaData> findByObjectType(final List<TableMetaData> tableMetaDataList,
-            final Class<? extends ConditionsObject> objectType) {
-        List<TableMetaData> list = new ArrayList<TableMetaData>();
-        for (TableMetaData tableMetaData : tableMetaDataList) {
-            if (tableMetaData.getObjectClass().equals(objectType)) {
-
-                list.add(tableMetaData);
-            }
-        }
-        return list;
-    }
-    
+        return this.tableName;
+    }
+
+    public void setFieldNames(final String[] fieldNames) {
+        this.fieldNames = new HashSet<String>();
+        for (final String fieldName : fieldNames) {
+            this.fieldNames.add(fieldName);
+        }
+    }
+
+    public void setTableName(final String tableName) {
+        this.tableName = tableName;
+    }
+
     /**
      * Convert to a string.
+     *
      * @return This object converted to a string.
      */
+    @Override
     public String toString() {
         final StringBuffer buff = new StringBuffer();
-        buff.append("tableMetaData: tableName = " + this.getTableName());  
+        buff.append("tableMetaData: tableName = " + this.getTableName());
         buff.append(", objectClass = " + this.getObjectClass().getCanonicalName());
         buff.append(", collectionClass = " + this.getCollectionClass().getCanonicalName());
         buff.append(", fieldNames = ");
-        for (String field : this.getFieldNames()) {
+        for (final String field : this.getFieldNames()) {
             buff.append(field + " ");
         }
         buff.setLength(buff.length() - 1);

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