Issue Details (XML | Word | Printable)

Key: NUCRDBMS-349
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Unassigned
Reporter: Sudipta
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
DataNucleus Store RDBMS

JDOQL2 : Compiled JDO queries are wrongly getting cached

Created: 23/Mar/10 06:50 PM   Updated: 03/Apr/10 10:44 AM   Resolved: 26/Mar/10 08:25 PM
Component/s: Queries
Affects Version/s: 2.0.2
Fix Version/s: 2.0.3, 2.1.0.m1

File Attachments: 1. Zip Archive query-cache.zip (19 kB)


Severity: Development


 Description  « Hide
Hi,
I am using 2.0.2. I have two jdo queries. The two queries are same but the actual filter parameters are different. When I run those queries I noticed that the first query is fine, but the second query is not replacing the proper value of one of the parameter, instead it is using the value of the parameter from the first query.

This is my Main program:

PersistenceManager pm = pmf.getPersistenceManager();
Query query = pm.newQuery(Event.class);
String filterString = "(timestamp >= timestampStart) && (timestamp <= timestampEnd) && (eventTypeName.eventTypeNameId == 2065)";
filterString += "&& description.matches(descriptionParam)";
query.setFilter(filterString );
String paramDeclaration = "java.util.Date timestampStart, java.util.Date timestampEnd, String descriptionParam";
query.declareParameters(paramDeclaration);
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
HashMap params = new HashMap();
params.put("timestampStart", sdf.parse("03/22/2010 21:21:10"));
params.put("timestampEnd", sdf.parse("03/22/2010 21:21:12"));
params.put("descriptionParam", ".*Device has no running configuration\\..*");
NucleusLogger.QUERY.debug("Executing first query");
Collection events = (Collection)query.executeWithMap(params);
query.closeAll();

Query query1 = pm.newQuery(Event.class);
query1.setFilter(filterString);
query1.declareParameters(paramDeclaration);
HashMap params1 = new HashMap();
params1.put("timestampStart", sdf.parse("03/22/2010 21:21:12"));
params1.put("timestampEnd", sdf.parse("03/22/2010 21:21:15"));
params1.put("descriptionParam", ".*Device has no startup configuration\\..*");
NucleusLogger.QUERY.debug("Executing 2nd query");
Collection events1 = (Collection)query1.executeWithMap(params1);
query1.closeAll();
pm.close();

When I run the above program the first query run fine.
For the 2nd query the timestampStart and timeStampEnd specified in the parameters of the 2nd query is used, but for the parameter descriptionParam (this is used in matches) the value of this parameter specified in the 1st query params is used instead of the one specified in the 2nd query params, which is totally wrong.

The sql for the first query:

SELECT 'foo.Event' AS NUCLEUS_TYPE,a0.current_session_number,a0.description,a0.event_category_name_id,c0.event_category_na
me_id,c0.nme,c0.jdo_version,a0.event_type_name_id,d0.event_type_name_id,d0.nme,d0.jdo_version,a0.rea
lm_name,a0.root_session_number,a0.severity,a0.source_name,a0.target_key,a0.target_name,a0."timestamp",a0.event_id,a0.jdo_version FROM event a0 LEFT OUTER JOIN event_type_name b0 ON a0.event_type_name_id = b0.event_type_name_id LEFT OUTER JOIN event_category_name c0 ON a0.event_category_name_id = c0.event_category_name_id LEFT OUTER JOIN event_type_name d0 ON a0.event_type_name_id = d0.event_type_name_id WHERE a0."timestamp" >= <2010-03-22 21:21:10.0> AND a0."timestamp" <= <2010-03-22 21:21:12.0> AND b0.event_type_name_id = 2065 AND a0.description LIKE '%Device has no running configuration.%' ESCAPE '\\'

The sql for the 2nd query
SELECT 'foo.Event' AS NUCLEUS_TYPE,a0.current_session_number,a0.description,a0.event_category_name_id,c0.event_category_na
me_id,c0.nme,c0.jdo_version,a0.event_type_name_id,d0.event_type_name_id,d0.nme,d0.jdo_version,a0.rea
lm_name,a0.root_session_number,a0.severity,a0.source_name,a0.target_key,a0.target_name,a0."timestamp",a0.event_id,a0.jdo_version FROM event a0 LEFT OUTER JOIN event_type_name b0 ON a0.event_type_name_id = b0.event_type_name_id LEFT OUTER JOIN event_category_name c0 ON a0.event_category_name_id = c0.event_category_name_id LEFT OUTER JOIN event_type_name d0 ON a0.event_type_name_id = d0.event_type_name_id WHERE a0."timestamp" >= <2010-03-22 21:21:12.0> AND a0."timestamp" <= <2010-03-22 21:21:15.0> AND b0.event_type_name_id = 2065 AND a0.description LIKE '%Device has no running configuration.%' ESCAPE '\\'

The proper value for LIKE would be '%Device has no startup configuration.%'

Notice the last like, it is using the value from the first query.
This is a query caching issue.
I think this is the issue:
Since the parameter for matches is directly hardcoded in the query rather that using prepared statement parameters and since the query got wrongly cached during the 1st query execution it did not replace the value of the matches parameter while executing the 2nd query. The other parameters (timestampEnd and timeStampStart) uses prepared statement parameter, so they get substituted properly qhile query execution.

This issue gets solved if I turn off query compilation caching by setting datanucleus.query.compilation.cached=false

Can someone provide me a fix for this.
Thanks
Sudipta


Sudipta added a comment - 23/Mar/10 06:56 PM
The zip file contains the java files, the jdo files and test.properties which is the datanucleus property file.

Sudipta made changes - 23/Mar/10 06:56 PM
Field Original Value New Value
Attachment query-cache.zip [ 11110 ]
Andy Jefferson added a comment - 24/Mar/10 05:55 PM
JDOQL2 is an option in DN 2.0, that's all. The default implementation is what should be used for the majority of things. This almost certainly works in DN 2.1 (see nightly builds 2.1.0-m1-SNAPSHOT) since it passes the JDO2 TCK with that implementation for that release.

Andy Jefferson made changes - 24/Mar/10 05:55 PM
Summary Compiled JDO queries are wrongly getting cached JDOQL2 : Compiled JDO queries are wrongly getting cached
Priority Major [ 3 ] Minor [ 4 ]
Andy Jefferson added a comment - 26/Mar/10 08:25 PM
Assumed to work in 2.1.0.m1

Andy Jefferson made changes - 26/Mar/10 08:25 PM
Status Open [ 1 ] Resolved [ 5 ]
Fix Version/s 2.1.0.m1 [ 10902 ]
Resolution Fixed [ 1 ]
Andy Jefferson added a comment - 30/Mar/10 08:13 AM
Also in SVN branches/2.0 now

Andy Jefferson made changes - 30/Mar/10 08:13 AM
Fix Version/s 2.0.3 [ 10871 ]
Andy Jefferson made changes - 03/Apr/10 10:44 AM
Status Resolved [ 5 ] Closed [ 6 ]