|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--gov.noaa.pmel.tmap.db.DbaseObject
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);
| 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 |
java.lang.String mTable
java.util.Vector mSerializable
java.util.Vector mFields
static final java.lang.String OID
java.lang.String oid
| Constructor Detail |
protected DbaseObject(java.lang.String name)
name - name of db table| Method Detail |
public java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String getOid()
protected void addField(java.lang.String name)
The field name must be the same as the column name
name - field name to add
protected void addField(java.lang.String fname,
java.lang.String cname)
The field name does not have to be the same as the column name
protected void setup()
throws java.sql.SQLException
java.sql.SQLException
protected void convert(java.lang.reflect.Field f,
java.sql.ResultSet rs,
int column)
throws java.sql.SQLException
java.sql.SQLException
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
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
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
id - key to use with the "other" key in join tablefk - foreign key of this object into the join tablejoinTable - name of the join tablejoinTableKey - other key to use in join tableaddedConstraint - any other SQL parameters
java.sql.SQLException
java.util.Vector deserializeManyToMany(java.lang.String id,
java.lang.String fk,
java.lang.String joinTable,
java.lang.String joinTableKey)
throws java.sql.SQLException
id - key to use with the "other" key in join tablefk - foreign key of this object into the join tablejoinTable - name of the join tablejoinTableKey - other key to use in join table
java.sql.SQLExceptiondeserializeManyToMany(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
java.util.Vector deserializeAggregate(java.lang.String id,
java.lang.String fk,
java.lang.String addedConstraint)
throws java.sql.SQLException
This method handles the case where there is a one to many relationship between two tables.
id - value of keyfk - name of key to useaddedConstraint - any other SQL parameters
java.sql.SQLException
java.util.Vector deserializeAggregate()
throws java.sql.SQLException
All table rows are returned.
java.sql.SQLException
java.util.Vector deserializeAggregate(java.lang.String id,
java.lang.String fk)
throws java.sql.SQLException
This method handles the case where there is a one to many relationship between two tables.
id - value of keyfk - name of key to use
java.sql.SQLException
public void deserialize(java.lang.String id)
throws java.sql.SQLException
id - key value to deserialize
java.sql.SQLException
public void deserialize(java.lang.String id,
java.lang.String key)
throws java.sql.SQLException
id - key value to deserializekey - name of table column to use as key
java.sql.SQLException
public void deserialize(java.lang.String id,
java.lang.String key,
java.lang.String addedConstraint)
throws java.sql.SQLException
id - key value to deserializekey - name of table column to use as keyaddedConstraint - any other SQL parameters
java.sql.SQLException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||