Methods Summary |
---|
public abstract java.lang.String | getPersistentClass(java.util.Hashtable h)Subclasses must implement this method to provide the
DatabaseSetPeer with the name of a subclasses of Persistent
to instantiate for each row returned from the database.
|
public abstract java.lang.String | getSql(java.util.Hashtable h)Subclasses must implement this method to provide the
DatabaseSetPeer with the proper SQL for performing a query.
The Hashtable may be null.
|
public void | restore(PersistentSet set, Transaction trans)Implementation of the PersistentSetPeer method for restoring
a set without query criteria.
restore(set, trans, null);
|
public void | restore(PersistentSet set, Transaction trans, java.util.Hashtable data)Implementation of the PersistentSetPeer method for restoring
based on specified query criteria
ResultSetMetaData meta = null;
Connection connection = null;
Statement statement = null;
ResultSet results = null;
String sql = getSql(data); // Get the SQL from the subclass
try {
// Get the Connection from the DatabaseTransaction
connection = ((DatabaseTransaction)trans).getConnection();
// Create a Statement from the Connection
statement = connection.createStatement();
// Get the results
results = statement.executeQuery(sql);
// Get the meta data
meta = results.getMetaData();
// While there are rows in the result set
while( results.next() ) {
Hashtable h = new Hashtable(); // Store the results here
String class_name;
Persistent p;
// For each column in the row
for(int i=1; i<=meta.getColumnCount(); i++) {
Object ob = results.getObject(i); // Get the value
h.put(meta.getColumnLabel(i), ob); // Stick it in Hashtable
}
// Get the name of the class to create from this row
class_name = getPersistentClass(h);
// Get a Persistent from the Persistent
p = Persistent.getPersistent(trans, h, class_name);
// Add the Persistent to the set
set.addPersistent(p);
}
statement.close(); // closing statement closes results
connection.commit(); // Release database locks
}
catch( SQLException e ) {
if( statement != null ) {
try { statement.close(); } // closes results too
catch( SQLException e2 ) { }
}
throw new PersistenceException(e);
}
|