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:

r2777 - in /java/trunk/conditions/src: main/java/org/hps/conditions/cli/LoadCommand.java main/java/org/hps/conditions/database/DatabaseConditionsManager.java test/java/org/hps/conditions/database/CollectionIdTest.java

From:

[log in to unmask]

Reply-To:

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

Date:

Tue, 21 Apr 2015 23:40:30 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (154 lines)

Author: [log in to unmask]
Date: Tue Apr 21 16:40:21 2015
New Revision: 2777

Log:
Add log and description fields to collections table.  Remove option for supplying a collection ID to load command.

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

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	Tue Apr 21 16:40:21 2015
@@ -4,6 +4,7 @@
 import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
+import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.StringTokenizer;
@@ -44,9 +45,9 @@
     private static final Options OPTIONS = new Options();
     static {
         OPTIONS.addOption(new Option("h", false, "Show help for load command"));
-        OPTIONS.addOption(new Option("t", true, "Set the name of the target table in the database"));
-        OPTIONS.addOption(new Option("c", true, "Set the collection ID of this conditions set"));
-        OPTIONS.addOption(new Option("f", true, "Set the input data file"));
+        OPTIONS.addOption(new Option("t", true, "Name of the target table in the database"));
+        OPTIONS.addOption(new Option("f", true, "Input data file"));
+        OPTIONS.addOption(new Option("d", true, "Description of collection data"));
     }
 
     /**
@@ -64,7 +65,7 @@
     @Override
     public void execute(final String[] arguments) {
 
-        final CommandLine commandLine = parse(arguments);
+        final CommandLine commandLine = this.parse(arguments);
 
         final String fileName = commandLine.getOptionValue("f");
         if (fileName == null) {
@@ -86,30 +87,32 @@
             openedConnection = conditionsManager.openConnection();
         }
 
-        int collectionID;
-        if (commandLine.getOptionValue("c") != null) {
-            collectionID = Integer.parseInt(commandLine.getOptionValue("c"));
-            if (conditionsManager.collectionExists(tableName, collectionID)) {
-                throw new IllegalArgumentException("The user supplied collection ID " + collectionID
-                        + " already exists in this table.");
-            }
-        } else {
-            collectionID = conditionsManager.getNextCollectionID(tableName);
+        String collectionDescription = null;
+        if (commandLine.hasOption("d")) {
+            collectionDescription = commandLine.getOptionValue("d");
+        }
+
+        int collectionId;
+        try {
+            collectionId = conditionsManager.addCollection(tableName,
+                    "loaded with command line client by " + System.getProperty("user.name"), collectionDescription);
+        } catch (final SQLException e) {
+            throw new RuntimeException("Error getting new collection ID.", e);
         }
 
         final List<String> columnNames = new ArrayList<String>();
         final List<List<String>> rows = new ArrayList<List<String>>();
-        parseFile(fileName, columnNames, rows);
+        this.parseFile(fileName, columnNames, rows);
 
-        final String insertSql = QueryBuilder.buildInsert(tableName, collectionID, columnNames, rows);
-        if (getVerbose()) {
+        final String insertSql = QueryBuilder.buildInsert(tableName, collectionId, columnNames, rows);
+        if (this.getVerbose()) {
             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);
         LOGGER.info("Inserted " + ids.size() + " new rows into table " + tableName + " with collection_id "
-                + collectionID);
+                + collectionId);
         conditionsManager.closeConnection(openedConnection);
     }
 

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	Tue Apr 21 16:40:21 2015
@@ -285,7 +285,8 @@
      * @return the collection's ID
      * @throws SQLException
      */
-    public synchronized int addCollection(final String tableName, final String comment) throws SQLException {
+    public synchronized int addCollection(final String tableName, final String log, final String description)
+            throws SQLException {
         if (tableName == null) {
             throw new IllegalArgumentException("The tableName argument is null.");
         }
@@ -295,16 +296,21 @@
         int collectionId = -1;
         try {
             statement = this.connection.prepareStatement(
-                    "INSERT INTO collections (table_name, comment, created) VALUES (?, ?, ?)",
+                    "INSERT INTO collections (table_name, log, description, created) VALUES (?, ?, ?, ?)",
                     Statement.RETURN_GENERATED_KEYS);
             statement.setString(1, tableName);
-            if (comment == null) {
+            if (log == null) {
                 statement.setNull(2, java.sql.Types.VARCHAR);
             } else {
-                statement.setString(2, comment);
-            }
-            statement.setDate(3, new java.sql.Date(Calendar.getInstance().getTime().getTime()));
-            final boolean result = statement.execute();
+                statement.setString(2, log);
+            }
+            if (description == null) {
+                statement.setNull(3, java.sql.Types.VARCHAR);
+            } else {
+                statement.setString(3, description);
+            }
+            statement.setDate(4, new java.sql.Date(Calendar.getInstance().getTime().getTime()));
+            statement.execute();
             resultSet = statement.getGeneratedKeys();
             resultSet.next();
             collectionId = resultSet.getInt(1);

Modified: java/trunk/conditions/src/test/java/org/hps/conditions/database/CollectionIdTest.java
 =============================================================================
--- java/trunk/conditions/src/test/java/org/hps/conditions/database/CollectionIdTest.java	(original)
+++ java/trunk/conditions/src/test/java/org/hps/conditions/database/CollectionIdTest.java	Tue Apr 21 16:40:21 2015
@@ -43,10 +43,10 @@
      * @throws SQLException if there is an error executing SQL queries
      */
     public void testCollectionId() throws SQLException {
-        int collectionId = this.manager.addCollection("dummy", "foo bar baz");
+        int collectionId = this.manager.addCollection("dummy", "test add", "foo bar baz");
         System.out.println("created new collection " + collectionId);
 
-        collectionId = this.manager.addCollection("dummy", null);
+        collectionId = this.manager.addCollection("dummy", null, null);
         System.out.println("created new collection " + collectionId);
     }
 }

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