Better diagnostic messages on why a query can not be cached

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@923940 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Pinaki Poddar 2010-03-16 19:10:49 +00:00
parent 8dc74c1e59
commit 0f5508e680
2 changed files with 26 additions and 22 deletions

View File

@ -170,13 +170,13 @@ public class PreparedQueryImpl implements PreparedQuery {
if (selector == null || selector.hasMultipleSelects()
|| ((selector instanceof Union)
&& (((Union)selector).getSelects().length != 1)))
return new PreparedQueryCacheImpl.StrongExclusion(_id, _loc.get("exclude-multi-select").getMessage());
return new PreparedQueryCacheImpl.StrongExclusion(_id, _loc.get("exclude-multi-select", _id).getMessage());
select = extractImplementation(selector);
if (select == null)
return new PreparedQueryCacheImpl.StrongExclusion(_id, _loc.get("exclude-no-select").getMessage());
return new PreparedQueryCacheImpl.StrongExclusion(_id, _loc.get("exclude-no-select", _id).getMessage());
SQLBuffer buffer = selector.getSQL();
if (buffer == null)
return new PreparedQueryCacheImpl.StrongExclusion(_id, _loc.get("exclude-no-sql").getMessage());;
return new PreparedQueryCacheImpl.StrongExclusion(_id, _loc.get("exclude-no-sql", _id).getMessage());;
setTargetQuery(buffer.getSQL());
setParameters(buffer.getParameters());
setUserParameterPositions(buffer.getUserParameters());
@ -194,18 +194,18 @@ public class PreparedQueryImpl implements PreparedQuery {
*/
private Object[] extractSelectExecutor(Object result) {
if (result instanceof ResultList == false)
return new Object[]{null, _loc.get("exclude-not-result")};
return new Object[]{null, _loc.get("exclude-not-result", _id)};
Object userObject = ((ResultList<?>)result).getUserObject();
if (userObject == null || !userObject.getClass().isArray() || ((Object[])userObject).length != 2)
return new Object[]{null, _loc.get("exclude-no-user-object")};
return new Object[]{null, _loc.get("exclude-no-user-object", _id)};
Object provider = ((Object[])userObject)[0];
Object executor = ((Object[])userObject)[1];
if (executor instanceof StoreQuery.Executor == false)
return new Object[]{null, _loc.get("exclude-not-executor")};
return new Object[]{null, _loc.get("exclude-not-executor", _id)};
_exps = ((StoreQuery.Executor)executor).getQueryExpressions();
for (int i = 0; i < _exps.length; i++) {
if (isUsingExternalizedParameter(_exps[i])) {
return new Object[]{null, _loc.get("exclude-externalized-param", provider.getClass().getName())};
return new Object[]{null, _loc.get("exclude-externalized-param", _id)};
}
}
if (_exps[0].projections.length == 0) {
@ -225,7 +225,7 @@ public class PreparedQueryImpl implements PreparedQuery {
if (provider instanceof SelectResultObjectProvider) {
return new Object[]{((SelectResultObjectProvider)provider).getSelect(), null};
}
return new Object[]{null, _loc.get("exclude-not-select-rop", provider.getClass().getName())};
return new Object[]{null, _loc.get("exclude-not-select-rop", _id, provider.getClass().getName())};
}
private SelectImpl extractImplementation(SelectExecutor selector) {

View File

@ -149,17 +149,21 @@ bad-lrs-size: Invalid LRS size. Valid values are \
"unknown"(0), "last"(1) or "query"(2). Specified value: {0}.
bad-join-syntax: Invalid join syntax. Valid values are \
"sql92"(0), "tradition"(1) or "database"(2). Specified value: {0}.
exclude-multi-select: This query generates multiple SQL statements. \
A query can be cached only when it corresponds to a single SQL statement.
exclude-not-result: This query returns a single value rather than \
a list. A query that returns single value can not be cached.
exclude-no-user-object: Post-execution data can not be extracted \
from this query.
exclude-no-sql: Target SQL statement can not be extracted \
from this query.
exclude-no-select: Internal select instance can not be extracted \
from this query.
exclude-not-select-rop: The query result is not obtained by executing \
a select statement. This can happen if the query was evaluated in-memory. \
The result was provided by an instance of {0}.
exclude-not-executor: This query was not executed on a data store.
exclude-multi-select: Query "{0}" is not cached because it generates multiple \
SQL statements. A query can be cached only when it corresponds to a single \
SQL statement.
exclude-not-result: Query "{0}" is not cached because it returns a single value \
rather than a list. A query that returns single value can not be cached.
exclude-no-user-object: Query "{0}" is not cached because post-execution data \
can not be extracted from this query.
exclude-no-sql: Query "{0}" is not cached because SQL statement can not be \
extracted from this query.
exclude-no-select: Query "{0}" is not cached because the internal select \
can not be extracted from this query.
exclude-not-select-rop: Query "{0}" is not cached because its result \
is not obtained by executing a select statement. This can happen \
if the query was evaluated in-memory. The result was provided by {1}.
exclude-not-executor: Query "{0}" is not cached because it was not executed on a \
data store.
exclude-externalized-param: Query "{0}" is not cached because some parameterized \
field values are externalized.