Author: [log in to unmask]
Date: Wed Apr 22 17:55:28 2015
New Revision: 2792
Log:
More miscellaneous changes to conditions dev branch.
Modified:
java/branches/conditions-HPSJAVA-488/pom.xml
java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/api/BaseConditionsObject.java
java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/api/BaseConditionsObjectCollection.java
java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/api/ConditionsObject.java
java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/api/ConditionsObjectCollection.java
java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/api/DatabaseObject.java
java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/api/DatabaseObjectException.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/ConditionsRecordConverter.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/ecal/EcalChannel.java
java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/svt/AbstractSvtChannel.java
java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/svt/CalibrationHandler.java
java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/svt/DaqMapHandler.java
java/branches/conditions-HPSJAVA-488/src/test/java/org/hps/conditions/dummy/DummyConditionsObjectConverterTest.java
Modified: java/branches/conditions-HPSJAVA-488/pom.xml
=============================================================================
--- java/branches/conditions-HPSJAVA-488/pom.xml (original)
+++ java/branches/conditions-HPSJAVA-488/pom.xml Wed Apr 22 17:55:28 2015
@@ -8,7 +8,7 @@
<groupId>org.hps</groupId>
<artifactId>hps-parent</artifactId>
<relativePath>../parent/pom.xml</relativePath>
- <version>3.3.0-SNAPSHOT</version>
+ <version>3.3.1-SNAPSHOT</version>
</parent>
<scm>
<url>http://java.freehep.org/svn/repos/hps/list/java/trunk/conditions/</url>
Modified: java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/api/BaseConditionsObject.java
=============================================================================
--- java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/api/BaseConditionsObject.java (original)
+++ java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/api/BaseConditionsObject.java Wed Apr 22 17:55:28 2015
@@ -27,8 +27,14 @@
*/
static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss");
+ /**
+ * Value that indicates collection ID is not set (no collection assigned).
+ */
static final int UNSET_COLLECTION_ID = -1;
+ /**
+ * Value that indicates row ID is not assigned (new record).
+ */
static final int UNSET_ROW_ID = -1;
protected static String defaultToString(final BaseConditionsObject object) {
@@ -55,7 +61,7 @@
/**
* The row ID of the object in its table. This will be -1 for new objects that are not in the database.
*/
- private int id = UNSET_ROW_ID;
+ private int rowId = UNSET_ROW_ID;
/**
* Flag to indicate object is locally changed and database update has not been executed.
@@ -67,6 +73,9 @@
*/
private TableMetaData tableMetaData;
+ /**
+ *
+ */
protected BaseConditionsObject() {
this.fieldValues = new FieldValuesMap();
}
@@ -89,7 +98,7 @@
/**
* Class constructor.
* <p>
- * This should be used when creating new objects with a list of field values.
+ * This should be used when creating new objects from a list of field values.
*
* @param connection
* @param tableMetaData
@@ -99,31 +108,14 @@
this.connection = connection;
this.tableMetaData = tableMetaData;
this.fieldValues = fields;
- }
-
- /**
- * Class constructor.
- * <p>
- * This should be used when the object is already in the database and the row ID is known. A SQL SELECT operation
- * will be performed to get data into this object from the database.
- *
- * @param connection
- * @param rowId
- * @param tableMetaData
- * @throw ConditionsObjectException if getting data into this object fails
- * @throw SQLException if there is an SQL error when executing the SELECT operation
- */
- public BaseConditionsObject(final Connection connection, final TableMetaData tableMetaData, final int rowId)
- throws DatabaseObjectException, SQLException {
- this.connection = connection;
- this.tableMetaData = tableMetaData;
- this.fieldValues = new FieldValuesMap(tableMetaData);
- select(rowId);
- // if (!selected) {
- // throw new ConditionsObjectException("Failed to select data into object using row ID " + rowId);
- // }
- }
-
+
+ // Since a list of field values are being provided, this object is flagged as needing to be updated.
+ this.isDirty = true;
+ }
+
+ /**
+ *
+ */
@Override
public final void delete() throws DatabaseObjectException, SQLException {
if (isNew()) {
@@ -134,7 +126,7 @@
try {
statement = this.connection.createStatement();
statement.executeUpdate(sql);
- this.setRowId(UNSET_ROW_ID);
+ this.rowId = UNSET_ROW_ID;
} finally {
if (statement != null) {
statement.close();
@@ -142,6 +134,9 @@
}
}
+ /**
+ *
+ */
@Override
@Field(names = {"collection_id"})
public final Integer getCollectionId() {
@@ -152,26 +147,41 @@
}
}
+ /**
+ *
+ */
@Override
public FieldValues getFieldValues() {
return this.fieldValues;
}
+ /**
+ *
+ */
@Override
public final int getRowId() {
- return this.id;
- }
-
+ return this.rowId;
+ }
+
+ /**
+ *
+ */
@Override
public final TableMetaData getTableMetaData() {
return this.tableMetaData;
}
+ /**
+ *
+ */
@Override
public final <T> T getFieldValue(final Class<T> type, final String name) {
return type.cast(this.fieldValues.getValue(type, name));
}
+ /**
+ *
+ */
@Override
public final void insert() throws DatabaseObjectException, SQLException {
if (!this.isNew()) {
@@ -205,7 +215,7 @@
resultSet = statement.getGeneratedKeys();
while (resultSet.next()) {
final int key = resultSet.getInt(1);
- this.id = key;
+ this.rowId = key;
break;
}
} finally {
@@ -219,19 +229,28 @@
this.isDirty = false;
}
+ /**
+ *
+ */
@Override
public final boolean isDirty() {
return this.isDirty;
}
+ /**
+ *
+ */
@Override
public final boolean isNew() {
return getRowId() == UNSET_ROW_ID;
}
+ /**
+ *
+ */
@Override
public final boolean select(final int id) throws DatabaseObjectException, SQLException {
- this.id = id;
+ this.rowId = id;
if (id < 1) {
throw new IllegalArgumentException("bad row ID value: " + id);
}
@@ -268,6 +287,9 @@
return selected;
}
+ /**
+ *
+ */
@Override
public void setCollectionId(final int collectionId) throws ConditionsObjectException {
if (this.getCollectionId() != UNSET_COLLECTION_ID) {
@@ -279,37 +301,51 @@
this.setFieldValue(COLLECTION_ID_FIELD, collectionId);
}
+ /**
+ *
+ */
@Override
public final void setConnection(final Connection connection) {
this.connection = connection;
}
+ /**
+ *
+ */
@Override
public void setFieldValues(final FieldValues fieldValues) {
this.fieldValues = fieldValues;
- }
-
- @Override
- public void setRowId(final int id) {
- this.id = id;
- }
-
+ this.isDirty = true;
+ }
+
+ /**
+ *
+ */
@Override
public final void setTableMetaData(final TableMetaData tableMetaData) {
this.tableMetaData = tableMetaData;
}
+ /**
+ *
+ */
@Override
public final void setFieldValue(final String name, final Object value) {
this.fieldValues.setValue(name, value);
this.isDirty = true;
}
+ /**
+ *
+ */
@Override
public String toString() {
return defaultToString(this);
}
+ /**
+ *
+ */
@Override
public final boolean update() throws DatabaseObjectException, SQLException {
int rowsUpdated = 0;
@@ -348,13 +384,23 @@
return rowsUpdated != 0;
}
+ /**
+ *
+ */
@Override
public <T> T getFieldValue(final String name) {
return (T) this.fieldValues.getValue(name);
}
+ /**
+ *
+ */
@Override
public boolean hasValidCollection() {
return getCollectionId() != UNSET_COLLECTION_ID;
}
+
+ void setRowId(final int rowId) {
+ this.rowId = rowId;
+ }
}
Modified: java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/api/BaseConditionsObjectCollection.java
=============================================================================
--- java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/api/BaseConditionsObjectCollection.java (original)
+++ java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/api/BaseConditionsObjectCollection.java Wed Apr 22 17:55:28 2015
@@ -39,18 +39,23 @@
}
@Override
- public boolean add(final ObjectType object) {
+ public boolean add(final ObjectType object) throws ConditionsObjectException {
if (object == null) {
throw new IllegalArgumentException("The object argument is null.");
}
+ // Does this collection have a valid ID yet?
if (getCollectionId() != BaseConditionsObject.UNSET_COLLECTION_ID) {
- if (object.getCollectionId() != BaseConditionsObject.UNSET_ROW_ID) {
+ // Does the object that is being added have a collection ID?
+ if (object.getCollectionId() != BaseConditionsObject.UNSET_COLLECTION_ID) {
+ // Does the object's collection ID not match?
if (object.getCollectionId() != this.collectionId) {
+ // Cannot add an object from a different collection.
throw new IllegalArgumentException("Cannot add object with different collection ID: "
+ object.getCollectionId());
}
} else {
try {
+ // Set the collection ID on the object.
object.setCollectionId(this.collectionId);
} catch (final ConditionsObjectException e) {
throw new RuntimeException("Error assigning collection ID " + this.collectionId + " to object.", e);
@@ -77,7 +82,6 @@
+ getCollectionId() + "'";
statement = this.connection.createStatement();
statement.executeUpdate(sql);
- this.connection.commit();
} catch (final SQLException e) {
e.printStackTrace();
} finally {
@@ -134,6 +138,14 @@
+ " table.", this);
}
}
+
+ // Set collection ID on objects.
+ try {
+ setConditionsObjectCollectionIds();
+ } catch (final ConditionsObjectException e) {
+ throw new DatabaseObjectException("Error setting collection IDs on objects.", e, this);
+ }
+
PreparedStatement insertObjects = null;
final StringBuffer sb = new StringBuffer();
sb.append("INSERT INTO " + this.getTableMetaData().getTableName() + " (");
@@ -151,11 +163,6 @@
try {
insertObjects = this.connection.prepareStatement(updateStatement, Statement.RETURN_GENERATED_KEYS);
for (final ObjectType object : this) {
- try {
- object.setCollectionId(this.collectionId);
- } catch (final ConditionsObjectException e) {
- throw new DatabaseObjectException("Error setting collection ID on object.", object);
- }
for (int fieldIndex = 0; fieldIndex < this.getTableMetaData().getFieldNames().length; fieldIndex++) {
final String fieldName = this.getTableMetaData().getFieldNames()[fieldIndex];
insertObjects.setObject(fieldIndex + 1,
@@ -164,13 +171,12 @@
insertObjects.executeUpdate();
final ResultSet resultSet = insertObjects.getGeneratedKeys();
resultSet.next();
- object.setRowId(resultSet.getInt(1));
-
- // This will commit the insert statements for the collections info table and the records.
- this.connection.commit();
-
+ ((BaseConditionsObject) object).setRowId(resultSet.getInt(1));
resultSet.close();
}
+ // This will commit the insert statements for the collections info table and the records.
+ this.connection.commit();
+
} catch (final SQLException e1) {
e1.printStackTrace();
if (this.connection != null) {
@@ -249,12 +255,16 @@
newObject.setConnection(this.connection);
newObject.setTableMetaData(this.tableMetaData);
final int id = resultSet.getInt(1);
- newObject.setRowId(id);
+ ((BaseConditionsObject) newObject).setRowId(id);
for (int fieldIndex = 0; fieldIndex < this.tableMetaData.getFieldNames().length; fieldIndex++) {
final String fieldName = this.tableMetaData.getFieldNames()[fieldIndex];
newObject.setFieldValue(fieldName, resultSet.getObject(fieldIndex + 2));
}
- add(newObject);
+ try {
+ add(newObject);
+ } catch (final ConditionsObjectException e) {
+ throw new DatabaseObjectException("Error adding object to collection.", e, newObject);
+ }
selected = true;
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
@@ -280,8 +290,15 @@
}
private final void setConditionsObjectCollectionIds() throws ConditionsObjectException {
- for (final ConditionsObject object : this) {
- object.setCollectionId(this.collectionId);
+ if (this.collectionId != BaseConditionsObject.UNSET_COLLECTION_ID) {
+ for (final ConditionsObject object : this) {
+ if (object.getCollectionId() != this.getCollectionId()) {
+ throw new ConditionsObjectException("The collection ID on the object does not match.");
+ }
+ if (!object.hasValidCollection()) {
+ object.setCollectionId(this.collectionId);
+ }
+ }
}
}
@@ -347,7 +364,11 @@
throw new RuntimeException("Error creating new collection instance.", e);
}
for (final ObjectType object : list) {
- collection.add(object);
+ try {
+ collection.add(object);
+ } catch (final ConditionsObjectException e) {
+ throw new RuntimeException("Error adding to new collection in sorted method.", e);
+ }
}
return collection;
}
Modified: java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/api/ConditionsObject.java
=============================================================================
--- java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/api/ConditionsObject.java (original)
+++ java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/api/ConditionsObject.java Wed Apr 22 17:55:28 2015
@@ -33,9 +33,6 @@
void setFieldValues(FieldValues fieldValues);
- // FIXME: Maybe this should not be in the interface.
- void setRowId(int id);
-
/**
* @param name
* @param value
Modified: java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/api/ConditionsObjectCollection.java
=============================================================================
--- java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/api/ConditionsObjectCollection.java (original)
+++ java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/api/ConditionsObjectCollection.java Wed Apr 22 17:55:28 2015
@@ -5,7 +5,7 @@
public interface ConditionsObjectCollection<ObjectType extends ConditionsObject> extends Iterable<ObjectType>,
DatabaseObject {
- boolean add(final ObjectType object);
+ boolean add(final ObjectType object) throws ConditionsObjectException;
ObjectType get(final int index);
Modified: java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/api/DatabaseObject.java
=============================================================================
--- java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/api/DatabaseObject.java (original)
+++ java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/api/DatabaseObject.java Wed Apr 22 17:55:28 2015
@@ -3,6 +3,9 @@
import java.sql.Connection;
import java.sql.SQLException;
+/**
+ * @author <a href="mailto:[log in to unmask]">Jeremy McCormick</a>
+ */
public interface DatabaseObject {
/**
@@ -12,6 +15,9 @@
*/
TableMetaData getTableMetaData();
+ /**
+ * @param tableMetaData
+ */
void setTableMetaData(TableMetaData tableMetaData);
/**
@@ -58,5 +64,11 @@
*/
void delete() throws DatabaseObjectException, SQLException;
+ /**
+ * @param id
+ * @return
+ * @throws DatabaseObjectException
+ * @throws SQLException
+ */
boolean select(final int id) throws DatabaseObjectException, SQLException;
}
Modified: java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/api/DatabaseObjectException.java
=============================================================================
--- java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/api/DatabaseObjectException.java (original)
+++ java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/api/DatabaseObjectException.java Wed Apr 22 17:55:28 2015
@@ -1,14 +1,37 @@
package org.hps.conditions.api;
+/**
+ * @author <a href="mailto:[log in to unmask]">Jeremy McCormick</a>
+ */
public final class DatabaseObjectException extends Exception {
+ /**
+ *
+ */
private final DatabaseObject object;
+ /**
+ * @param message
+ * @param object
+ */
public DatabaseObjectException(final String message, final DatabaseObject object) {
super(message);
this.object = object;
}
+ /**
+ * @param message
+ * @param cause
+ * @param object
+ */
+ public DatabaseObjectException(final String message, final Throwable cause, final DatabaseObject object) {
+ super(message, cause);
+ this.object = object;
+ }
+
+ /**
+ * @return
+ */
public DatabaseObject getDatabaseObject() {
return this.object;
}
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 Wed Apr 22 17:55:28 2015
@@ -10,6 +10,7 @@
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
+import org.hps.conditions.api.ConditionsObjectException;
import org.hps.conditions.api.ConditionsRecord;
import org.hps.conditions.api.ConditionsRecord.ConditionsRecordCollection;
import org.hps.conditions.api.DatabaseObjectException;
@@ -131,7 +132,11 @@
newRecord.setFieldValue("tag", newTag);
// Add the record to the tag.
- tagRecords.add(newRecord);
+ try {
+ tagRecords.add(newRecord);
+ } catch (final ConditionsObjectException e) {
+ throw new RuntimeException(e);
+ }
// Flag the record's ID as used so it is only added once.
addedIds.add(record.getRowId());
Modified: java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/database/ConditionsRecordConverter.java
=============================================================================
--- java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/database/ConditionsRecordConverter.java (original)
+++ java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/database/ConditionsRecordConverter.java Wed Apr 22 17:55:28 2015
@@ -6,6 +6,7 @@
import org.hps.conditions.api.AbstractConditionsObjectConverter;
import org.hps.conditions.api.BaseConditionsObjectCollection;
import org.hps.conditions.api.ConditionsObject;
+import org.hps.conditions.api.ConditionsObjectException;
import org.hps.conditions.api.ConditionsRecord;
import org.hps.conditions.api.ConditionsRecord.ConditionsRecordCollection;
import org.hps.conditions.api.DatabaseObjectException;
@@ -64,9 +65,11 @@
conditionsRecord.setConnection(databaseConditionsManager.getConnection());
conditionsRecord.setTableMetaData(tableMetaData);
conditionsRecord.select(resultSet.getInt(1));
- // AbstractConditionsObjectConverter.createConditionsObject(
- // resultSet, tableMetaData);
- collection.add(conditionsRecord);
+ try {
+ collection.add(conditionsRecord);
+ } catch (final ConditionsObjectException e) {
+ throw new RuntimeException(e);
+ }
}
} catch (final DatabaseObjectException | SQLException e) {
throw new RuntimeException("Error creating new conditions record.", e);
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 Wed Apr 22 17:55:28 2015
@@ -389,7 +389,11 @@
for (final ConditionsRecord record : runConditionsRecords) {
if (record.getName().equals(name)) {
if (matchesTag(record)) {
- foundConditionsRecords.add(record);
+ try {
+ foundConditionsRecords.add(record);
+ } catch (final ConditionsObjectException e) {
+ throw new RuntimeException(e);
+ }
logger.finer("found matching conditions record " + record.getRowId());
} else {
logger.finer("conditions record " + record.getRowId() + " rejected from non-matching tag "
Modified: java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/ecal/EcalChannel.java
=============================================================================
--- java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/ecal/EcalChannel.java (original)
+++ java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/ecal/EcalChannel.java Wed Apr 22 17:55:28 2015
@@ -9,6 +9,7 @@
import org.hps.conditions.api.BaseConditionsObject;
import org.hps.conditions.api.BaseConditionsObjectCollection;
import org.hps.conditions.api.ConditionsObjectCollection;
+import org.hps.conditions.api.ConditionsObjectException;
import org.hps.conditions.database.Converter;
import org.hps.conditions.database.DatabaseConditionsManager;
import org.hps.conditions.database.Field;
@@ -178,7 +179,7 @@
* @return <code>true</code> if object was added successfully
*/
@Override
- public boolean add(final EcalChannel channel) {
+ public boolean add(final EcalChannel channel) throws ConditionsObjectException {
super.add(channel);
final DaqId daqId = channel.createDaqId();
if (daqId.isValid()) {
Modified: java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/svt/AbstractSvtChannel.java
=============================================================================
--- java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/svt/AbstractSvtChannel.java (original)
+++ java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/svt/AbstractSvtChannel.java Wed Apr 22 17:55:28 2015
@@ -6,6 +6,7 @@
import org.hps.conditions.api.BaseConditionsObject;
import org.hps.conditions.api.BaseConditionsObjectCollection;
+import org.hps.conditions.api.ConditionsObjectException;
import org.hps.conditions.database.Field;
import org.hps.util.Pair;
@@ -42,7 +43,7 @@
* @param channel channel of a type extending {@link AbstractSvtChannel}
*/
@Override
- public final boolean add(final T channel) {
+ public final boolean add(final T channel) throws ConditionsObjectException {
// If it doesn't exist, add the channel to the channel map
if (this.channelMap.containsKey(channel.getChannelID())) {
Modified: java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/svt/CalibrationHandler.java
=============================================================================
--- java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/svt/CalibrationHandler.java (original)
+++ java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/svt/CalibrationHandler.java Wed Apr 22 17:55:28 2015
@@ -3,6 +3,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.hps.conditions.api.ConditionsObjectException;
import org.hps.conditions.database.DatabaseConditionsManager;
import org.hps.conditions.svt.SvtCalibration.SvtCalibrationCollection;
import org.hps.conditions.svt.SvtChannel.SvtChannelCollection;
@@ -13,27 +14,27 @@
import org.xml.sax.helpers.DefaultHandler;
/**
- * Handler for calibration events.
+ * Handler for calibration events.
*
- * @author <a href="mailto:[log in to unmask]">Omar Moreno</a>
+ * @author <a href="mailto:[log in to unmask]">Omar Moreno</a>
*/
class CalibrationHandler extends DefaultHandler {
/**
* Initialize the logger.
*/
- private static Logger logger = LogUtil.create(SvtConditionsLoader.class.getSimpleName(),
- new DefaultLogFormatter(), Level.INFO);
+ private static Logger logger = LogUtil.create(SvtConditionsLoader.class.getSimpleName(), new DefaultLogFormatter(),
+ Level.INFO);
/**
* List of SVT channels.
*/
- private SvtChannelCollection svtChannels;
+ private final SvtChannelCollection svtChannels;
/**
* List of SVT calibrations.
*/
- private SvtCalibrationCollection calibrations = new SvtCalibrationCollection();
+ private final SvtCalibrationCollection calibrations = new SvtCalibrationCollection();
/**
* An SVT calibration object encapsulating the baseline and noise values for a channel.
@@ -72,9 +73,8 @@
private int noiseSampleID = 0;
/**
- * Flag denoting whether the calibrations of a given channel should be
- * loaded into the conditions DB. If a channel is found to be missing
- * baseline or noise values, is will be marked invalid.
+ * Flag denoting whether the calibrations of a given channel should be loaded into the conditions DB. If a channel
+ * is found to be missing baseline or noise values, is will be marked invalid.
*/
private boolean isValidChannel = false;
@@ -82,18 +82,18 @@
* Default constructor.
*/
public CalibrationHandler() {
- svtChannels = (SvtChannelCollection) DatabaseConditionsManager.getInstance()
- .getCachedConditions(SvtChannelCollection.class, "svt_channels").getCachedData();
+ this.svtChannels = DatabaseConditionsManager.getInstance()
+ .getCachedConditions(SvtChannelCollection.class, "svt_channels").getCachedData();
}
/**
- * Method that is triggered when the start tag is encountered.
+ * Method that is triggered when the start tag is encountered.
*
- * @param uri the Namespace URI
- * @param locaName the local name (without prefix)
- * @param qName the qualified name (with prefix)
- * @param attributes the attributes attached to the element
- * @throws SAXException if there is an error processing the element
+ * @param uri the Namespace URI
+ * @param locaName the local name (without prefix)
+ * @param qName the qualified name (with prefix)
+ * @param attributes the attributes attached to the element
+ * @throws SAXException if there is an error processing the element
*/
@Override
public void startElement(final String uri, final String localName, final String qName, final Attributes attributes)
@@ -101,22 +101,23 @@
switch (qName) {
case "Feb":
- febID = Integer.parseInt(attributes.getValue("id"));
+ this.febID = Integer.parseInt(attributes.getValue("id"));
break;
case "Hybrid":
- hybridID = Integer.parseInt(attributes.getValue("id"));
- logger.info("Processing calibrations for FEB " + febID + " Hybrid " + hybridID);
+ this.hybridID = Integer.parseInt(attributes.getValue("id"));
+ logger.info("Processing calibrations for FEB " + this.febID + " Hybrid " + this.hybridID);
break;
case "channel":
- channel = Integer.parseInt(attributes.getValue("id"));
- calibration = new SvtCalibration(svtChannels.findChannelID(febID, hybridID, channel));
- isValidChannel = false;
+ this.channel = Integer.parseInt(attributes.getValue("id"));
+ this.calibration = new SvtCalibration(this.svtChannels.findChannelID(this.febID, this.hybridID,
+ this.channel));
+ this.isValidChannel = false;
break;
case "baseline":
- baselineSampleID = Integer.parseInt(attributes.getValue("id"));
+ this.baselineSampleID = Integer.parseInt(attributes.getValue("id"));
break;
case "noise":
- noiseSampleID = Integer.parseInt(attributes.getValue("id"));
+ this.noiseSampleID = Integer.parseInt(attributes.getValue("id"));
break;
default:
break;
@@ -132,41 +133,43 @@
* @throws SAXException if there is an error processing the element
*/
@Override
- public void endElement(final String uri, final String localName, final String qName)
- throws SAXException {
+ public void endElement(final String uri, final String localName, final String qName) throws SAXException {
switch (qName) {
case "channel":
- if (isValidChannel) {
- calibrations.add(calibration);
+ if (this.isValidChannel) {
+ try {
+ this.calibrations.add(this.calibration);
+ } catch (final ConditionsObjectException e) {
+ throw new RuntimeException(e);
+ }
}
break;
case "baseline":
- calibration.setPedestal(baselineSampleID, Double.parseDouble(content));
- isValidChannel = true;
+ this.calibration.setPedestal(this.baselineSampleID, Double.parseDouble(this.content));
+ this.isValidChannel = true;
break;
case "noise":
- calibration.setNoise(baselineSampleID, Double.parseDouble(content));
- isValidChannel = true;
+ this.calibration.setNoise(this.baselineSampleID, Double.parseDouble(this.content));
+ this.isValidChannel = true;
break;
default:
break;
}
}
- /**
- * Method called to extract character data inside of an element.
- *
- * @param ch the characters
- * @param start the start position in the character array
- * @param length the number of characters to use from the character array
- * @throws SAXException if there is an error processing the element (possibly wraps another exception type)
- */
- @Override
- public void characters(final char[] ch, final int start, final int length)
- throws SAXException {
- content = String.copyValueOf(ch, start, length).trim();
- }
+ /**
+ * Method called to extract character data inside of an element.
+ *
+ * @param ch the characters
+ * @param start the start position in the character array
+ * @param length the number of characters to use from the character array
+ * @throws SAXException if there is an error processing the element (possibly wraps another exception type)
+ */
+ @Override
+ public void characters(final char[] ch, final int start, final int length) throws SAXException {
+ this.content = String.copyValueOf(ch, start, length).trim();
+ }
/**
* Get the {@link SvtCalibrationCollection} created from parsing the XML input file.
@@ -174,6 +177,6 @@
* @return the {@link SvtCalibrationCollection} created from parsing the XML
*/
public SvtCalibrationCollection getCalibrations() {
- return calibrations;
+ return this.calibrations;
}
}
Modified: java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/svt/DaqMapHandler.java
=============================================================================
--- java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/svt/DaqMapHandler.java (original)
+++ java/branches/conditions-HPSJAVA-488/src/main/java/org/hps/conditions/svt/DaqMapHandler.java Wed Apr 22 17:55:28 2015
@@ -1,5 +1,6 @@
package org.hps.conditions.svt;
+import org.hps.conditions.api.ConditionsObjectException;
import org.hps.conditions.svt.SvtChannel.SvtChannelCollection;
import org.hps.conditions.svt.SvtDaqMapping.SvtDaqMappingCollection;
import org.xml.sax.Attributes;
@@ -69,7 +70,11 @@
*/
public void addSvtChannels(final int febID, final int febHybridID) {
for (int channel = 0; channel < CHANNELS_MAX; channel++) {
- this.svtChannels.add(new SvtChannel(this.currentSvtChannelID, this.febID, this.hybridID, channel));
+ try {
+ this.svtChannels.add(new SvtChannel(this.currentSvtChannelID, this.febID, this.hybridID, channel));
+ } catch (final ConditionsObjectException e) {
+ throw new RuntimeException(e);
+ }
this.currentSvtChannelID++;
}
}
@@ -99,24 +104,28 @@
public void endElement(final String uri, final String localName, final String qName) throws SAXException {
switch (qName) {
- case "Hybrid":
- this.daqMap.add(this.daqMapping);
- this.addSvtChannels(this.febID, this.hybridID);
- break;
- case "Half":
- this.daqMapping.setSvtHalf(this.content);
- break;
- case "Layer":
- this.daqMapping.setLayerNumber(Integer.parseInt(this.content));
- break;
- case "Side":
- this.daqMapping.setSide(this.content);
- break;
- case "Orientation":
- this.daqMapping.setOrientation(this.content);
- break;
- default:
- break;
+ case "Hybrid":
+ try {
+ this.daqMap.add(this.daqMapping);
+ } catch (final ConditionsObjectException e) {
+ throw new RuntimeException(e);
+ }
+ this.addSvtChannels(this.febID, this.hybridID);
+ break;
+ case "Half":
+ this.daqMapping.setSvtHalf(this.content);
+ break;
+ case "Layer":
+ this.daqMapping.setLayerNumber(Integer.parseInt(this.content));
+ break;
+ case "Side":
+ this.daqMapping.setSide(this.content);
+ break;
+ case "Orientation":
+ this.daqMapping.setOrientation(this.content);
+ break;
+ default:
+ break;
}
}
@@ -152,15 +161,15 @@
throws SAXException {
switch (qName) {
- case "Feb":
- this.febID = Integer.parseInt(attributes.getValue("id"));
- break;
- case "Hybrid":
- this.hybridID = Integer.parseInt(attributes.getValue("id"));
- this.daqMapping = new SvtDaqMapping(this.febID, this.hybridID);
- break;
- default:
- break;
+ case "Feb":
+ this.febID = Integer.parseInt(attributes.getValue("id"));
+ break;
+ case "Hybrid":
+ this.hybridID = Integer.parseInt(attributes.getValue("id"));
+ this.daqMapping = new SvtDaqMapping(this.febID, this.hybridID);
+ break;
+ default:
+ break;
}
}
Modified: java/branches/conditions-HPSJAVA-488/src/test/java/org/hps/conditions/dummy/DummyConditionsObjectConverterTest.java
=============================================================================
--- java/branches/conditions-HPSJAVA-488/src/test/java/org/hps/conditions/dummy/DummyConditionsObjectConverterTest.java (original)
+++ java/branches/conditions-HPSJAVA-488/src/test/java/org/hps/conditions/dummy/DummyConditionsObjectConverterTest.java Wed Apr 22 17:55:28 2015
@@ -24,12 +24,12 @@
final TableMetaData tableMetaData = TableRegistry.getTableRegistry().findByTableName("dummy");
final DummyConditionsObjectCollection newCollection = new DummyConditionsObjectCollection();
+ newCollection.setCollectionId(42);
newCollection.setTableMetaData(tableMetaData);
newCollection.setConnection(manager.getConnection());
final DummyConditionsObject object = new DummyConditionsObject(manager.getConnection(), tableMetaData);
object.setFieldValue("dummy", 1.2345);
- newCollection.setCollectionId(1001);
newCollection.add(object);
try {
|