Allow caching to be skipped for single record loads, ensure that we don't cache

DepotMigrationHistoryRecord.
This commit is contained in:
Michael Bayne
2009-01-09 21:40:30 +00:00
parent c46535cffd
commit a8b3e24e87
2 changed files with 22 additions and 3 deletions
@@ -271,7 +271,19 @@ public abstract class DepotRepository
protected <T extends PersistentRecord> T load (Class<T> type, QueryClause... clauses) protected <T extends PersistentRecord> T load (Class<T> type, QueryClause... clauses)
throws DatabaseException throws DatabaseException
{ {
return _ctx.invoke(new FindOneQuery<T>(_ctx, type, clauses)); return load(type, CacheStrategy.BEST, 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, CacheStrategy strategy,
QueryClause... clauses)
throws DatabaseException
{
return _ctx.invoke(new FindOneQuery<T>(_ctx, type, strategy, clauses));
} }
/** /**
@@ -1063,7 +1075,8 @@ public abstract class DepotRepository
DepotMigrationHistoryRecord record; DepotMigrationHistoryRecord record;
while (true) { while (true) {
// check to see if the migration has already been completed // check to see if the migration has already been completed
record = load(DepotMigrationHistoryRecord.class, migration.getIdent()); record = load(DepotMigrationHistoryRecord.class, CacheStrategy.NONE,
DepotMigrationHistoryRecord.getKey(migration.getIdent()));
if (record != null && record.whenCompleted != null) { if (record != null && record.whenCompleted != null) {
return; // great, no need to do anything return; // great, no need to do anything
} }
@@ -45,9 +45,11 @@ import static com.samskivert.depot.Log.log;
*/ */
public class FindOneQuery<T extends PersistentRecord> extends Query<T> public class FindOneQuery<T extends PersistentRecord> extends Query<T>
{ {
public FindOneQuery (PersistenceContext ctx, Class<T> type, QueryClause[] clauses) public FindOneQuery (PersistenceContext ctx, Class<T> type,
DepotRepository.CacheStrategy strategy, QueryClause[] clauses)
throws DatabaseException throws DatabaseException
{ {
_strategy = strategy;
_marsh = ctx.getMarshaller(type); _marsh = ctx.getMarshaller(type);
_select = new SelectClause<T>(type, _marsh.getFieldNames(), clauses); _select = new SelectClause<T>(type, _marsh.getFieldNames(), clauses);
WhereClause where = _select.getWhereClause(); WhereClause where = _select.getWhereClause();
@@ -123,10 +125,14 @@ public class FindOneQuery<T extends PersistentRecord> extends Query<T>
protected CacheKey getCacheKey () protected CacheKey getCacheKey ()
{ {
if (_strategy == DepotRepository.CacheStrategy.NONE) {
return null;
}
WhereClause where = _select.getWhereClause(); WhereClause where = _select.getWhereClause();
return (where != null && where instanceof CacheKey) ? (CacheKey)where : null; return (where != null && where instanceof CacheKey) ? (CacheKey)where : null;
} }
protected DepotRepository.CacheStrategy _strategy;
protected DepotMarshaller<T> _marsh; protected DepotMarshaller<T> _marsh;
protected SelectClause<T> _select; protected SelectClause<T> _select;
protected SQLBuilder _builder; protected SQLBuilder _builder;