Print

Print


Author: [log in to unmask]
Date: Tue Sep 29 13:07:36 2015
New Revision: 3733

Log:
Add additional methods to run db manager.

Modified:
    java/trunk/run-database/src/main/java/org/hps/run/database/RunManager.java

Modified: java/trunk/run-database/src/main/java/org/hps/run/database/RunManager.java
 =============================================================================
--- java/trunk/run-database/src/main/java/org/hps/run/database/RunManager.java	(original)
+++ java/trunk/run-database/src/main/java/org/hps/run/database/RunManager.java	Tue Sep 29 13:07:36 2015
@@ -21,24 +21,20 @@
  * @author Jeremy McCormick, SLAC
  */
 public final class RunManager implements ConditionsListener {
-    
+
     /**
      * Simple class for caching data.
      */
     private class DataCache {
+
+        List<EpicsData> epicsData;
+        RunSummary fullRunSummary;
         Boolean runExists;
+        RunSummary runSummary;
+        List<ScalerData> scalerData;
         TriggerConfig triggerConfig;
-        List<EpicsData> epicsData;
-        List<ScalerData> scalerData;
-        RunSummary runSummary;
-        RunSummary fullRunSummary;
-    }
-    
-    /**
-     * The data cache of run information.
-     */
-    private DataCache dataCache;
-   
+    }
+
     /**
      * The default connection parameters for read-only access to the run database.
      */
@@ -78,33 +74,47 @@
     private final ConnectionParameters connectionParameters = DEFAULT_CONNECTION_PARAMETERS;
 
     /**
+     * The data cache of run information.
+     */
+    private DataCache dataCache;
+
+    /**
+     * Factory for creating database API objects.
+     */
+    private final RunDatabaseDaoFactory factory;
+
+    /**
      * The run number; the -1 value indicates that this has not been set externally yet.
      */
     private Integer run = null;
 
-    /**
-     * Factory for creating database API objects.
-     */
-    private RunDatabaseDaoFactory factory;
-    
-    /**
-     * Class constructor.
-     * 
-     * @param connection the database connection
-     */
-    public RunManager(Connection connection) {
-        this.connection = connection;
-        openConnection();
-        factory = new RunDatabaseDaoFactory(this.connection);
-    }
-    
     /**
      * Class constructor using default connection parameters.
      */
     public RunManager() {
         this.connection = DEFAULT_CONNECTION_PARAMETERS.createConnection();
-        openConnection();
+        this.openConnection();
         factory = new RunDatabaseDaoFactory(this.connection);
+    }
+
+    /**
+     * Class constructor.
+     *
+     * @param connection the database connection
+     */
+    public RunManager(final Connection connection) {
+        this.connection = connection;
+        this.openConnection();
+        factory = new RunDatabaseDaoFactory(this.connection);
+    }
+
+    /**
+     * Check if the run number has been set.
+     */
+    private void checkRunNumber() {
+        if (this.run == null) {
+            throw new IllegalStateException("The run number was not set.");
+        }
     }
 
     /**
@@ -117,12 +127,12 @@
             }
         } catch (final SQLException e) {
             e.printStackTrace();
-        }        
+        }
     }
 
     /**
      * Load new run information when conditions have changed.
-     * 
+     *
      * @param conditionsEvent the event with new conditions information
      */
     @Override
@@ -131,6 +141,66 @@
     }
 
     /**
+     * Delete a run from the database.
+     *
+     * @param run the run number
+     */
+    public void deleteRun() {
+        // Create object for updating run info in the database.
+        final RunSummaryDao runSummaryDao = factory.createRunSummaryDao();
+
+        // Delete run from the database.
+        runSummaryDao.deleteFullRun(run);
+    }
+
+    /**
+     * Return the database connection.
+     *
+     * @return the database connection
+     */
+    Connection getConnection() {
+        return this.connection;
+    }
+
+    /**
+     * Get the EPICS data for the current run.
+     *
+     * @param epicsType the type of EPICS data
+     * @return the EPICS data for the current run
+     */
+    public List<EpicsData> getEpicsData(final EpicsType epicsType) {
+        this.checkRunNumber();
+        if (this.dataCache.epicsData == null) {
+            LOGGER.info("loading EPICS data for run " + this.run);
+            this.dataCache.epicsData = factory.createEpicsDataDao().getEpicsData(epicsType, this.run);
+        }
+        return this.dataCache.epicsData;
+    }
+
+    /**
+     * Get the EPICS variables.
+     *
+     * @param epicsType the type of EPICS data
+     * @return the EPICS data for the current run
+     */
+    public List<EpicsVariable> getEpicsVariables(final EpicsType epicsType) {
+        return factory.createEpicsVariableDao().getEpicsVariables(epicsType);
+    }
+
+    /**
+     * Get the full run summary for the current run including scaler data, etc.
+     *
+     * @return the full run summary for the current run
+     */
+    public RunSummary getFullRunSummary() {
+        this.checkRunNumber();
+        if (this.dataCache.fullRunSummary == null) {
+            this.dataCache.fullRunSummary = factory.createRunSummaryDao().readFullRunSummary(this.run);
+        }
+        return this.dataCache.fullRunSummary;
+    }
+
+    /**
      * Get the current run number.
      *
      * @return the run number
@@ -146,6 +216,74 @@
      */
     public List<Integer> getRuns() {
         return new RunSummaryDaoImpl(this.connection).getRuns();
+    }
+
+    /**
+     * Get the full list of summaries for all runs in the database without complex data like EPICS records.
+     *
+     * @return the full list of run summaries
+     */
+    public List<RunSummary> getRunSummaries() {
+        return this.factory.createRunSummaryDao().getRunSummaries();
+    }
+
+    /**
+     * Get the run summary for the current run not including its sub-objects like scaler data.
+     *
+     * @return the run summary for the current run
+     */
+    public RunSummary getRunSummary() {
+        this.checkRunNumber();
+        if (this.dataCache.runSummary == null) {
+            this.dataCache.runSummary = factory.createRunSummaryDao().getRunSummary(this.run);
+        }
+        return this.dataCache.runSummary;
+    }
+
+    /**
+     * Get the scaler data for the current run.
+     *
+     * @return the scaler data for the current run
+     */
+    public List<ScalerData> getScalerData() {
+        this.checkRunNumber();
+        if (this.dataCache.scalerData == null) {
+            LOGGER.info("loading scaler data for run " + this.run);
+            this.dataCache.scalerData = factory.createScalerDataDao().getScalerData(run);
+        }
+        return this.dataCache.scalerData;
+    }
+
+    /**
+     * Get the trigger config for the current run.
+     *
+     * @return the trigger config for the current run
+     */
+    public TriggerConfig getTriggerConfig() {
+        this.checkRunNumber();
+        if (this.dataCache.triggerConfig == null) {
+            LOGGER.info("loading trigger config for run " + this.run);
+            this.dataCache.triggerConfig = factory.createTriggerConfigDao().getTriggerConfig(run);
+        }
+        return this.dataCache.triggerConfig;
+    }
+
+    /**
+     * Update the database with information found from crawling the files.
+     *
+     * @param runs the list of runs to update
+     * @throws SQLException if there is a database query error
+     */
+    public void insertRun(final RunSummary runSummary) throws SQLException {
+        LOGGER.info("updating run database for run " + runSummary.getRun());
+
+        // Create object for updating run info in the database.
+        final RunSummaryDao runSummaryDao = factory.createRunSummaryDao();
+
+        // Insert run summary into database.
+        runSummaryDao.insertFullRunSummary(runSummary);
+
+        LOGGER.info("done updating run database");
     }
 
     /**
@@ -167,152 +305,47 @@
     }
 
     /**
+     * Return <code>true</code> if the run exists in the database.
+     *
+     * @return <code>true</code> if the run exists in the database
+     */
+    public boolean runExists() {
+        this.checkRunNumber();
+        if (this.dataCache.runExists == null) {
+            this.dataCache.runExists = factory.createRunSummaryDao().runSummaryExists(this.run);
+        }
+        return this.dataCache.runExists;
+    }
+
+    /**
+     * Return <code>true</code> if the run exists in the database.
+     *
+     * @param run the run number
+     * @return <code>true</code> if the run exists in the database
+     */
+    boolean runExists(final int run) {
+        if (this.dataCache.runExists == null) {
+            this.dataCache.runExists = factory.createRunSummaryDao().runSummaryExists(run);
+        }
+        return this.dataCache.runExists;
+    }
+
+    /**
      * Set the run number and then load the applicable {@link RunSummary} from the database.
      *
      * @param run the run number
      */
     public void setRun(final int run) {
-        
+
         if (this.run == null || run != this.run) {
-        
+
             LOGGER.info("setting new run " + run);
-            
+
             // Set the run number.
             this.run = run;
-        
+
             // Reset the data cache.
             this.dataCache = new DataCache();
-        } 
-    }
-    
-    /**
-     * Get the run summary for the current run not including its sub-objects like scaler data.
-     * 
-     * @return the run summary for the current run
-     */
-    public RunSummary getRunSummary() {
-        checkRunNumber();
-        if (this.dataCache.runSummary == null) {
-            this.dataCache.runSummary = factory.createRunSummaryDao().getRunSummary(this.run);
-        }
-        return this.dataCache.runSummary;
-    }
-    
-    /**
-     * Get the full run summary for the current run including scaler data, etc.
-     * 
-     * @return the full run summary for the current run
-     */
-    public RunSummary getFullRunSummary() {
-        checkRunNumber();
-        if (this.dataCache.fullRunSummary == null) {
-            this.dataCache.fullRunSummary = factory.createRunSummaryDao().readFullRunSummary(this.run);
-        }
-        return this.dataCache.fullRunSummary;
-    }
-    
-    /**
-     * Get the trigger config for the current run.
-     * 
-     * @return the trigger config for the current run
-     */
-    public TriggerConfig getTriggerConfig() {
-        checkRunNumber();
-        if (this.dataCache.triggerConfig == null) {
-            LOGGER.info("loading trigger config for run " + this.run);
-            this.dataCache.triggerConfig = factory.createTriggerConfigDao().getTriggerConfig(run);
-        }
-        return this.dataCache.triggerConfig;
-    }
-    
-    /**
-     * Get the EPICS data for the current run.
-     * 
-     * @param epicsType the type of EPICS data
-     * @return the EPICS data for the current run
-     */
-    public List<EpicsData> getEpicsData(EpicsType epicsType) {
-        checkRunNumber();
-        if (this.dataCache.epicsData == null) {
-            LOGGER.info("loading EPICS data for run " + this.run);
-            this.dataCache.epicsData = factory.createEpicsDataDao().getEpicsData(epicsType, this.run);
-        }
-        return this.dataCache.epicsData;
-    }
-    
-    /**
-     * Get the scaler data for the current run.
-     * 
-     * @return the scaler data for the current run
-     */
-    public List<ScalerData> getScalerData() {
-        checkRunNumber();
-        if (this.dataCache.scalerData == null) {
-            LOGGER.info("loading scaler data for run " + this.run);
-            this.dataCache.scalerData = factory.createScalerDataDao().getScalerData(run);
-        }
-        return this.dataCache.scalerData;
-    }
-    
-    /**
-     * Update the database with information found from crawling the files.
-     *
-     * @param runs the list of runs to update
-     * @throws SQLException if there is a database query error
-     */
-    public void insertRun(final RunSummary runSummary) throws SQLException {
-        LOGGER.info("updating run database for run " + runSummary.getRun());
-
-        // Create object for updating run info in the database.
-        final RunSummaryDao runSummaryDao = factory.createRunSummaryDao();
-
-        // Insert run summary into database.
-        runSummaryDao.insertFullRunSummary(runSummary);
-
-        LOGGER.info("done updating run database");
-    }
-    
-    /**
-     * Delete a run from the database.
-     * 
-     * @param run the run number
-     */
-    public void deleteRun() {
-        // Create object for updating run info in the database.
-        final RunSummaryDao runSummaryDao = factory.createRunSummaryDao();
-
-        // Delete run from the database.
-        runSummaryDao.deleteFullRun(run);
-    }
-    
-    /**
-     * Return <code>true</code> if the run exists in the database.
-     * 
-     * @return <code>true</code> if the run exists in the database
-     */
-    public boolean runExists() {
-        checkRunNumber();
-        if (this.dataCache.runExists == null) {
-            this.dataCache.runExists = factory.createRunSummaryDao().runSummaryExists(run);
-        }
-        return this.dataCache.runExists;
-    }
-        
-    /**
-     * Check if the run number has been set.
-     */
-    private void checkRunNumber() {
-        if (this.run == null) {
-            throw new IllegalStateException("The run number was not set.");
-        }
-    }    
-    
-    /**
-     * Return the database connection.
-     * 
-     * @return the database connection
-     */
-    Connection getConnection() {
-        return this.connection;
+        }
     }
 }