Posts

Showing posts from December, 2020

JDOQL: What is the equivalent of SQL's count(*) in the JDO world?

Displaying large datasets There are often times when you need to display data in a table format and the size of the potential dataset is extremely large and so ends up being represented across many pages and displayed with the usual "previous/next" buttons. Most UI frameworks need to know upfront what is the total count of items you will be displaying so they know how many pages there are and can display some text above the table that says something like: Items 31-40 of 397 Avoiding a big database, memory and CPU hit What you don't want to do is force your JDO ORM (or an ORM using any Java persistence standard e.g. JPA) from instantiating ALL of the objects just so that your UI knows the total count of items to be displayed. To do this you need to perform some kind of 'count' query. In JDO this is done by setting the result set to 'count' but count needs a parameter. e.g. PersistenceManager pm = getPm(); Query q = pm.newQuery(MyClass.class);          /