Methods Summary |
---|
protected abstract java.lang.String | getInsertSql(Persistent p)Subclasses must implement this method to build an INSERT
statement for the specified persistent object.
|
protected abstract java.lang.String | getRemoveSql(Persistent p)Subclasses must implement this method to build a DELETE
statement for the specified persistent object.
|
protected abstract java.lang.String | getRestoreSql(Persistent p)Subclasses must implement this method to build a SELECT
statement that will restore only the named persistent object.
At the time it gets passed to this method, the persistent
object has only its ID set. All other values are awaiting
a restore operation.
|
protected abstract java.lang.String | getUpdateSql(Persistent p)Subclasses must implement this method to build an UPDATE
statement that will update the specified persistent object.
|
public void | insert(Persistent p, Transaction t)This method implements the insert persistence operation
as prescribed by the PersistentPeer interface. It asks
its subclasses for the proper SQL and then triggers
a save using that SQL statement.
save((DatabaseTransaction)t, getInsertSql(p));
|
public void | remove(Persistent p, Transaction t)This method implements the remove persistence operation
as prescribed by the PersistentPeer interface. It asks
its subclasses for the proper SQL and then triggers
a save using that SQL statement.
save((DatabaseTransaction)t, getRemoveSql(p));
|
public void | restore(Persistent p, Transaction trans)This method implements the restore persistence operation
as prescribed by the PersistentPeer interface. It asks
its subclasses for the proper SQL and then triggers
a save using that SQL statement.
String sql = getRestoreSql(p); // get the restore SQL
Connection connection = null;
Statement statement = null;
ResultSet results = null;
ResultSetMetaData meta = null;
try {
Hashtable h = new Hashtable(); // store the values here
// Get the connection from the DatabaseTransaction
connection = ((DatabaseTransaction)trans).getConnection();
// Create a JDBC statement from the connection
statement = connection.createStatement();
// Execute the SQL
results = statement.executeQuery(sql);
// Get the meta data
meta = results.getMetaData();
// Make sure we got a row!
if( !results.next() ) {
throw new PersistenceException("No rows found!");
}
// For each column in the result set
for(int i=1; i<=meta.getColumnCount(); i++) {
Object ob = results.getObject(i);
// Put the value in the Hashtable using the column name
// as a key
h.put(meta.getColumnLabel(i), ob);
}
// Call the restore from Hashtable method in the Persistent
p.restore(trans, h);
}
catch( SQLException e ) {
if( statement != null ) { // This is not required
try { statement.close(); }
catch( SQLException e2 ) { }
}
throw new PersistenceException(e);
}
|
private void | save(DatabaseTransaction trans, java.lang.String sql)
Connection connection = null;
Statement statement = null;
try {
connection = trans.getConnection(); // Get the JDBC connection
statement = connection.createStatement(); // Create a statement
statement.executeUpdate(sql); // Execute the SQL
statement.close(); // Close the statement (not required)
}
catch( SQLException e ) {
if( statement != null ) { // not required
try { statement.close(); }
catch( SQLException e2) { }
}
throw new PersistenceException(e);
}
|
public void | update(Persistent p, Transaction t)This method implements the update persistence operation
as prescribed by the PersistentPeer interface. It asks
its subclasses for the proper SQL and then triggers
a save using that SQL statement.
save((DatabaseTransaction)t, getUpdateSql(p));
|