Print

Print


Author: [log in to unmask]
Date: Mon Apr 27 15:59:36 2015
New Revision: 2832

Log:
Remove the verbose option and use logging instead.

Modified:
    java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/cli/AbstractCommand.java
    java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/cli/AddCommand.java
    java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/cli/LoadCommand.java
    java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/cli/PrintCommand.java

Modified: java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/cli/AbstractCommand.java
 =============================================================================
--- java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/cli/AbstractCommand.java	(original)
+++ java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/cli/AbstractCommand.java	Mon Apr 27 15:59:36 2015
@@ -34,11 +34,6 @@
      * The parser for the options.
      */
     private final Parser parser = new PosixParser();
-
-    /**
-     * Verbose setting.
-     */
-    private boolean verbose = false;
 
     /**
      * Class constructor.
@@ -85,22 +80,6 @@
     }
 
     /**
-     * Set whether verbose output is enabled.
-     * @param verbose <code>true</code> to enable verbose output
-     */
-    final void setVerbose(final boolean verbose) {
-        this.verbose = verbose;
-    }
-
-    /**
-     * Get verbose flag.
-     * @return the verbose flag
-     */
-    protected boolean getVerbose() {
-        return verbose;
-    }
-
-    /**
      * Parse the sub-command's options.
      * @param arguments the sub-command's arguments
      * @return the parsed command line

Modified: java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/cli/AddCommand.java
 =============================================================================
--- java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/cli/AddCommand.java	(original)
+++ java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/cli/AddCommand.java	Mon Apr 27 15:59:36 2015
@@ -20,7 +20,7 @@
  *
  * @author <a href="mailto:[log in to unmask]">Jeremy McCormick</a>
  */
-public class AddCommand extends AbstractCommand {
+final class AddCommand extends AbstractCommand {
 
     /**
      * Setup logger.
@@ -32,17 +32,17 @@
      */
     private static final Options OPTIONS = new Options();
     static {
-        OPTIONS.addOption(new Option("h", false, "Show help for add command"));
-        OPTIONS.addOption("r", true, "The starting run number (required)");
+        OPTIONS.addOption(new Option("h", false, "print help for add command"));
+        OPTIONS.addOption("r", true, "starting run number (required)");
         OPTIONS.getOption("r").setRequired(true);
-        OPTIONS.addOption("e", true, "The ending run number (default is starting run number)");
-        OPTIONS.addOption("t", true, "The table name (required)");
+        OPTIONS.addOption("e", true, "ending run number (default is starting run number)");
+        OPTIONS.addOption("t", true, "table name (required)");
         OPTIONS.getOption("t").setRequired(true);
-        OPTIONS.addOption("c", true, "The collection ID (required)");
+        OPTIONS.addOption("c", true, "collection ID (required)");
         OPTIONS.getOption("c").setRequired(true);
-        OPTIONS.addOption("T", true, "A tag value (optional)");
-        OPTIONS.addOption("u", true, "Your user name (optional)");
-        OPTIONS.addOption("m", true, "The notes about this conditions set (optional)");
+        OPTIONS.addOption("T", true, "tag value (optional)");
+        OPTIONS.addOption("u", true, "user name (optional)");
+        OPTIONS.addOption("m", true, "notes about this conditions set (optional)");
     }
 
     /**

Modified: java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/cli/LoadCommand.java
 =============================================================================
--- java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/cli/LoadCommand.java	(original)
+++ java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/cli/LoadCommand.java	Mon Apr 27 15:59:36 2015
@@ -32,7 +32,7 @@
  *
  * @author <a href="mailto:[log in to unmask]">Jeremy McCormick</a>
  */
-class LoadCommand extends AbstractCommand {
+final class LoadCommand extends AbstractCommand {
 
     /**
      * Setup logger.
@@ -44,10 +44,10 @@
      */
     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, "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"));
+        OPTIONS.addOption(new Option("h", false, "print help for load command"));
+        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"));
     }
 
     /**
@@ -105,9 +105,8 @@
         this.parseFile(fileName, columnNames, rows);
 
         final String insertSql = QueryBuilder.buildInsert(tableName, collectionId, columnNames, rows);
-        if (this.getVerbose()) {
-            LOGGER.info(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);

Modified: java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/cli/PrintCommand.java
 =============================================================================
--- java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/cli/PrintCommand.java	(original)
+++ java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/cli/PrintCommand.java	Mon Apr 27 15:59:36 2015
@@ -26,7 +26,7 @@
  *
  * @author <a href="mailto:[log in to unmask]">Jeremy McCormick</a>
  */
-class PrintCommand extends AbstractCommand {
+final class PrintCommand extends AbstractCommand {
 
     /**
      * Setup logger.
@@ -39,13 +39,12 @@
     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"));
-        options.addOption(new Option("i", false, "Print the ID for the records (off by default)"));
-        options.addOption(new Option("f", true, "Write print output to a file (must be used with -t option)"));
-        options.addOption(new Option("H", false, "Suppress printing of conditions record and table info"));
-        options.addOption(new Option("d", false, "Use tabs for field delimiter instead of spaces"));
-        options.addOption(new Option("T", true, "Specify a conditions tag to use for filtering records"));
+        options.addOption(new Option("h", false, "print help for print command"));
+        options.addOption(new Option("t", true, "table name"));
+        options.addOption(new Option("i", false, "print the ID for the records (off by default)"));
+        options.addOption(new Option("f", true, "write print output to a file (must be used with -t option)"));
+        options.addOption(new Option("H", false, "suppress printing of conditions record and table info"));
+        options.addOption(new Option("d", false, "use tabs for field delimiter instead of spaces"));
     }
 
     /**
@@ -94,11 +93,6 @@
 
         if (!conditionsManager.isInitialized()) {
             throw new RuntimeException("conditions system is not initialized");
-        }
-
-        // User specified tag of conditions records.
-        if (commandLine.hasOption("T")) {
-            conditionsManager.setTag(commandLine.getOptionValue("T"));
         }
 
         // Print conditions sets matching a specific conditions key.
@@ -178,8 +172,10 @@
         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);
+            	if (!"collection_id".equals(columnName)) {
+            		buffer.append(((ConditionsObject) object).getFieldValue(columnName));
+            		buffer.append(this.fieldDelimiter);
+            	}
             }
             buffer.setLength(buffer.length() - 1);
             buffer.append('\n');
@@ -195,8 +191,10 @@
      * @param collection the collection
      */
     private void printCollectionHeader(final ConditionsObjectCollection<?> collection) {
-        // LOGGER.info('\n' + "--------------------------------------" + '\n' + collection.getConditionsRecord()
-        // + "--------------------------------------");
+        LOGGER.info('\n' + "--------------------------------------" + '\n' 
+        		+ "table: " + collection.getTableMetaData().getTableName() + '\n'
+        		+ "collection ID: " + collection.getCollectionId() + '\n'
+        		+ "--------------------------------------");
     }
 
     /**
@@ -228,8 +226,10 @@
             this.ps.print(this.fieldDelimiter);
         }
         for (final String columnName : tableMetaData.getFieldNames()) {
-            this.ps.print(columnName);
-            this.ps.print(this.fieldDelimiter);
+        	if (!"collection_id".equals(columnName)) {
+        		this.ps.print(columnName);
+        		this.ps.print(this.fieldDelimiter);
+        	}
         }
         this.ps.println();
     }