Query -> Fetcher because I want to next change QueryBuilder -> Query so that it
looks nicer when you keep partially constructed queries around.
This commit is contained in:
@@ -50,7 +50,7 @@ import com.samskivert.depot.impl.DepotTypes;
|
|||||||
import com.samskivert.depot.impl.KeyCacheKey;
|
import com.samskivert.depot.impl.KeyCacheKey;
|
||||||
import com.samskivert.depot.impl.Modifier;
|
import com.samskivert.depot.impl.Modifier;
|
||||||
import com.samskivert.depot.impl.Operation;
|
import com.samskivert.depot.impl.Operation;
|
||||||
import com.samskivert.depot.impl.Query;
|
import com.samskivert.depot.impl.Fetcher;
|
||||||
import com.samskivert.depot.impl.SQLBuilder;
|
import com.samskivert.depot.impl.SQLBuilder;
|
||||||
|
|
||||||
import static com.samskivert.depot.Log.log;
|
import static com.samskivert.depot.Log.log;
|
||||||
@@ -278,17 +278,17 @@ public class PersistenceContext
|
|||||||
/**
|
/**
|
||||||
* Invokes a non-modifying query and returns its result.
|
* Invokes a non-modifying query and returns its result.
|
||||||
*/
|
*/
|
||||||
public <T> T invoke (Query<T> query)
|
public <T> T invoke (Fetcher<T> fetcher)
|
||||||
throws DatabaseException
|
throws DatabaseException
|
||||||
{
|
{
|
||||||
// we check to see if the query is already cached before invoking it to avoid requesting a
|
// we check to see if the query is already cached before invoking it to avoid requesting a
|
||||||
// database connection if we don't actually need one
|
// database connection if we don't actually need one
|
||||||
T result = query.getCachedResult(this);
|
T result = fetcher.getCachedResult(this);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
query.updateStats(_stats);
|
fetcher.updateStats(_stats);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return invoke(query, true);
|
return invoke(fetcher, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1037,7 +1037,7 @@ public class DepotMarshaller<T extends PersistentRecord> implements QueryMarshal
|
|||||||
public static TableMetaData load (PersistenceContext ctx, final String tableName)
|
public static TableMetaData load (PersistenceContext ctx, final String tableName)
|
||||||
throws DatabaseException
|
throws DatabaseException
|
||||||
{
|
{
|
||||||
return ctx.invoke(new Query.Trivial<TableMetaData>() {
|
return ctx.invoke(new Fetcher.Trivial<TableMetaData>() {
|
||||||
public TableMetaData invoke (PersistenceContext ctx, Connection conn,
|
public TableMetaData invoke (PersistenceContext ctx, Connection conn,
|
||||||
DatabaseLiaison dl) throws SQLException {
|
DatabaseLiaison dl) throws SQLException {
|
||||||
return new TableMetaData(conn.getMetaData(), tableName);
|
return new TableMetaData(conn.getMetaData(), tableName);
|
||||||
|
|||||||
+3
-3
@@ -25,13 +25,13 @@ import com.samskivert.depot.PersistenceContext;
|
|||||||
/**
|
/**
|
||||||
* The base of all read-only queries.
|
* The base of all read-only queries.
|
||||||
*/
|
*/
|
||||||
public abstract class Query<T>
|
public abstract class Fetcher<T>
|
||||||
implements Operation<T>
|
implements Operation<T>
|
||||||
{
|
{
|
||||||
/** A simple base class for non-complex queries. */
|
/** A simple base class for non-complex queries. */
|
||||||
public static abstract class Trivial<T> extends Query<T>
|
public static abstract class Trivial<T> extends Fetcher<T>
|
||||||
{
|
{
|
||||||
@Override // from Query
|
@Override // from Fetcher
|
||||||
public T getCachedResult (PersistenceContext ctx) {
|
public T getCachedResult (PersistenceContext ctx) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -43,7 +43,7 @@ import static com.samskivert.depot.Log.log;
|
|||||||
/**
|
/**
|
||||||
* Loads all primary keys for the records matching the supplied clause.
|
* Loads all primary keys for the records matching the supplied clause.
|
||||||
*/
|
*/
|
||||||
public class FindAllKeysQuery<T extends PersistentRecord> extends Query<List<Key<T>>>
|
public class FindAllKeysQuery<T extends PersistentRecord> extends Fetcher<List<Key<T>>>
|
||||||
{
|
{
|
||||||
public FindAllKeysQuery (PersistenceContext ctx, Class<T> type, boolean forUpdate,
|
public FindAllKeysQuery (PersistenceContext ctx, Class<T> type, boolean forUpdate,
|
||||||
Iterable<? extends QueryClause> clauses)
|
Iterable<? extends QueryClause> clauses)
|
||||||
@@ -62,13 +62,13 @@ public class FindAllKeysQuery<T extends PersistentRecord> extends Query<List<Key
|
|||||||
return !_forUpdate;
|
return !_forUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // from Query
|
@Override // from Fetcher
|
||||||
public List<Key<T>> getCachedResult (PersistenceContext ctx)
|
public List<Key<T>> getCachedResult (PersistenceContext ctx)
|
||||||
{
|
{
|
||||||
return null; // TODO
|
return null; // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
// from Query
|
// from Fetcher
|
||||||
public List<Key<T>> invoke (PersistenceContext ctx, Connection conn, DatabaseLiaison liaison)
|
public List<Key<T>> invoke (PersistenceContext ctx, Connection conn, DatabaseLiaison liaison)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
@@ -85,7 +85,7 @@ public class FindAllKeysQuery<T extends PersistentRecord> extends Query<List<Key
|
|||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
// from Query
|
// from Fetcher
|
||||||
public void updateStats (Stats stats)
|
public void updateStats (Stats stats)
|
||||||
{
|
{
|
||||||
stats.noteQuery(0, 1, 0, 0, 0); // one uncached query
|
stats.noteQuery(0, 1, 0, 0, 0); // one uncached query
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ import static com.samskivert.depot.Log.log;
|
|||||||
* a collection of persistent objects using one of two included strategies.
|
* a collection of persistent objects using one of two included strategies.
|
||||||
*/
|
*/
|
||||||
public abstract class FindAllQuery<T extends PersistentRecord,R>
|
public abstract class FindAllQuery<T extends PersistentRecord,R>
|
||||||
extends Query<List<R>>
|
extends Fetcher<List<R>>
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* A base class for queries that fetch a full record at a time.
|
* A base class for queries that fetch a full record at a time.
|
||||||
@@ -113,7 +113,7 @@ public abstract class FindAllQuery<T extends PersistentRecord,R>
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // from Query
|
@Override // from Fetcher
|
||||||
public List<T> getCachedResult (PersistenceContext ctx)
|
public List<T> getCachedResult (PersistenceContext ctx)
|
||||||
{
|
{
|
||||||
if (_qkey == null) {
|
if (_qkey == null) {
|
||||||
@@ -128,7 +128,7 @@ public abstract class FindAllQuery<T extends PersistentRecord,R>
|
|||||||
return (_fetchKeys.size() == 0) ? resolve(_keys, _entities) : null;
|
return (_fetchKeys.size() == 0) ? resolve(_keys, _entities) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// from Query
|
// from Fetcher
|
||||||
public List<T> invoke (PersistenceContext ctx, Connection conn, DatabaseLiaison liaison)
|
public List<T> invoke (PersistenceContext ctx, Connection conn, DatabaseLiaison liaison)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
@@ -185,7 +185,7 @@ public abstract class FindAllQuery<T extends PersistentRecord,R>
|
|||||||
_keys = keys;
|
_keys = keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // from Query
|
@Override // from Fetcher
|
||||||
public List<T> getCachedResult (PersistenceContext ctx)
|
public List<T> getCachedResult (PersistenceContext ctx)
|
||||||
{
|
{
|
||||||
// look up what we can from the cache
|
// look up what we can from the cache
|
||||||
@@ -195,7 +195,7 @@ public abstract class FindAllQuery<T extends PersistentRecord,R>
|
|||||||
return _fetchKeys.isEmpty() ? resolve(_keys, _entities) : null;
|
return _fetchKeys.isEmpty() ? resolve(_keys, _entities) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// from Query
|
// from Fetcher
|
||||||
public List<T> invoke (PersistenceContext ctx, Connection conn, DatabaseLiaison liaison)
|
public List<T> invoke (PersistenceContext ctx, Connection conn, DatabaseLiaison liaison)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
@@ -228,7 +228,7 @@ public abstract class FindAllQuery<T extends PersistentRecord,R>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // from Query
|
@Override // from Fetcher
|
||||||
public List<T> getCachedResult (PersistenceContext ctx)
|
public List<T> getCachedResult (PersistenceContext ctx)
|
||||||
{
|
{
|
||||||
if (_qkey != null) {
|
if (_qkey != null) {
|
||||||
@@ -238,7 +238,7 @@ public abstract class FindAllQuery<T extends PersistentRecord,R>
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// from Query
|
// from Fetcher
|
||||||
public List<T> invoke (PersistenceContext ctx, Connection conn, DatabaseLiaison liaison)
|
public List<T> invoke (PersistenceContext ctx, Connection conn, DatabaseLiaison liaison)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
@@ -278,13 +278,13 @@ public abstract class FindAllQuery<T extends PersistentRecord,R>
|
|||||||
_marsh = new ProjectionQueryMarshaller<T,R>(cset, _types);
|
_marsh = new ProjectionQueryMarshaller<T,R>(cset, _types);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // from Query
|
@Override // from Fetcher
|
||||||
public List<R> getCachedResult (PersistenceContext ctx)
|
public List<R> getCachedResult (PersistenceContext ctx)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// from Query
|
// from Fetcher
|
||||||
public List<R> invoke (PersistenceContext ctx, Connection conn, DatabaseLiaison liaison)
|
public List<R> invoke (PersistenceContext ctx, Connection conn, DatabaseLiaison liaison)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
@@ -345,7 +345,7 @@ public abstract class FindAllQuery<T extends PersistentRecord,R>
|
|||||||
protected DepotTypes _types;
|
protected DepotTypes _types;
|
||||||
}
|
}
|
||||||
|
|
||||||
// from Query
|
// from Fetcher
|
||||||
public void updateStats (Stats stats)
|
public void updateStats (Stats stats)
|
||||||
{
|
{
|
||||||
stats.noteQuery(_cachedQueries, _uncachedQueries, _explicitQueries,
|
stats.noteQuery(_cachedQueries, _uncachedQueries, _explicitQueries,
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ import static com.samskivert.depot.Log.log;
|
|||||||
/**
|
/**
|
||||||
* The implementation of {@link DepotRepository#load} functionality.
|
* The implementation of {@link DepotRepository#load} functionality.
|
||||||
*/
|
*/
|
||||||
public class FindOneQuery<T extends PersistentRecord> extends Query<T>
|
public class FindOneQuery<T extends PersistentRecord> extends Fetcher<T>
|
||||||
{
|
{
|
||||||
public FindOneQuery (PersistenceContext ctx, Class<T> type,
|
public FindOneQuery (PersistenceContext ctx, Class<T> type,
|
||||||
DepotRepository.CacheStrategy strategy, QueryClause[] clauses)
|
DepotRepository.CacheStrategy strategy, QueryClause[] clauses)
|
||||||
@@ -58,7 +58,7 @@ public class FindOneQuery<T extends PersistentRecord> extends Query<T>
|
|||||||
_builder.newQuery(_select);
|
_builder.newQuery(_select);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // from Query
|
@Override // from Fetcher
|
||||||
public T getCachedResult (PersistenceContext ctx)
|
public T getCachedResult (PersistenceContext ctx)
|
||||||
{
|
{
|
||||||
CacheKey key = getCacheKey();
|
CacheKey key = getCacheKey();
|
||||||
@@ -75,7 +75,7 @@ public class FindOneQuery<T extends PersistentRecord> extends Query<T>
|
|||||||
return cvalue;
|
return cvalue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// from Query
|
// from Fetcher
|
||||||
public T invoke (PersistenceContext ctx, Connection conn, DatabaseLiaison liaison)
|
public T invoke (PersistenceContext ctx, Connection conn, DatabaseLiaison liaison)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user