More strictness. Have to use a key to load individual records. Again this is

just as succinct, but type safer:

load(FooRecord.class, fooId) vs load(FooRecord.getKey(fooId))
This commit is contained in:
Michael Bayne
2009-05-29 18:36:25 +00:00
parent f052bba59d
commit 2b847056bf
2 changed files with 9 additions and 34 deletions
@@ -217,10 +217,10 @@ public abstract class DepotRepository
*
* @throws DatabaseException if any problem is encountered communicating with the database.
*/
protected <T extends PersistentRecord> T load (Key<T> key)
protected <T extends PersistentRecord> T load (Key<T> key, QueryClause... clauses)
throws DatabaseException
{
return load(key.getPersistentClass(), key);
return load(key, CacheStrategy.BEST, clauses);
}
/**
@@ -228,37 +228,12 @@ public abstract class DepotRepository
*
* @throws DatabaseException if any problem is encountered communicating with the database.
*/
protected <T extends PersistentRecord> T load (Class<T> type, Comparable<?> primaryKey,
protected <T extends PersistentRecord> T load (Key<T> key, CacheStrategy strategy,
QueryClause... clauses)
throws DatabaseException
{
clauses = ArrayUtil.append(clauses, _ctx.getMarshaller(type).makePrimaryKey(primaryKey));
return load(type, clauses);
}
/**
* Loads the persistent object that matches the specified primary key.
*
* @throws DatabaseException if any problem is encountered communicating with the database.
*/
protected <T extends PersistentRecord> T load (Class<T> type, ColumnExp ix, Comparable<?> val,
QueryClause... clauses)
throws DatabaseException
{
clauses = ArrayUtil.append(clauses, Key.newKey(type, ix, val));
return load(type, clauses);
}
/**
* Loads the first persistent object that matches the supplied query clauses.
*
* @throws DatabaseException if any problem is encountered communicating with the database.
*/
protected <T extends PersistentRecord> T load (
Class<T> type, Collection<? extends QueryClause> clauses)
throws DatabaseException
{
return load(type, clauses.toArray(new QueryClause[clauses.size()]));
clauses = ArrayUtil.append(clauses, key);
return _ctx.invoke(new FindOneQuery<T>(_ctx, key.getPersistentClass(), strategy, clauses));
}
/**
@@ -983,8 +958,8 @@ public abstract class DepotRepository
DepotMigrationHistoryRecord record;
while (true) {
// check to see if the migration has already been completed
record = load(DepotMigrationHistoryRecord.class, CacheStrategy.NONE,
DepotMigrationHistoryRecord.getKey(migration.getIdent()));
record = load(DepotMigrationHistoryRecord.getKey(migration.getIdent()),
CacheStrategy.NONE);
if (record != null && record.whenCompleted != null) {
return; // great, no need to do anything
}
@@ -90,7 +90,7 @@ public class TestRepository extends DepotRepository
record.numbers = new int[] { 9, 0, 2, 1, 0 };
repo.insert(record);
System.out.println("Record: " + repo.load(TestRecord.class, record.recordId));
System.out.println("Record: " + repo.load(TestRecord.getKey(record.recordId)));
// record.age = 25;
// record.name = "Bob";
@@ -100,7 +100,7 @@ public class TestRepository extends DepotRepository
repo.updatePartial(TestRecord.class, record.recordId,
TestRecord.AGE, 25, TestRecord.NAME, "Bob",
TestRecord.NUMBERS, new int[] { 1, 2, 3, 4, 5 });
System.out.println("Updated " + repo.load(TestRecord.class, record.recordId));
System.out.println("Updated " + repo.load(TestRecord.getKey(record.recordId)));
for (int ii = 2; ii < CREATE_RECORDS; ii++) {
record = new TestRecord();