LISTSERV mailing list manager LISTSERV 16.5

Help for HPS-SVN Archives


HPS-SVN Archives

HPS-SVN Archives


HPS-SVN@LISTSERV.SLAC.STANFORD.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

HPS-SVN Home

HPS-SVN Home

HPS-SVN  December 2014

HPS-SVN December 2014

Subject:

r1691 - in /java/trunk/conditions/src/main/java/org/hps/conditions/api: AbstractConditionsObject.java ConditionsObject.java

From:

[log in to unmask]

Reply-To:

Notification of commits to the hps svn repository <[log in to unmask]>

Date:

Thu, 11 Dec 2014 19:33:01 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (230 lines)

Author: [log in to unmask]
Date: Thu Dec 11 11:32:57 2014
New Revision: 1691

Log:
Simplify conditions object API.  Database operations will go through the collection interface instead.

Modified:
    java/trunk/conditions/src/main/java/org/hps/conditions/api/AbstractConditionsObject.java
    java/trunk/conditions/src/main/java/org/hps/conditions/api/ConditionsObject.java

Modified: java/trunk/conditions/src/main/java/org/hps/conditions/api/AbstractConditionsObject.java
 =============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/api/AbstractConditionsObject.java	(original)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/api/AbstractConditionsObject.java	Thu Dec 11 11:32:57 2014
@@ -1,14 +1,6 @@
 package org.hps.conditions.api;
 
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.util.List;
-
-import org.hps.conditions.database.DatabaseConditionsManager;
-import org.hps.conditions.database.DatabaseUtilities;
-import org.hps.conditions.database.QueryBuilder;
-import org.hps.conditions.database.TableMetaData;
+import java.util.Map.Entry;
 
 /**
  * The abstract implementation of {@link ConditionsObject}.
@@ -16,88 +8,25 @@
  */
 public abstract class AbstractConditionsObject implements ConditionsObject {
 
-    private TableMetaData tableMetaData = null;
     protected int rowId = -1;
-    protected int collectionId = -1;
     protected FieldValueMap fieldValues;
 
-    /**
+    /** 
      * Constructor for sub-classing.
      */
     protected AbstractConditionsObject() {
         fieldValues = new FieldValueMap();
     }
 
-    public TableMetaData getTableMetaData() {
-        return tableMetaData;
-    }
-
     public int getRowId() {
         return rowId;
-    }
-
-    public int getCollectionId() {
-        return collectionId;
     }
 
     public boolean isNew() {
         return rowId == -1;
     }
 
-    public void delete() throws ConditionsObjectException {
-        String query = QueryBuilder.buildDelete(tableMetaData.getTableName(), rowId);
-        // TODO: Replace this with a method that takes a conditions object.
-        DatabaseConditionsManager.getInstance().updateQuery(query);
-        rowId = -1;
-    }
-
-    public void insert() throws ConditionsObjectException {
-        if (fieldValues.size() == 0)
-            throw new ConditionsObjectException("There are no field values to insert.");
-        if (collectionId == -1)
-            throw new ConditionsObjectException("The object's collection ID is not valid.");
-        // TODO: Replace this with a method that takes a conditions object.
-        String query = QueryBuilder.buildInsert(getTableMetaData().getTableName(), getCollectionId(), getTableMetaData().getFieldNames(), fieldValues.valuesToArray());
-        System.out.println(query);
-        List<Integer> keys = DatabaseConditionsManager.getInstance().updateQuery(query);
-        if (keys.size() != 1) {
-            throw new ConditionsObjectException("SQL insert returned wrong number of keys: " + keys.size());
-        }
-        rowId = keys.get(0);
-    }
-
-    public void select() throws ConditionsObjectException {
-        if (isNew()) {
-            throw new ConditionsObjectException("Record has not been inserted into the database yet.");
-        }
-        // TODO: Replace this with method that takes a conditions object.
-        String query = QueryBuilder.buildSelect(getTableMetaData().getTableName(), collectionId, fieldValues.fieldsToArray(), "id ASC");
-        DatabaseConditionsManager manager = DatabaseConditionsManager.getInstance();
-        ResultSet resultSet = manager.selectQuery(query);
-        try {
-            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));
-                }
-            }
-        } catch (SQLException e) {
-            throw new ConditionsObjectException(e.getMessage(), this);
-        }
-        DatabaseUtilities.close(resultSet);
-        resultSet = null;
-    }
-
-    public void update() throws ConditionsObjectException {
-        if (fieldValues.size() == 0) {
-            throw new ConditionsObjectException("No field values to update.", this);
-        }
-        // TODO: Replace this with method that takes a conditions object.
-        String query = QueryBuilder.buildUpdate(tableMetaData.getTableName(), rowId, fieldValues.fieldsToArray(), fieldValues.valuesToArray());
-        DatabaseConditionsManager.getInstance().updateQuery(query);
-    }
-
+   
     public void setFieldValue(String key, Object value) {
         fieldValues.put(key, value);
     }
@@ -119,18 +48,6 @@
         return (T) fieldValues.get(field);
     }
 
-    public void setTableMetaData(TableMetaData tableMetaData) throws ConditionsObjectException {
-        if (this.tableMetaData != null)
-            throw new ConditionsObjectException("The table meta data cannot be reset on an object.", this);
-        this.tableMetaData = tableMetaData;
-    }
-
-    public void setCollectionId(int collectionId) throws ConditionsObjectException {
-        if (this.collectionId != -1)
-            throw new ConditionsObjectException("The collection ID cannot be reassigned once set.", this);
-        this.collectionId = collectionId;
-    }
-
     public void setRowId(int rowId) throws ConditionsObjectException {
         if (!isNew()) {
             throw new ConditionsObjectException("The row ID cannot be reassigned on an existing object.");
@@ -142,8 +59,8 @@
         StringBuffer sb = new StringBuffer();
         sb.append(this.getRowId());
         sb.append('\t');
-        for (String fieldName : getTableMetaData().getFieldNames()) {
-            sb.append(getFieldValue(fieldName));
+        for (Entry<String, Object> entries : this.getFieldValues().entrySet()) {
+            sb.append(entries.getValue());
             sb.append('\t');
         }
         return sb.toString();

Modified: java/trunk/conditions/src/main/java/org/hps/conditions/api/ConditionsObject.java
 =============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/api/ConditionsObject.java	(original)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/api/ConditionsObject.java	Thu Dec 11 11:32:57 2014
@@ -8,47 +8,19 @@
  * -1 which indicates they are not in the database yet.
  * @author Jeremy McCormick <[log in to unmask]>
  */
-// TODO: The collection ID should be a regular field in the FieldValueMap.
 public interface ConditionsObject {
 
     /**
      * Get the database table meta data associated to this object.
      * @return The database table meta data associated to this object.
      */
-    TableMetaData getTableMetaData();
+    //TableMetaData getTableMetaData();
 
     /**
      * Get the row ID of this object.
      * @return The database row ID.
      */
     int getRowId();
-
-    /**
-     * Get the collection ID of this object identifying its unique collection.
-     * @return The collection ID.
-     */
-    int getCollectionId();
-
-    /**
-     * Update this row in the database using a SQL UPDATE statement.
-     */
-    void update() throws ConditionsObjectException;
-
-    /**
-     * Delete this object's row in the database using a SQL DELETE statement.
-     */
-    void delete() throws ConditionsObjectException;
-
-    /**
-     * Insert this object into the database using a SQL INSERT statement.
-     */
-    void insert() throws ConditionsObjectException;
-
-    /**
-     * Select data into this object from the database using a SQL SELECT
-     * statement.
-     */
-    void select() throws ConditionsObjectException;
 
     /**
      * Generic set method for field values. This will set the object to the
@@ -86,22 +58,6 @@
     public <T> T getFieldValue(String field);
 
     /**
-     * Set the ConditionsTableMetaData of this object. This cannot be reset once
-     * set.
-     * @param tableMetaData The ConditionsTableMetaData.
-     * @throws ConditionsObjectException if already set
-     */
-    void setTableMetaData(TableMetaData 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) 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.

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

November 2017
August 2017
July 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013

ATOM RSS1 RSS2



LISTSERV.SLAC.STANFORD.EDU

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager

Privacy Notice, Security Notice and Terms of Use