134 Queries with JDOQL Query compilation is generally
Query examples 135 8.4.1 Query without filter Our first example is a query that lists all instances of the BusinessPartner class. I have presented this as a small application with a main() method which can be run from the command line, although future query examples will be shown as code snippets. SimpleQuery.Java package com.ogilviepartners.jdobook.app; import java.util.Collection; import java.util.Iterator; import javax.jdo.*; public class SimpleQuery { public static void main() { JDOBootstrap bootstrap = new JDOBootstrap(); PersistenceManagerFactory pmf = bootstrap.getPersistenceManagerFactory(); PersistenceManager pm = pmf.getPersistenceManager(); Transaction t = pm.currentTransaction(); t.begin(); Extent partnerExt = pm.getExtent( BusinessPartner.class, true); Query q = pm.newQuery(partnerExt); Collection c = (Collection) q.execute(); Iterator i = c.iterator(); System.out.println( “Listing all BusinessPartner instances:”); while(i.hasNext()) { Object o = i.next(); System.out.println(o); } System.out.println(”Done.”); q.close(c); t.commit(); } } The above example is indeed very simple. There is no filter defined, nor are there any parameter, variable, import, or ordering declarations. The candidate
Hint: This post is supported by Gama web hosting hrvatska services