You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by AMELIN Franck <f....@consult.fr> on 2003/01/10 14:58:22 UTC
about JDO query filter
Hi all,
Here is a sample code using org.apache.ojb.tutorial5.Product class.
javax.jdo.PersistenceManagerFactory factory = new org.apache.ojb.jdori.sql.OjbStorePMF();
javax.jdo.PersistenceManager manager = factory.getPersistenceManager();
manager.currentTransaction().begin();
javax.jdo.Query query = manager.newQuery(Product.class);
query.setFilter("stock < 30000");
java.util.Collection allProducts = (java.util.Collection)query.execute();
java.util.Iterator iter = allProducts.iterator();
if (! iter.hasNext())
{
System.out.println("No Product entries found!");
}
while (iter.hasNext())
{
System.out.println(iter.next());
}
manager.currentTransaction().commit();
It works but if my table is very big (30 000 enr.) it's very long
because the executed query is "SELECT A0.STOCK,A0.PRICE,A0.NAME,A0.ID FROM PRODUCT A0"
This code construct all object Product instances and then apply my filter on the object collection.
Is there a way to have the same result but with the sql query :
"SELECT A0.STOCK,A0.PRICE,A0.NAME,A0.ID FROM PRODUCT A0 WHERE STOCK < 30000"
Regards,
Franck