gov.noaa.pmel.tmap.db
Class DbaseObject

java.lang.Object
  |
  +--gov.noaa.pmel.tmap.db.DbaseObject
Direct Known Subclasses:
Axis, Category, Config, Constraint, ConstraintWidget, DbaseWidgetItem, Image, Institution, LiveMap, MetaData, Options, OptionsWidget, UI, VariableInfo, Widget

public class DbaseObject
extends java.lang.Object

Deserialize objects from the MySQL database.

A subclass of DbaseObject can specify which fields it wants to deserialize from the database, and reflection is used to stuff data deserialized from the database into the object.

Only supports String, int, and boolean SQL types

Example:

 // Define an object to be associated with the MyObject table
 public class MyObject extends DbaseObject {
 
   public String name;
   public String type;
 
   public MyObject(){
     super("MyObject"); // Associate this object with MyObject table in db
     addField("name");  // The name field will be deserialized from the name
                        // column of the MyObject table in the db
     addField("type");
   }
   ...
 }
 
 MyObject o = new MyObject();
 o.deserialize("5");   // Get the row with an id of 5
 System.out.println(o.name);
 
 

Version:
$Revision: 1.2 $
Author:
$Author: kobrien $

Nested Class Summary
(package private)  class DbaseObject.DbaseMap
           
 
Field Summary
(package private)  java.util.Vector mFields
           
(package private)  java.util.Vector mSerializable
           
(package private)  java.lang.String mTable
           
(package private)  java.lang.String oid
           
(package private) static java.lang.String OID
           
 
Constructor Summary
protected DbaseObject(java.lang.String name)
          Instantiate a new DbaseObject to be associated with a db table
 
Method Summary
protected  void addField(java.lang.String name)
          Add a field from this class to the list of columns to be deserialized from the table associated with this object.
protected  void addField(java.lang.String fname, java.lang.String cname)
          Add a field from this class to the list of columns to be deserialized from the table associated with this object.
protected  void convert(java.lang.reflect.Field f, java.sql.ResultSet rs, int column)
           
 void deserialize(java.lang.String id)
          Deserialize a row of a table into this object using key this.OID
 void deserialize(java.lang.String id, java.lang.String key)
          Deserialize a row of a table into this object.
 void deserialize(java.lang.String id, java.lang.String key, java.lang.String addedConstraint)
          Deserialize a row of a table into this object.
(package private)  java.util.Vector deserializeAggregate()
          Deserialize a db table into a vector of objects.
(package private)  java.util.Vector deserializeAggregate(java.lang.String id, java.lang.String fk)
          Deserialize a db table into a vector of objects.
(package private)  java.util.Vector deserializeAggregate(java.lang.String id, java.lang.String fk, java.lang.String addedConstraint)
          Deserialize a db table into a vector of objects.
(package private)  java.util.Vector deserializeManyToMany(java.lang.String id, java.lang.String fk, java.lang.String joinTable, java.lang.String joinTableKey)
           
(package private)  java.util.Vector deserializeManyToMany(java.lang.String id, java.lang.String fk, java.lang.String joinTable, java.lang.String joinTableKey, java.lang.String addedConstraint)
          Deserialize a db table into a vector of objects.
(package private)  java.util.Vector doDeserializeAggregate(java.lang.String id, java.lang.String fk, java.lang.String joinTable, java.lang.String joinTableKey, java.lang.String addedConstraint)
           
 java.lang.String getOid()
          Get the object id of this object
protected  void setup()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

mTable

java.lang.String mTable

mSerializable

java.util.Vector mSerializable

mFields

java.util.Vector mFields

OID

static final java.lang.String OID
See Also:
Constant Field Values

oid

java.lang.String oid
Constructor Detail

DbaseObject

protected DbaseObject(java.lang.String name)
Instantiate a new DbaseObject to be associated with a db table

Parameters:
name - name of db table
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getOid

public java.lang.String getOid()
Get the object id of this object

Returns:
object id

addField

protected void addField(java.lang.String name)
Add a field from this class to the list of columns to be deserialized from the table associated with this object.

The field name must be the same as the column name

Parameters:
name - field name to add

addField

protected void addField(java.lang.String fname,
                        java.lang.String cname)
Add a field from this class to the list of columns to be deserialized from the table associated with this object.

The field name does not have to be the same as the column name


setup

protected void setup()
              throws java.sql.SQLException
java.sql.SQLException

convert

protected void convert(java.lang.reflect.Field f,
                       java.sql.ResultSet rs,
                       int column)
                throws java.sql.SQLException
java.sql.SQLException

doDeserializeAggregate

java.util.Vector doDeserializeAggregate(java.lang.String id,
                                        java.lang.String fk,
                                        java.lang.String joinTable,
                                        java.lang.String joinTableKey,
                                        java.lang.String addedConstraint)
                                  throws java.sql.SQLException
java.sql.SQLException

deserializeManyToMany

java.util.Vector deserializeManyToMany(java.lang.String id,
                                       java.lang.String fk,
                                       java.lang.String joinTable,
                                       java.lang.String joinTableKey,
                                       java.lang.String addedConstraint)
                                 throws java.sql.SQLException
Deserialize a db table into a vector of objects.

This method handles the case where there is a many to many relationship between two tables. It is assumed that a separate join table is used to quantify this relationship.

For instance if the fk is "varid", the joinTable "AxisVariableJoin", and the joinTableKey "axisid", the following SQL statement might be issued:

    SELECT Axis... from Axis,AxisVariableJoin where Axis.oid=AxisVariableJoin.axisid and varid=1
 

Parameters:
id - key to use with the "other" key in join table
fk - foreign key of this object into the join table
joinTable - name of the join table
joinTableKey - other key to use in join table
addedConstraint - any other SQL parameters
Returns:
Vector of deserialized objects
java.sql.SQLException

deserializeManyToMany

java.util.Vector deserializeManyToMany(java.lang.String id,
                                       java.lang.String fk,
                                       java.lang.String joinTable,
                                       java.lang.String joinTableKey)
                                 throws java.sql.SQLException
Parameters:
id - key to use with the "other" key in join table
fk - foreign key of this object into the join table
joinTable - name of the join table
joinTableKey - other key to use in join table
Returns:
Vector of deserialized objects
java.sql.SQLException
See Also:
deserializeManyToMany(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)

deserializeAggregate

java.util.Vector deserializeAggregate(java.lang.String id,
                                      java.lang.String fk,
                                      java.lang.String addedConstraint)
                                throws java.sql.SQLException
Deserialize a db table into a vector of objects.

This method handles the case where there is a one to many relationship between two tables.

Parameters:
id - value of key
fk - name of key to use
addedConstraint - any other SQL parameters
Returns:
Vector of deserialized objects
java.sql.SQLException

deserializeAggregate

java.util.Vector deserializeAggregate()
                                throws java.sql.SQLException
Deserialize a db table into a vector of objects.

All table rows are returned.

Returns:
Vector of deserialized objects
java.sql.SQLException

deserializeAggregate

java.util.Vector deserializeAggregate(java.lang.String id,
                                      java.lang.String fk)
                                throws java.sql.SQLException
Deserialize a db table into a vector of objects.

This method handles the case where there is a one to many relationship between two tables.

Parameters:
id - value of key
fk - name of key to use
Returns:
Vector of deserialized objects
java.sql.SQLException

deserialize

public void deserialize(java.lang.String id)
                 throws java.sql.SQLException
Deserialize a row of a table into this object using key this.OID

Parameters:
id - key value to deserialize
java.sql.SQLException

deserialize

public void deserialize(java.lang.String id,
                        java.lang.String key)
                 throws java.sql.SQLException
Deserialize a row of a table into this object.

Parameters:
id - key value to deserialize
key - name of table column to use as key
java.sql.SQLException

deserialize

public void deserialize(java.lang.String id,
                        java.lang.String key,
                        java.lang.String addedConstraint)
                 throws java.sql.SQLException
Deserialize a row of a table into this object.

Parameters:
id - key value to deserialize
key - name of table column to use as key
addedConstraint - any other SQL parameters
java.sql.SQLException