Java Reference
In-Depth Information
transaction = pm.currentTransaction();
// make all of the objects in the graph persistent
pm.makePersistentAll(yachts);
transaction.commit();
// retrieve object ids for the persisted objects
for(int i = 0; i < yachts.length; i++) {
id.add(pm.getObjectId(yachts[i]));
System.out.println("Object id is: " + id.elementAt(i));
}
// close current PM to ensure that objects are read from the datastore
// rather than the PM's memory cache.
pm.close();
}
/** Display the persisted objects' state on standard output */
public void display(int endIndex) {
Yacht aYacht;
int max = endIndex <= SIZE ? endIndex : SIZE;
System.out.println("\n------------------------------------------------
---------
");
System.out.println(" Display: Persisted Yachts");
System.out.println("--------------------------------------------------
-------");
// get a new PM
pm = pmf.getPersistenceManager();
// retrieve objects from datastore and display their state
for(int i = 0; i < max; i++) {
aYacht = (Yacht)pm.getObjectById(id.elementAt(i), false);
System.out.println("------------ " + i + " ------------");
System.out.println("YachtName : " + aYacht.getYachtName());
System.out.println("Builder : " + aYacht.getBuilder());
System.out.println("Engine Type : " + aYacht.getEngineType());
System.out.println("Capacity : " + aYacht.getCapacity());
System.out.println("Max Velocity: " + aYacht.getMaxVelocity());
System.out.println("-------------------------------");
}
pm.close();
}
/** Change a Yacht's name and make the change persistent */
public void change() {
Yacht aYacht;
// get a PM and set transaction
Search WWH ::




Custom Search