8.6. Further examples

Now that you know a bit more about JDOQL’s capabilities and syntax, let’s look at some slightly more complicated examples.

8.6.1. Parameterization

Our previous example employed the simple JDOQL filter

name == "Ogilvie Partners" 

Now we’ll add parameterization. The test will no longer be against the string literal “Ogilvie Partners,” but against an incoming string parameter.

Extent partnerExt = pm.getExtent(BusinessPartner.class, true); 
String filter = "name == searchName"; 
Query q = pm.newQuery(partnerExt, filter); 
q.declareParameters("String searchName"); 
q.setOrdering("name ascending, partnerId descending"); 
Collection c = (Collection) q.execute("Ogilvie Partners");
					

The filter has been changed, so that name is compared ...

Get Java™ Data Objects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.