3 removed + 9 modified, total 12 files
java/trunk/conditions/src/main/java/org/hps/conditions
--- java/trunk/conditions/src/main/java/org/hps/conditions/AbstractConditionsDatabaseObject.java 2014-03-14 18:36:46 UTC (rev 299)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/AbstractConditionsDatabaseObject.java 2014-03-14 19:52:03 UTC (rev 300)
@@ -1,234 +0,0 @@
-package org.hps.conditions;
-
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.util.LinkedHashMap;
-import java.util.Map.Entry;
-
-/**
- * The abstract implementation of {@link ConditionsObject}.
- * @author Jeremy McCormick <[log in to unmask]>
- */
-public abstract class AbstractConditionsDatabaseObject implements ConditionsObject {
-
- private ConnectionManager _connectionManager = null;
- private ConditionsTableMetaData _tableMetaData = null;
- protected int _rowId = -1;
- protected int _collectionId = -1;
- protected boolean _isDirty = false;
- protected boolean _isReadOnly = false;
- protected FieldValueMap _fieldValues = null;
-
- /**
- * Class that maps field names to values.
- */
- public static final class FieldValueMap extends LinkedHashMap<String, Object> {
- }
-
- /**
- * Constructor for sub-classing with no arguments.
- */
- protected AbstractConditionsDatabaseObject() {}
-
- /**
- * Constructor for a new object which cannot initially be read only as it must be inserted.
- * @param tableMetaData
- * @param fieldValues
- * @param setId
- * @param isReadOnly
- */
- public AbstractConditionsDatabaseObject(
- ConnectionManager connectionManager,
- ConditionsTableMetaData tableMetaData,
- int setId,
- FieldValueMap fieldValues) {
-
- if (connectionManager == null) {
- throw new IllegalArgumentException("The connectionManager is null.");
- }
- if (tableMetaData == null) {
- throw new IllegalArgumentException("The tableMetaData is null");
- }
- if (setId <= 0) {
- throw new IllegalArgumentException("The set ID value is invalid: " + setId);
- }
- _connectionManager = connectionManager;
- _tableMetaData = tableMetaData;
- _collectionId = setId;
- _rowId = -1;
- if (fieldValues != null) {
- _fieldValues = fieldValues;
- } else {
- _fieldValues = new FieldValueMap();
- }
- }
-
- /**
- * Constructor for loading data from an existing object with a row ID.
- * @param tableMetaData
- * @param rowId
- * @param isReadOnly
- */
- public AbstractConditionsDatabaseObject(
- ConnectionManager connectionManager,
- ConditionsTableMetaData tableMetaData,
- int rowId,
- boolean isReadOnly) {
- if (connectionManager == null) {
- throw new IllegalArgumentException("The connectionManager cannot be null!");
- }
- if (tableMetaData == null) {
- throw new IllegalArgumentException("The tableMetaData cannot be null");
- }
- if (rowId <= 0) {
- throw new IllegalArgumentException("Invalid row ID: " + rowId);
- }
- _connectionManager = connectionManager;
- _tableMetaData = tableMetaData;
- _rowId = rowId;
- _isReadOnly = isReadOnly;
- _fieldValues = new FieldValueMap();
- }
-
- public ConditionsTableMetaData getTableMetaData() {
- return _tableMetaData;
- }
-
- public int getRowId() {
- return _rowId;
- }
-
- public int getCollectionId() {
- return _collectionId;
- }
-
- public boolean isReadOnly() {
- return _isReadOnly;
- }
-
- public boolean isNew() {
- return _rowId == -1;
- }
-
- public boolean isDirty() {
- return _isDirty;
- }
-
- public void delete() throws ConditionsObjectException {
- if (isReadOnly()) {
- throw new ConditionsObjectException("This object cannot be deleted in read only mode.");
- }
- String query = "DELETE FROM " + _tableMetaData.getTableName() + " WHERE id = " + _rowId;
- _connectionManager.update(query);
- _rowId = -1;
- }
-
- public void insert() throws ConditionsObjectException, SQLException {
- if (!isNew()) {
- throw new ConditionsObjectException("Record already exists in database.");
- }
- if (isReadOnly()) {
- throw new ConditionsObjectException("Cannot insert in read only mode.");
- }
- if (_fieldValues.size() == 0) {
- throw new ConditionsObjectException("There are no field values to insert.");
- }
- StringBuffer buff = new StringBuffer();
- buff.append("INSERT INTO " + _tableMetaData.getTableName() + "( set_id");
- for (Entry<String, Object> entry : _fieldValues.entrySet()) {
- buff.append(", " + entry.getKey());
- }
- buff.append(" ) VALUES ( ");
- buff.append(_collectionId);
- for (Entry<String, Object> entry : _fieldValues.entrySet()) {
- buff.append(", " + entry.getValue());
- }
- buff.append(") ");
- int key = _connectionManager.update(buff.toString());
- _rowId = key;
- }
-
- public void select() throws ConditionsObjectException, SQLException {
- if (isNew()) {
- throw new ConditionsObjectException("Record has not been inserted into database yet.");
- }
- StringBuffer buff = new StringBuffer();
- buff.append("SELECT ");
- for (String fieldName : _tableMetaData.getFieldNames()) {
- buff.append(fieldName + ", ");
- }
- buff.delete(buff.length()-2, buff.length()-1);
- buff.append(" FROM " + _tableMetaData.getTableName());
- buff.append(" WHERE id = " + _rowId);
- ResultSet resultSet = _connectionManager.query(buff.toString());
- ResultSetMetaData metadata = resultSet.getMetaData();
- int ncolumns = metadata.getColumnCount();
- if (resultSet.next()) {
- for (int i=1; i<=ncolumns; i++) {
- _fieldValues.put(metadata.getColumnName(i), resultSet.getObject(i));
- }
- }
- }
-
- public void update() throws ConditionsObjectException {
- if (isReadOnly()) {
- throw new ConditionsObjectException("Cannot update in read only mode.");
- }
- if (isNew()) {
- throw new ConditionsObjectException("Cannot update a new record.");
- }
- if (_fieldValues.size() == 0) {
- throw new ConditionsObjectException("No field values to update.");
- }
- StringBuffer buff = new StringBuffer();
- buff.append("UPDATE " + _tableMetaData.getTableName() + " SET ");
- for (Entry<String, Object> entry : _fieldValues.entrySet()) {
- buff.append(entry.getKey() + " = '" + entry.getValue() + "', ");
- }
- buff.delete(buff.length()-2, buff.length()-1);
- buff.append(" WHERE id = " + _rowId);
- _connectionManager.update(buff.toString());
- setIsDirty(false);
- }
-
- public void setFieldValue(String key, Object value) {
- if (_fieldValues == null)
- _fieldValues = new FieldValueMap();
- _fieldValues.put(key, value);
- setIsDirty(true);
- }
-
- public void setFieldValues(FieldValueMap fieldValues) {
- _fieldValues = fieldValues;
- if (!isNew()) {
- setIsDirty(true);
- }
- }
-
- public <T> T getFieldValue(Class<T> klass, String field) {
- return klass.cast(_fieldValues.get(field));
- }
-
- public void setConnectionManager(ConnectionManager connectionManager) {
- _connectionManager = connectionManager;
- }
-
- public void setTableMetaData(ConditionsTableMetaData tableMetaData) {
- _tableMetaData = tableMetaData;
- }
-
- public void setCollectionId(int collectionId) {
- _collectionId = collectionId;
- if (!isNew())
- setIsDirty(true);
- }
-
- public void setIsDirty(boolean isDirty) {
- _isDirty = isDirty;
- }
-
- protected void setIsReadOnly(boolean isReadOnly) {
- _isReadOnly = isReadOnly;
- }
-}
\ No newline at end of file
java/trunk/conditions/src/main/java/org/hps/conditions
--- java/trunk/conditions/src/main/java/org/hps/conditions/BasicConditionsObjectCollection.java 2014-03-14 18:36:46 UTC (rev 299)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/BasicConditionsObjectCollection.java 2014-03-14 19:52:03 UTC (rev 300)
@@ -1,112 +0,0 @@
-package org.hps.conditions;
-
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.hps.conditions.ConditionsObject.ConditionsObjectException;
-
-public class BasicConditionsObjectCollection implements ConditionsObjectCollection {
-
- List<ConditionsObject> objects = new ArrayList<ConditionsObject>();
- ConditionsTableMetaData _tableMetaData;
- int _collectionId;
- boolean _isReadOnly;
- boolean _isNew;
- boolean _isDirty;
-
- /**
- * Use for existing collection.
- * @param tableMetaData
- * @param collectionId
- * @param isReadOnly
- */
- public BasicConditionsObjectCollection(ConditionsTableMetaData tableMetaData, int collectionId, boolean isReadOnly) {
- _tableMetaData = tableMetaData;
- _collectionId = collectionId;
- _isReadOnly = isReadOnly;
- if (collectionId == -1) {
- _isNew = true;
- }
- }
-
- /**
- * Use for new collection.
- * @param tableMetaData
- */
- public BasicConditionsObjectCollection(ConditionsTableMetaData tableMetaData) {
- _tableMetaData = tableMetaData;
- _collectionId = -1;
- _isReadOnly = true;
- }
-
- public ConditionsObject get(int index) {
- return objects.get(index);
- }
-
- public List<ConditionsObject> getObjects() {
- return Collections.unmodifiableList(objects);
- }
-
- public void add(ConditionsObject object) {
- if (objects.contains(object)) {
- throw new IllegalArgumentException("Collection already contains this object.");
- }
- object.setCollectionId(getCollectionId());
- objects.add(object);
- if (!isNew())
- setIsDirty(true);
- }
-
- public ConditionsTableMetaData getTableMetaData() {
- return _tableMetaData;
- }
-
- public int getCollectionId() {
- return _collectionId;
- }
-
- public void updateAll() throws ConditionsObjectException {
- for (ConditionsObject object : objects) {
- object.update();
- }
- setIsDirty(false);
- }
-
- public void deleteAll() throws ConditionsObjectException {
- for (ConditionsObject object : objects) {
- object.delete();
- }
- }
-
- public void selectAll() throws ConditionsObjectException, SQLException {
- for (ConditionsObject object : objects) {
- object.select();
- }
- }
-
- public void insertAll() throws ConditionsObjectException, SQLException {
- for (ConditionsObject object : objects) {
- if (object.isNew()) {
- object.insert();
- }
- }
- }
-
- public boolean isDirty() {
- return _isDirty;
- }
-
- public boolean isReadOnly() {
- return _isReadOnly;
- }
-
- void setIsDirty(boolean isDirty) {
- _isDirty = isDirty;
- }
-
- public boolean isNew() {
- return _isNew;
- }
-}
java/trunk/conditions/src/main/java/org/hps/conditions
--- java/trunk/conditions/src/main/java/org/hps/conditions/BasicConditionsObjectFactory.java 2014-03-14 18:36:46 UTC (rev 299)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/BasicConditionsObjectFactory.java 2014-03-14 19:52:03 UTC (rev 300)
@@ -1,9 +1,13 @@
package org.hps.conditions;
-import org.hps.conditions.AbstractConditionsDatabaseObject.FieldValueMap;
+import org.hps.conditions.AbstractConditionsObject.FieldValueMap;
import org.hps.conditions.ConditionsObject.ConditionsObjectException;
-
+/**
+ * The basic implementation of the {@link ConditionsObjectFactory} interface.
+ *
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
public class BasicConditionsObjectFactory implements ConditionsObjectFactory {
private ConnectionManager _connectionManager;
@@ -14,14 +18,16 @@
_tableRegistry = tableRegistry;
}
+ /**
+ * This method is the primary one in the API for creating new conditions objects.
+ */
@SuppressWarnings("unchecked")
- // FIXME: Not sure this is the best way to accomplish the desired generic behavior, especially
- // the unchecked cast to the T return type.
- public ConditionsObject createObject(
+ public <T> T createObject(
Class<? extends ConditionsObject> klass,
- String tableName,
- int collectionId, // should be -1 if new object
- FieldValueMap fieldValues) throws ConditionsObjectException {
+ String tableName,
+ int rowId,
+ FieldValueMap fieldValues,
+ boolean isReadOnly) throws ConditionsObjectException {
ConditionsObject newObject = null;
try {
newObject = klass.newInstance();
@@ -30,7 +36,8 @@
} catch (IllegalAccessException x) {
throw new RuntimeException(x);
}
- newObject.setCollectionId(collectionId);
+ if (rowId != -1)
+ newObject.setRowId(rowId);
newObject.setFieldValues(fieldValues);
newObject.setConnectionManager(_connectionManager);
ConditionsTableMetaData tableMetaData = _tableRegistry.getTableMetaData(tableName);
@@ -38,10 +45,16 @@
throw new ConditionsObjectException("No meta data found for table: " + tableName);
}
newObject.setTableMetaData(tableMetaData);
- return newObject;
+ if (isReadOnly)
+ newObject.setIsReadOnly();
+ return (T)newObject;
}
public ConditionsTableRegistry getTableRegistry() {
return _tableRegistry;
}
+
+ public ConditionsTableMetaData getTableMetaData(String name) {
+ return _tableRegistry.getTableMetaData(name);
+ }
}
java/trunk/conditions/src/main/java/org/hps/conditions
--- java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsConverterRegister.java 2014-03-14 18:36:46 UTC (rev 299)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsConverterRegister.java 2014-03-14 19:52:03 UTC (rev 300)
@@ -40,6 +40,7 @@
manager.registerConditionsConverter(new ConditionsRecordConverter());
// SVT gains. (TESTING!!!)
+ // TODO: The factory should be a required argument for the converter classes.
SvtGainConverter svtGainConverter = new SvtGainConverter();
svtGainConverter.setObjectFactory(factory);
manager.registerConditionsConverter(svtGainConverter);
java/trunk/conditions/src/main/java/org/hps/conditions
--- java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsObject.java 2014-03-14 18:36:46 UTC (rev 299)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsObject.java 2014-03-14 19:52:03 UTC (rev 300)
@@ -2,10 +2,12 @@
import java.sql.SQLException;
-import org.hps.conditions.AbstractConditionsDatabaseObject.FieldValueMap;
+import org.hps.conditions.AbstractConditionsObject.FieldValueMap;
/**
- * This is an interface for accessing conditions database information by row.
+ * This is an ORM interface for accessing conditions database information by row.
+ * It can handle new or existing records. The ID values for new records are -1
+ * which indicates they are not in the database yet.
* @author Jeremy McCormick <[log in to unmask]>
*/
public interface ConditionsObject {
@@ -23,7 +25,7 @@
int getRowId();
/**
- * Get the set ID of this object identifying its collection.
+ * Get the collection ID of this object identifying its unique collection.
* @return The collection ID.
*/
int getCollectionId();
@@ -67,7 +69,8 @@
boolean isDirty();
/**
- * Generic set method. This will set the object to the 'dirty' state.
+ * Generic set method for field values.
+ * This will set the object to the 'dirty' state.
* @param fieldName The name of the field.
* @param fieldValue The field value.
*/
@@ -80,7 +83,7 @@
void setFieldValues(FieldValueMap fieldValues);
/**
- * Get a field value cast to the given type.
+ * Get a field value, cast to the given type.
* @param field The field value.
* @return The field value casted to type T.
*/
@@ -88,23 +91,42 @@
/**
* Set the ConnectionManager of this object.
+ * This cannot be reset once set.
* @param connectionManager The ConnectionManager.
+ * @throws ConditionsObjectException if already set
*/
- void setConnectionManager(ConnectionManager connectionManager);
+ void setConnectionManager(ConnectionManager connectionManager) throws ConditionsObjectException ;
/**
* Set the ConditionsTableMetaData of this object.
+ * This cannot be reset once set.
* @param tableMetaData The ConditionsTableMetaData.
+ * @throws ConditionsObjectException if already set
*/
- void setTableMetaData(ConditionsTableMetaData tableMetaData);
+ void setTableMetaData(ConditionsTableMetaData tableMetaData) throws ConditionsObjectException;
/**
* Set the collection ID of this object.
+ * This cannot be reset once set to a valid ID (e.g. not -1).
* @param collectionId The collection ID.
+ * @throws ConditionsObjectException if already set
*/
- void setCollectionId(int collectionId);
+ void setCollectionId(int collectionId) throws ConditionsObjectException;
/**
+ * Set the row ID of this object.
+ * This cannot be reset once set to a valid ID (e.g. not -1).
+ * @param rowId The object's row ID.
+ * @throws ConditionsObjectException if already set
+ */
+ public void setRowId(int rowId) throws ConditionsObjectException;
+
+ /**
+ * Set the object to read only mode. This cannot be changed back once it is set.
+ */
+ void setIsReadOnly();
+
+ /**
* Generic Exception type throw by methods in this interface.
*/
public static final class ConditionsObjectException extends Exception {
java/trunk/conditions/src/main/java/org/hps/conditions
--- java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsObjectCollection.java 2014-03-14 18:36:46 UTC (rev 299)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsObjectCollection.java 2014-03-14 19:52:03 UTC (rev 300)
@@ -1,35 +0,0 @@
-package org.hps.conditions;
-
-import java.sql.SQLException;
-import java.util.List;
-
-import org.hps.conditions.ConditionsObject.ConditionsObjectException;
-
-// TODO: This should be a generic with <T extends ConditionsDatabaseObject>
-// but of course this is a pain in the ass!!!
-public interface ConditionsObjectCollection {
-
- ConditionsObject get(int index);
-
- void add(ConditionsObject object);
-
- List<ConditionsObject> getObjects();
-
- ConditionsTableMetaData getTableMetaData();
-
- int getCollectionId();
-
- void updateAll() throws ConditionsObjectException;
-
- void deleteAll() throws ConditionsObjectException;
-
- void selectAll() throws ConditionsObjectException, SQLException;
-
- void insertAll() throws ConditionsObjectException, SQLException;
-
- boolean isDirty();
-
- boolean isReadOnly();
-
- boolean isNew();
-}
java/trunk/conditions/src/main/java/org/hps/conditions
--- java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsObjectFactory.java 2014-03-14 18:36:46 UTC (rev 299)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsObjectFactory.java 2014-03-14 19:52:03 UTC (rev 300)
@@ -1,6 +1,6 @@
package org.hps.conditions;
-import org.hps.conditions.AbstractConditionsDatabaseObject.FieldValueMap;
+import org.hps.conditions.AbstractConditionsObject.FieldValueMap;
import org.hps.conditions.ConditionsObject.ConditionsObjectException;
/**
@@ -11,21 +11,24 @@
/**
* Create a <code>ConditionsObject</code> generically, given a concrete class,
- * an associated table in the conditions database, a collection ID (which may be -1 for a new object),
- * and a map of field values.
+ * an associated table in the conditions database, and a map of field values.
*
+ * The collection ID should be assigned externally to this method by adding it
+ * to a <code>ConditionsObjectCollection</code>.
+ *
* @param klass The concrete Class to be instantiated, which must have a zero argument constructor.
* @param tableName The name of the table in the conditions database.
- * @param collectionId The unique collection
+ * @param collectionId The unique collection ID which should be set to -1 for a new collection.
* @param fieldValues The field values of the object.
* @return The new ConditionsObject with concrete type <code>klass</code>.
* @throws ConditionsObjectException if there is a problem creating the object.
*/
- public ConditionsObject createObject(
- Class<? extends ConditionsObject> klass,
- String tableName,
- int collectionId,
- FieldValueMap fieldValues) throws ConditionsObjectException;
+ public <T> T createObject(
+ Class<? extends ConditionsObject> klass,
+ String tableName,
+ int rowId,
+ FieldValueMap fieldValues,
+ boolean isReadOnly) throws ConditionsObjectException;
/**
* Get the registry of table meta data used by this factory.
java/trunk/conditions/src/main/java/org/hps/conditions/svt
--- java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtConditionsConverter.java 2014-03-14 18:36:46 UTC (rev 299)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtConditionsConverter.java 2014-03-14 19:52:03 UTC (rev 300)
@@ -60,14 +60,10 @@
// Add gains by channel.
SvtGainCollection gains = manager.getCachedConditions(SvtGainCollection.class, SVT_GAINS).getCachedData();
- //for (Entry<Integer,SvtGain> entry : gains.entrySet()) {
- // SvtChannel channel = conditions.getChannelMap().get(entry.getKey());
- // conditions.getChannelConstants(channel).setGain(entry.getValue());
- //}
- for (ConditionsObject object : gains.getObjects()) {
- int channelId = object.getFieldValue(Integer.class, "svt_channel_id");
+ for (SvtGain object : gains.getObjects()) {
+ int channelId = object.getChannelID();
SvtChannel channel = conditions.getChannelMap().get(channelId);
- conditions.getChannelConstants(channel).setGain((SvtGain)object);
+ conditions.getChannelConstants(channel).setGain(object);
}
// Set the time shifts by sensor.
java/trunk/conditions/src/main/java/org/hps/conditions/svt
--- java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtGain.java 2014-03-14 18:36:46 UTC (rev 299)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtGain.java 2014-03-14 19:52:03 UTC (rev 300)
@@ -1,14 +1,22 @@
package org.hps.conditions.svt;
-import org.hps.conditions.AbstractConditionsDatabaseObject;
+import org.hps.conditions.AbstractConditionsObject;
/**
* This class represents gain measurements for a single SVT channel.
* @author Jeremy McCormick <[log in to unmask]>
*/
-public class SvtGain extends AbstractConditionsDatabaseObject {
-
+public class SvtGain extends AbstractConditionsObject {
+
/**
+ * Get the channel ID.
+ * @return The channel ID.
+ */
+ int getChannelID() {
+ return getFieldValue(Integer.class, "svt_channel_id");
+ }
+
+ /**
* Get the gain.
* @return The gain value.
*/
@@ -24,6 +32,7 @@
return getFieldValue(Double.class, "offset");
}
+
/**
* Convert this object to a human-readable string.
* @return This object converted to a string.
java/trunk/conditions/src/main/java/org/hps/conditions/svt
--- java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtGainCollection.java 2014-03-14 18:36:46 UTC (rev 299)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtGainCollection.java 2014-03-14 19:52:03 UTC (rev 300)
@@ -1,6 +1,6 @@
package org.hps.conditions.svt;
-import org.hps.conditions.BasicConditionsObjectCollection;
+import org.hps.conditions.ConditionsObjectCollection;
import org.hps.conditions.ConditionsTableMetaData;
@@ -9,7 +9,7 @@
* with their SVT channel IDs from the database.
* @author Jeremy McCormick <[log in to unmask]>
*/
-public class SvtGainCollection extends BasicConditionsObjectCollection {
+public class SvtGainCollection extends ConditionsObjectCollection<SvtGain> {
public SvtGainCollection(ConditionsTableMetaData tableMetaData, int collectionId, boolean isReadOnly) {
super(tableMetaData, collectionId, isReadOnly);
java/trunk/conditions/src/main/java/org/hps/conditions/svt
--- java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtGainConverter.java 2014-03-14 18:36:46 UTC (rev 299)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtGainConverter.java 2014-03-14 19:52:03 UTC (rev 300)
@@ -3,8 +3,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
-import org.hps.conditions.AbstractConditionsDatabaseObject.FieldValueMap;
-import org.hps.conditions.ConditionsObject;
+import org.hps.conditions.AbstractConditionsObject.FieldValueMap;
import org.hps.conditions.ConditionsObject.ConditionsObjectException;
import org.hps.conditions.ConditionsRecord;
import org.hps.conditions.ConditionsTableMetaData;
@@ -41,7 +40,6 @@
int collectionId = record.getFieldValue();
// Objects for building the return value.
- //SvtGainCollection collection = new SvtGainCollection();
ConditionsTableMetaData tableMetaData = _objectFactory.getTableRegistry().getTableMetaData(tableName);
SvtGainCollection collection =
new SvtGainCollection(tableMetaData, collectionId, true);
@@ -50,7 +48,7 @@
ConnectionManager connectionManager = ConnectionManager.getConnectionManager();
// Construct the query to find matching calibration records using the ID field.
- String query = "SELECT svt_channel_id, gain, offset FROM "
+ String query = "SELECT id, svt_channel_id, gain, offset FROM "
+ tableName + " WHERE " + fieldName + " = " + collectionId
+ " ORDER BY svt_channel_id ASC";
@@ -61,15 +59,22 @@
// Loop over the gain records.
while(resultSet.next()) {
- // Setup conditions object.
+ // Get the object parameters from the ResultSet.
+ int rowId = resultSet.getInt(1);
FieldValueMap fieldValues = new FieldValueMap();
- fieldValues.put("svt_channel_id", resultSet.getInt(1));
- fieldValues.put("gain", resultSet.getDouble(2));
- fieldValues.put("offset", resultSet.getDouble(3));
- ConditionsObject newObject = _objectFactory.createObject(
- SvtGain.class, tableName, -1, fieldValues);
+ fieldValues.put("svt_channel_id", resultSet.getInt(2));
+ fieldValues.put("gain", resultSet.getDouble(3));
+ fieldValues.put("offset", resultSet.getDouble(4));
- // Add to collection.
+ // Create the object using the factory.
+ SvtGain newObject = _objectFactory.createObject(
+ SvtGain.class,
+ tableName,
+ rowId,
+ fieldValues,
+ true);
+
+ // Add the object to the collection.
collection.add(newObject);
}
} catch (SQLException x1) {
java/trunk/conditions/src/test/java/org/hps/conditions
--- java/trunk/conditions/src/test/java/org/hps/conditions/ConditionsDatabaseObjectTest.java 2014-03-14 18:36:46 UTC (rev 299)
+++ java/trunk/conditions/src/test/java/org/hps/conditions/ConditionsDatabaseObjectTest.java 2014-03-14 19:52:03 UTC (rev 300)
@@ -6,7 +6,7 @@
import junit.framework.TestCase;
-import org.hps.conditions.AbstractConditionsDatabaseObject.FieldValueMap;
+import org.hps.conditions.AbstractConditionsObject.FieldValueMap;
import org.hps.conditions.ConditionsObject.ConditionsObjectException;
/**
@@ -72,7 +72,7 @@
}
}
- public static class DummyConditionsObject extends AbstractConditionsDatabaseObject {
+ public static class DummyConditionsObject extends AbstractConditionsObject {
// Create a new object.
DummyConditionsObject(ConnectionManager connectionManager,
SVNspam 0.1