I
- The implementation class which extends QueryBuilder
. This
is set explicitly in the declaration of the implementation class,
and allows the superclass to provide concrete implementations of
methods reusable by the descendants.R
- The return type of the execute()
method, which
corresponds to a method in ContentResolver
.public abstract class QueryBuilder<I extends QueryBuilder,R>
extends java.lang.Object
ContentResolver
query using builder-style methods, rather
than the standard methods, which use long lists of often-null parameters.
This class is supposed to do very little; the consumer should use the
static methods insertInto(android.content.ContentResolver, android.net.Uri)
, update()
, selectFrom(android.content.ContentResolver, android.net.Uri)
, and
deleteFrom(android.content.ContentResolver, android.net.Uri)
to spawn instances of the various implementation classes
corresponding to query actions.
Modifier and Type | Class and Description |
---|---|
static class |
QueryBuilder.ExecutionException
Exception thrown by
execute() and executeOn(android.content.ContentResolver, android.net.Uri) when the
underlying ContentResolver query operation fails. |
static class |
QueryBuilder.UnboundException
Informs a consumer of
QueryBuilder that it has tried to invoke
the execute() method without first binding to a data
source. |
Modifier and Type | Field and Description |
---|---|
protected java.lang.String[] |
m_asExplicitWhereParams
A substitute, explicit list of "where" parameters, to fit the format
string stored in
m_sExplicitWhereFormat . |
protected android.content.ContentResolver |
m_rslv
The
ContentResolver to which the builder is bound. |
protected java.lang.String |
m_sExplicitWhereFormat
A substitute, explicit "where" format string, for which
m_asExplicitWhereParams provides the values. |
protected android.net.Uri |
m_uri
The
Uri to be supplied to the ContentResolver . |
protected android.content.ContentValues |
m_valsToWrite
For "insert" and "update" operations, these are the values to be written.
|
Constructor and Description |
---|
QueryBuilder()
The default constructor; does not bind to a particular data source.
|
QueryBuilder(android.content.ContentResolver rslv,
android.net.Uri uri)
A shared constructor which binds the builder to a specific resolver and
URI.
|
QueryBuilder(android.content.Context ctx,
android.net.Uri uri)
A shared constructor which binds the builder to a the resolver found in
the given context, and the specified URI.
|
Modifier and Type | Method and Description |
---|---|
static DeletionBuilder |
delete()
Kicks off construction of a deletion query.
|
static DeletionBuilder |
deleteFrom(android.content.ContentResolver rslv,
android.net.Uri uri)
Kicks off construction of a deletion query.
|
static DeletionBuilder |
deleteFrom(android.content.Context ctx,
android.net.Uri uri)
Kicks off construction of a deletion query.
|
R |
execute()
Executes the query that has been built by the implementation class, using
the
ContentResolver and Uri to which the builder has been
bound, either by the constructor, or by an invocation of
onDataSource(android.content.ContentResolver, android.net.Uri) . |
R |
executeOn(android.content.ContentResolver rslv,
android.net.Uri uri)
Executes the query that has been built by the implementation class, using
the supplied
ContentResolver and Uri . |
R |
executeOn(android.content.Context ctx,
android.net.Uri uri)
Executes the query that has been built by the implementation class, using
the
ContentResolver provided by the specified Context ,
and the specified Uri . |
protected abstract R |
executeQuery(android.content.ContentResolver rslv,
android.net.Uri uri)
Consumed by
execute() and executeOn(android.content.ContentResolver, android.net.Uri) to actually carry out
the operation. |
protected static android.content.ContentResolver |
getContentResolver(android.content.Context ctx)
Obtains a
ContentResolver from the specified context, throwing an
exception if that context is null. |
protected java.lang.String |
getWhereFormat()
Creates the Android "where" clause format string to be passed to a
ContentResolver query method. |
protected java.lang.String[] |
getWhereParams()
Creates the array of "where" clause value substitutions to be passed to a
ContentResolver query method. |
static InsertionBuilder |
insert()
Kicks off construction of an insertion query.
|
static InsertionBuilder |
insertInto(android.content.ContentResolver rslv,
android.net.Uri uri)
Kicks off construction of an insertion query.
|
static InsertionBuilder |
insertInto(android.content.Context ctx,
android.net.Uri uri)
Kicks off construction of an insertion query.
|
I |
onDataSource(android.content.ContentResolver rslv,
android.net.Uri uri)
Binds the builder to a specific data context, to be used by the execution
methods.
|
I |
onDataSource(android.content.Context ctx,
android.net.Uri uri)
Binds the builder to a specific data context, to be used by the execution
methods.
|
static SelectionBuilder |
select()
Kicks off construction of a selection query.
|
static SelectionBuilder |
selectFrom(android.content.ContentResolver rslv,
android.net.Uri uri)
Kicks off construction of a selection query.
|
static SelectionBuilder |
selectFrom(android.content.Context ctx,
android.net.Uri uri)
Kicks off construction of a selection query.
|
I |
setValues(android.content.ContentValues vals)
Sets values to be written as part of an "insert" or "update" operation,
if applicable.
|
static UpdateBuilder |
update()
Kicks off construction of an update query.
|
static UpdateBuilder |
update(android.content.ContentResolver rslv,
android.net.Uri uri)
Kicks off construction of an update query.
|
static UpdateBuilder |
update(android.content.Context ctx,
android.net.Uri uri)
Kicks off construction of an update query.
|
protected static void |
validateDataContextBinding(android.content.ContentResolver rslv,
android.net.Uri uri)
Ensures that the specified
ContentResolver and Uri are
non-null and usable as a data context. |
I |
where(java.lang.String sWhereClause)
Constructs an explicit "where" clause for a query.
|
I |
where(java.lang.String sWhereFormat,
java.util.Collection<java.lang.String> asWhereParams)
Sets the "where" clause format and values for a query.
|
I |
where(java.lang.String sWhereFormat,
java.lang.String... asWhereParams)
Sets the "where" clause format and values for a query.
|
protected android.content.ContentResolver m_rslv
ContentResolver
to which the builder is bound.protected android.net.Uri m_uri
Uri
to be supplied to the ContentResolver
.protected android.content.ContentValues m_valsToWrite
protected java.lang.String m_sExplicitWhereFormat
m_asExplicitWhereParams
provides the values.protected java.lang.String[] m_asExplicitWhereParams
m_sExplicitWhereFormat
.public QueryBuilder()
public QueryBuilder(android.content.Context ctx, android.net.Uri uri) throws QueryBuilder.UnboundException
ctx
- a context which can provide a ContentResolver
uri
- the URI at which the query should be executedQueryBuilder.UnboundException
- if either parameter is unusablepublic QueryBuilder(android.content.ContentResolver rslv, android.net.Uri uri) throws QueryBuilder.UnboundException
rslv
- the resolver through which the query should be executeduri
- the URI at which the query should be executedQueryBuilder.UnboundException
- if either parameter is unusablepublic static InsertionBuilder insert()
onDataSource(android.content.ContentResolver, android.net.Uri)
, or use executeOn(android.content.ContentResolver, android.net.Uri)
instead of
execute()
.public static InsertionBuilder insertInto(android.content.ContentResolver rslv, android.net.Uri uri) throws QueryBuilder.UnboundException
rslv
- the resolver through which the query should be executeduri
- the URI at which the query should be executedQueryBuilder.UnboundException
- if the data context is unusablepublic static InsertionBuilder insertInto(android.content.Context ctx, android.net.Uri uri) throws QueryBuilder.UnboundException
ctx
- a context which can provide a ContentResolver
uri
- the URI at which the query should be executedQueryBuilder.UnboundException
- if the data context is unusablepublic static UpdateBuilder update()
onDataSource(android.content.ContentResolver, android.net.Uri)
, or use executeOn(android.content.ContentResolver, android.net.Uri)
instead of
execute()
.public static UpdateBuilder update(android.content.ContentResolver rslv, android.net.Uri uri) throws QueryBuilder.UnboundException
rslv
- the resolver through which the query should be executeduri
- the URI at which the query should be executedQueryBuilder.UnboundException
- if the data context is unusablepublic static UpdateBuilder update(android.content.Context ctx, android.net.Uri uri) throws QueryBuilder.UnboundException
ctx
- a context which can provide a ContentResolver
uri
- the URI at which the query should be executedQueryBuilder.UnboundException
- if the data context is unusablepublic static SelectionBuilder select()
onDataSource(android.content.ContentResolver, android.net.Uri)
, or use executeOn(android.content.ContentResolver, android.net.Uri)
instead of
execute()
.public static SelectionBuilder selectFrom(android.content.ContentResolver rslv, android.net.Uri uri) throws QueryBuilder.UnboundException
rslv
- the resolver through which the query should be executeduri
- the URI at which the query should be executedQueryBuilder.UnboundException
- if the data context is unusablepublic static SelectionBuilder selectFrom(android.content.Context ctx, android.net.Uri uri) throws QueryBuilder.UnboundException
ctx
- a context which can provide a ContentResolver
uri
- the URI at which the query should be executedQueryBuilder.UnboundException
- if the data context is unusablepublic static DeletionBuilder delete()
onDataSource(android.content.ContentResolver, android.net.Uri)
, or use executeOn(android.content.ContentResolver, android.net.Uri)
instead of
execute()
.public static DeletionBuilder deleteFrom(android.content.ContentResolver rslv, android.net.Uri uri) throws QueryBuilder.UnboundException
rslv
- the resolver through which the query should be executeduri
- the URI at which the query should be executedQueryBuilder.UnboundException
- if the data context is unusablepublic static DeletionBuilder deleteFrom(android.content.Context ctx, android.net.Uri uri) throws QueryBuilder.UnboundException
ctx
- a context which can provide a ContentResolver
uri
- the URI at which the query should be executedQueryBuilder.UnboundException
- if the data context is unusableprotected static android.content.ContentResolver getContentResolver(android.content.Context ctx) throws QueryBuilder.UnboundException
ContentResolver
from the specified context, throwing an
exception if that context is null.ctx
- a context which can provide a content resolver.QueryBuilder.UnboundException
- if the context is nullprotected static void validateDataContextBinding(android.content.ContentResolver rslv, android.net.Uri uri) throws QueryBuilder.UnboundException
ContentResolver
and Uri
are
non-null and usable as a data context.QueryBuilder.ExecutionException
- if any problems occurQueryBuilder.UnboundException
public I onDataSource(android.content.ContentResolver rslv, android.net.Uri uri) throws QueryBuilder.UnboundException
rslv
- the resolver through which the query should be executeduri
- the URI at which the query should be executedQueryBuilder.UnboundException
- if either parameter is unusablepublic I onDataSource(android.content.Context ctx, android.net.Uri uri) throws QueryBuilder.UnboundException
ctx
- a context which can provide a ContentResolver
uri
- the URI at which the query should be executedQueryBuilder.UnboundException
- if either parameter is unusablepublic I setValues(android.content.ContentValues vals)
vals
- the values to be writtenpublic I where(java.lang.String sWhereClause)
The supplied string is used as-is in the underlying
ContentResolver
query function, and should contain only necessary
columns with literal values (no variable substitutions). Based on this
restriction, the collection of variable substitution sources will be set
as null
.
sWhereClause
- the explicit "where" clause, containing only literal
valuespublic I where(java.lang.String sWhereFormat, java.lang.String... asWhereParams)
sWhereFormat
- the format string of the "where" clause, which must
use ?
for parameter substitutionasWhereParams
- the parameters for the "where" clause, assigned to
substitution markers in the format stringContentUtils.QUERY_VARIABLE_MARKER
public I where(java.lang.String sWhereFormat, java.util.Collection<java.lang.String> asWhereParams)
sWhereFormat
- the format string of the "where" clause, which must
use ?
for parameter substitutionasWhereParams
- the parameters for the "where" clause, assigned to
substitution markers in the format stringContentUtils.QUERY_VARIABLE_MARKER
protected java.lang.String getWhereFormat()
ContentResolver
query method.protected java.lang.String[] getWhereParams()
ContentResolver
query method.public final R execute() throws QueryBuilder.UnboundException, QueryBuilder.ExecutionException
ContentResolver
and Uri
to which the builder has been
bound, either by the constructor, or by an invocation of
onDataSource(android.content.ContentResolver, android.net.Uri)
.QueryBuilder.UnboundException
QueryBuilder.ExecutionException
public final R executeOn(android.content.ContentResolver rslv, android.net.Uri uri) throws QueryBuilder.UnboundException, QueryBuilder.ExecutionException
ContentResolver
and Uri
. Usually, this is
not invoked directly, but is instead consumed by execute()
.rslv
- the resolver through which the query should be executeduri
- the URI at which the query should be executedQueryBuilder.UnboundException
- if the data context binding is inadequateQueryBuilder.ExecutionException
- if the underlying query failspublic final R executeOn(android.content.Context ctx, android.net.Uri uri) throws QueryBuilder.UnboundException, QueryBuilder.ExecutionException
ContentResolver
provided by the specified Context
,
and the specified Uri
.ctx
- a context which can provide a ContentResolver
uri
- the URI at which the query should be executedQueryBuilder.UnboundException
- if the data context binding is inadequateQueryBuilder.ExecutionException
- if the underlying query failsprotected abstract R executeQuery(android.content.ContentResolver rslv, android.net.Uri uri) throws java.lang.Exception
execute()
and executeOn(android.content.ContentResolver, android.net.Uri)
to actually carry out
the operation. In the implementation class, this method should consist
solely of the ContentResolver
query method call, plus any other
pre-checks which might be able to short-circuit the query execution.rslv
- the resolver through which the query should be executeduri
- the URI at which the query should be executedjava.lang.Exception
- if anything goes wrong