persistence@glassfish.java.net

Re: Is using Toplink ExpressionBuilder a good choice

From: sonavor <jw_at_worleytown.com>
Date: Thu, 24 Jul 2008 23:35:00 -0700 (PDT)

I was able to solve my ORDER BY issue using the Toplink ExpressionBuilder.
To do that I had to switch from using -
javax.persistence.Query q = (
(oracle.toplink.essentials.ejb.cmp3.EntityManager)
em.getDelegate()).createQuery(exp, Person.class);

To using a Toplink ReadAllQuery -
oracle.toplink.essentials.queryframework.ReadAllQuery readAllQuery = new
ReadAllQuery(Person.class);

Since the ExpressionBuilder, Expression and ReadAllQuery classes are all
from oracle.toplink.essentials I am locking my solution to Toplink.

Anyway, the dynamic query now works great with the ORDER BY that I wanted.

The Expression building part of my code is identical to the previous
posting. It is actually in its own method called
"createAdhocAllPersonQuery". So with my main Expression object named "exp"
built up the change in the query implementation is as shown below -

           Expression exp = createAdhocAllPersonQuery(srchPerson);

            ReadAllQuery readAllQuery = new ReadAllQuery(Person.class);
            readAllQuery.addAscendingOrdering("lastName");
            readAllQuery.addAscendingOrdering("firstName");
            readAllQuery.addAscendingOrdering("midInitial");
            readAllQuery.setSelectionCriteria(exp);
            readAllQuery.prepareForExecution();

            // Session is from oracle.toplink.essentials.sessions.Session;
            Session session = (
(oracle.toplink.essentials.ejb.cmp3.EntityManager)
em.getDelegate()).getActiveSession();
            if (session != null) {
                List<Person> results = (List)
session.executeQuery(readAllQuery);
                if (results != null) {
                    for (Iterator i = results.iterator(); i.hasNext();) {
                        Person p = (Person) i.next();
                        // do stuff with Person object here
                        pList.add(p);
                    }
                }
              }
          

-- 
View this message in context: http://www.nabble.com/Is-using-Toplink-ExpressionBuilder-a-good-choice-tp18645581p18646010.html
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.