FileDocCategorySizeDatePackage
SerialDemoJDO.javaAPI DocExample1400Sun Mar 07 08:42:32 GMT 2004None

SerialDemoJDO

public class SerialDemoJDO extends SerialDemoAbstractBase
A demonstration of serialization using JDO. JDO is normally used to access a database, but can also be used to save locally, which is shown here.

Fields Summary
Constructors Summary
Methods Summary
public voiddump()

		PersistenceManager pm = getPM();
		Object[] data = new Object[3];
		pm.retrieveAll(data);
		for (int i = 0; i < data.length; i++) {
			System.out.println(data[i]);
		}
		pm.close();
	
public javax.jdo.PersistenceManagergetPM()

		Properties p = new Properties();
		try {
			p.load(new FileInputStream("jdo.properties"));
			PersistenceManagerFactory pmf = 
				JDOHelper.getPersistenceManagerFactory(p);
			return pmf.getPersistenceManager();
		} catch (IOException ex) {
			throw new RuntimeException(ex.toString());
		}
	
public static voidmain(java.lang.String[] args)

		SerialDemoJDO jd = new SerialDemoJDO();
		jd.save();
		jd.dump();
	
public voidwrite(java.lang.Object o)

		PersistenceManager pm = getPM();
		pm.currentTransaction().begin();
		if (o instanceof Collection) {
			pm.makePersistentAll((Collection)o);
		} else {
			pm.makePersistent(o);
		}
		pm.currentTransaction().commit();
		pm.close();