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:
@@ -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
|
* First attempts to update the supplied object and if that modifies
|
||||||
* zero rows, inserts the object into the specified table. The table
|
* 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
|
* Called when we fetch a connection from the provider. This gives
|
||||||
* derived classes an opportunity to configure whatever internals they
|
* derived classes an opportunity to configure whatever internals they
|
||||||
|
|||||||
Reference in New Issue
Block a user