Added some convenience methods for people that go for that whole brevity
thing. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1652 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -53,6 +53,77 @@ public abstract class JORARepository extends SimpleRepository
|
|||||||
createTables(_session);
|
createTables(_session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inserts the supplied object into the specified table. The table
|
||||||
|
* must be configured to store items of the supplied type.
|
||||||
|
*/
|
||||||
|
protected void insert (final Table table, final Object object)
|
||||||
|
throws PersistenceException
|
||||||
|
{
|
||||||
|
execute(new Operation() {
|
||||||
|
public Object invoke (Connection conn, DatabaseLiaison liaison)
|
||||||
|
throws SQLException, PersistenceException
|
||||||
|
{
|
||||||
|
table.insert(object);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the supplied object in the specified table. The table must
|
||||||
|
* be configured to store items of the supplied type.
|
||||||
|
*/
|
||||||
|
protected void update (final Table table, final Object object)
|
||||||
|
throws PersistenceException
|
||||||
|
{
|
||||||
|
execute(new Operation() {
|
||||||
|
public Object invoke (Connection conn, DatabaseLiaison liaison)
|
||||||
|
throws SQLException, PersistenceException
|
||||||
|
{
|
||||||
|
table.update(object);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads a single object from the specified table that matches the
|
||||||
|
* supplied query. <em>Note:</em> the query should match one or zero
|
||||||
|
* records, not more.
|
||||||
|
*/
|
||||||
|
protected Object load (final Table table, final String query)
|
||||||
|
throws PersistenceException
|
||||||
|
{
|
||||||
|
return execute(new Operation() {
|
||||||
|
public Object invoke (Connection conn, DatabaseLiaison liaison)
|
||||||
|
throws SQLException, PersistenceException
|
||||||
|
{
|
||||||
|
return table.select(query).next();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* First attempts to update the supplied object and if that modifies
|
||||||
|
* zero rows, inserts the object into the specified table. The table
|
||||||
|
* must be configured to store items of the supplied type.
|
||||||
|
*/
|
||||||
|
protected void store (final Table table, final Object object)
|
||||||
|
throws PersistenceException
|
||||||
|
{
|
||||||
|
execute(new Operation() {
|
||||||
|
public Object invoke (Connection conn, DatabaseLiaison liaison)
|
||||||
|
throws SQLException, PersistenceException
|
||||||
|
{
|
||||||
|
if (table.update(object) == 0) {
|
||||||
|
table.insert(object);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the specified field in the supplied object (which must
|
* Updates the specified field in the supplied object (which must
|
||||||
* correspond to the supplied table).
|
* correspond to the supplied table).
|
||||||
@@ -95,6 +166,19 @@ public abstract class JORARepository extends SimpleRepository
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void delete (final Table table, final Object object)
|
||||||
|
throws PersistenceException
|
||||||
|
{
|
||||||
|
execute(new Operation() {
|
||||||
|
public Object invoke (Connection conn, DatabaseLiaison liaison)
|
||||||
|
throws SQLException, PersistenceException
|
||||||
|
{
|
||||||
|
table.delete(object);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* After the database session is begun, this function will be called
|
* After the database session is begun, this function will be called
|
||||||
* to give the repository implementation the opportunity to create its
|
* to give the repository implementation the opportunity to create its
|
||||||
|
|||||||
Reference in New Issue
Block a user