We're getting jiggy with the convenience.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@1653 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2005-06-08 23:09:37 +00:00
parent 2931cb9dc8
commit 57b6bd257d
2 changed files with 64 additions and 0 deletions
@@ -104,6 +104,23 @@ public abstract class JORARepository extends SimpleRepository
});
}
/**
* Loads a single object from the specified table that matches the
* supplied example. <em>Note:</em> the query should match one or zero
* records, not more.
*/
protected Object loadByExample (final Table table, final Object example)
throws PersistenceException
{
return execute(new Operation() {
public Object invoke (Connection conn, DatabaseLiaison liaison)
throws SQLException, PersistenceException
{
return table.queryByExample(example).next();
}
});
}
/**
* First attempts to update the supplied object and if that modifies
* zero rows, inserts the object into the specified table. The table
@@ -197,6 +197,53 @@ public class SimpleRepository extends Repository
}
}
/**
* Executes the supplied update query in this repository, ignoring the
* return value.
*/
protected void update (final String query)
throws PersistenceException
{
execute(new Operation() {
public Object invoke (Connection conn, DatabaseLiaison liaison)
throws SQLException, PersistenceException
{
Statement stmt = null;
try {
stmt = conn.createStatement();
stmt.executeUpdate(query);
} finally {
JDBCUtil.close(stmt);
}
return null;
}
});
}
/**
* Executes the supplied update query in this repository, throwing an
* exception if the modification count is not equal to the specified
* count.
*/
protected void checkedUpdate (final String query, final int count)
throws PersistenceException
{
execute(new Operation() {
public Object invoke (Connection conn, DatabaseLiaison liaison)
throws SQLException, PersistenceException
{
Statement stmt = null;
try {
stmt = conn.createStatement();
JDBCUtil.checkedUpdate(stmt, query, 1);
} finally {
JDBCUtil.close(stmt);
}
return null;
}
});
}
/**
* Called when we fetch a connection from the provider. This gives
* derived classes an opportunity to configure whatever internals they