OPENJPA-1577: disable query cache when user-defined field strategy is used.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@924055 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Fay Wang 2010-03-16 23:41:36 +00:00
parent 3b15fe9e2d
commit 41ce320cc0
3 changed files with 43 additions and 1 deletions

View File

@ -27,6 +27,7 @@ import java.util.List;
import java.util.Map;
import org.apache.openjpa.jdbc.meta.ClassMapping;
import org.apache.openjpa.jdbc.meta.FieldMapping;
import org.apache.openjpa.jdbc.meta.MappingRepository;
import org.apache.openjpa.jdbc.schema.Column;
import org.apache.openjpa.jdbc.sql.LogicalUnion;
@ -177,6 +178,10 @@ public class PreparedQueryImpl implements PreparedQuery {
SQLBuffer buffer = selector.getSQL();
if (buffer == null)
return new PreparedQueryCacheImpl.StrongExclusion(_id, _loc.get("exclude-no-sql", _id).getMessage());;
boolean useFieldStrategy = isUsingFieldStrategy();
if (useFieldStrategy)
return new PreparedQueryCacheImpl.StrongExclusion(_id,
_loc.get("exclude-user-strategy", _id).getMessage());;
setTargetQuery(buffer.getSQL());
setParameters(buffer.getParameters());
setUserParameterPositions(buffer.getUserParameters());
@ -254,6 +259,27 @@ public class PreparedQueryImpl implements PreparedQuery {
return false;
}
private boolean isUsingFieldStrategy() {
for (int i = 0; i < _exps.length; i++) {
if (isUsingFieldStrategy(_exps[i])) {
return true;
}
}
return false;
}
private boolean isUsingFieldStrategy(QueryExpressions exp) {
if (exp == null)
return false;
List<FieldMetaData> fmds = exp.getParameterizedFields();
if (fmds == null || fmds.isEmpty())
return false;
for (FieldMetaData fmd : fmds) {
if (((FieldMapping)fmd).getMappingInfo().getStrategy() != null)
return true;
}
return false;
}
/**
* Merge the given user parameters with its own parameter. The given map

View File

@ -167,3 +167,5 @@ 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.
exclude-user-strategy: This query "{0}" is not cached because some parameterized \
field value depends on user-defined field strategy.

View File

@ -21,6 +21,8 @@ package org.apache.openjpa.persistence.jdbc.annotations;
import java.awt.*;
import java.util.Map;
import javax.persistence.Query;
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
import org.apache.openjpa.jdbc.meta.ClassMapping;
import org.apache.openjpa.jdbc.meta.Discriminator;
@ -327,5 +329,17 @@ public class TestNonstandardMappingAnnotations
assertEquals("name1", pc.getName());
assertEquals(1.0, pc.getPoint().getX());
assertEquals(2.0, pc.getPoint().getY());
for (int i = 0; i < 2; i++) {
Query query = em.createQuery("select s from NonstandardMappingEntity4 s where s.point = :point");
query.setParameter("point", new Point(1, 2));
java.util.List<NonstandardMappingEntity4> list = query.getResultList();
for (NonstandardMappingEntity4 pc1 : list) {
assertEquals(1.0, pc1.getPoint().getX());
assertEquals(2.0, pc1.getPoint().getY());
}
em.clear();
}
em.close();
}}