Java Reference
In-Depth Information
Deleting Entities
Deleting an entity is relatively straightforward. Call the PersistenceManager's
deletePersistent method with the object to delete. You can also delete multiple
objects by calling the PersistenceManager's deletePersistentAll method with the
Collection of objects. The delete action can also cascade down to any child objects,
which can be deleted as well.
public void deleteOrder(Order order) {
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
Order o = pm.getObjectById(Order.class, order.getId());
} finally {
Performing Queries with JDOQL
Now that you can perform basic CRUD functions, you'll need to be able to find
entities that you'd like to take action on. JDO includes a SQL-like query language
called JDOQL that performs queries for entities that meet specific sets of criteria. A
JDOQL query specifies the entity kind to query, zero or more conditions or “filters” on
entity properties, and zero or more sort-order descriptions. JDOQL also performs
type checking for results and query parameters to make life easier.
The query API is very accommodating and allows you to mix and match your
JDOQL query string to suit your preferences. You can write your entire JDOQL query
as a single string or construct all or some of the query by calling methods on the
query object with filters and parameter substitutions in the order in which they are
declared. Literal values are also supported for string and numeric values.
Here is a simple query constructed with the JDOQL string syntax:
import java.util.List;
import javax.jdo.Query;
Query qry = pm.newQuery("select from Contact where country == countryParam
" +
"order by dateCreated desc " +
"parameters String countryParam");
List<Contact> contacts = (List<Contact>) qry.execute("USA");
Search WWH ::

Custom Search