Commit in hps-java/src/main/java/org/lcsim/hps/conditions on MAIN | |||
DatabaseConditionsConverter.java | +4 | -1 | 1.1 -> 1.2 |
DatabaseConditionsReader.java | +13 | -38 | 1.3 -> 1.4 |
svt/SvtCalibrationConverter.java | +9 | -6 | 1.2 -> 1.3 |
+26 | -45 |
use ConnectionManager for connection and parameters
diff -u -r1.1 -r1.2 --- DatabaseConditionsConverter.java 18 Sep 2013 02:33:16 -0000 1.1 +++ DatabaseConditionsConverter.java 19 Sep 2013 01:28:05 -0000 1.2 @@ -3,6 +3,8 @@
import org.lcsim.conditions.ConditionsConverter; public abstract class DatabaseConditionsConverter<T> implements ConditionsConverter<T> {
+ + /*
ConnectionParameters connectionParameters = null; protected DatabaseConditionsConverter(ConnectionParameters parameters) {
@@ -11,5 +13,6 @@
public ConnectionParameters getConnectionParameters() { return this.connectionParameters;
- }
+ } + */
}
\ No newline at end of file
diff -u -r1.3 -r1.4 --- DatabaseConditionsReader.java 18 Sep 2013 21:03:23 -0000 1.3 +++ DatabaseConditionsReader.java 19 Sep 2013 01:28:05 -0000 1.4 @@ -2,9 +2,6 @@
import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream;
-import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException;
import java.io.IOException; import java.io.InputStream; import java.sql.Connection;
@@ -36,15 +33,15 @@
* are created. * * @author jeremym
- * @version $Id: DatabaseConditionsReader.java,v 1.3 2013/09/18 21:03:23 jeremy Exp $
+ * @version $Id: DatabaseConditionsReader.java,v 1.4 2013/09/19 01:28:05 jeremy Exp $
*/ public class DatabaseConditionsReader extends ConditionsReader { /** Database connection parameters. */
- ConnectionParameters connectionParameters = new ConnectionParameters();
+ //private static ConnectionParameters connectionParameters = new ConnectionParameters();
/** Database connection. */
- Connection connection = null;
+ private Connection connection = null;
/** Base ConditionsReader for getting the Detector. */ private final ConditionsReader reader;
@@ -70,36 +67,9 @@
*/ public DatabaseConditionsReader(ConditionsReader reader) { this.reader = reader;
- - // Setup possible custom database parameters. - setupConnectionParameters();
} /**
- * Setup custom database connection parameters if there is a configuration file pointed to by - * a system property. - */ - public void setupConnectionParameters() { - Object o = System.getProperties().get("hps.conditions.db.configuration"); - if (o != null) { - String config = o.toString(); - Properties p; - if (config != null) { - p = new Properties(); - try { - p.load(new FileInputStream(new File(config))); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } catch (IOException e) { - throw new RuntimeException(e); - } - this.connectionParameters = ConnectionParameters - .fromProperties(p); - } - } - } - - /**
* Update conditions for possibly new detector and run number. This will cache the * conditions meta data but will not automatically do any conversion. */
@@ -121,14 +91,14 @@
propertyCache.clear(); // Open a connection to the database.
- connection = this.connectionParameters.createConnection();
+ connection = ConnectionManager.createConnection();
// Register the conditions converters. registerConditionsConverters(manager); // Cache the meta data for the fetched conditions records. try {
- cacheMetadata(run);
+ cacheDataIdent(run);
} catch (Exception e) { throw new RuntimeException(e); }
@@ -170,10 +140,15 @@
* @throws SQLException * @throws IOException */
- private final void cacheMetadata(int run) throws SQLException, IOException {
+ private final void cacheDataIdent(int run) throws SQLException, IOException {
+
+ String db = ConnectionManager.getConnectionParameters().getDatabase();
+ String table = ConnectionManager.getConnectionParameters().getConditionsTable();
// Query for fetching the validity records matching this run.
- String query = "SELECT data_ident, run_start, run_end, calib_type FROM rd_hps_cond.conditions_test WHERE "
+ String query = "SELECT data_ident, run_start, run_end, calib_type FROM "
+ + db + "." + table
+ + " WHERE "
+ "run_start <= " + run + " AND run_end >= "
@@ -244,7 +219,7 @@
* @param manager The ConditionsManager. */ private void registerConditionsConverters(ConditionsManager manager) {
- manager.registerConditionsConverter(new SvtCalibrationConverter(connectionParameters));
+ manager.registerConditionsConverter(new SvtCalibrationConverter());
// TODO: Add other converters here as they are made available. } }
diff -u -r1.2 -r1.3 --- SvtCalibrationConverter.java 18 Sep 2013 02:56:39 -0000 1.2 +++ SvtCalibrationConverter.java 19 Sep 2013 01:28:05 -0000 1.3 @@ -7,6 +7,7 @@
import org.lcsim.conditions.ConditionsManager; import org.lcsim.conditions.ConditionsSet;
+import org.lcsim.hps.conditions.ConnectionManager;
import org.lcsim.hps.conditions.ConnectionParameters; import org.lcsim.hps.conditions.DatabaseConditionsConverter;
@@ -14,7 +15,7 @@
* Read from conditions database and create SVT calibration data. * * @author jeremym
- * @version $Id: SvtCalibrationConverter.java,v 1.2 2013/09/18 02:56:39 jeremy Exp $
+ * @version $Id: SvtCalibrationConverter.java,v 1.3 2013/09/19 01:28:05 jeremy Exp $
*/ public class SvtCalibrationConverter extends DatabaseConditionsConverter<SvtCalibrationConstants> {
@@ -22,8 +23,7 @@
* Constructor with argument. * @param connectionParameters The connection information for the condition database. */
- public SvtCalibrationConverter(ConnectionParameters connectionParameters) { - super(connectionParameters);
+ public SvtCalibrationConverter() {
} /**
@@ -31,18 +31,21 @@
* It produces a calibration object based on the appropriate database records. */ public SvtCalibrationConstants getData(ConditionsManager manager, String name) {
+
Connection connection = null;
- Statement statement = null;
+ Statement statement = null;
SvtCalibrationConstants calibration = new SvtCalibrationConstants(); try { // Get the meta data for this conditions set. ConditionsSet cs = manager.getConditions(name); // Connect to the database.
- connection = this.getConnectionParameters().createConnection();
+ connection = ConnectionManager.createConnection(); + + String db = ConnectionManager.getConnectionParameters().getDatabase();
String query = "SELECT fpga, hybrid, channel, noise, pedestal FROM "
- + getConnectionParameters().getDatabase() + "."
+ + db + "."
+ cs.getString("table") + " WHERE " + cs.getString("column") + " = " + cs.getString("id");
Use REPLY-ALL to reply to list
To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1