01: package animals;
02:
03: import org.objectweb.speedo.runtime.SpeedoPersistenceManagerFactory;
04: import org.objectweb.speedo.api.ExceptionHelper;
05:
06: import java.io.FileInputStream;
07: import java.util.Properties;
08:
09: public class Story {
10:
11: javax.jdo.PersistenceManagerFactory pmf;
12:
13: public static void main(String args[]) {
14: Story story = new Story();
15: story.initPersitency(args);
16: try {
17: story.run();
18: } catch (Exception e) {
19: ExceptionHelper.getNested(e).printStackTrace();
20: System.exit(-1);
21: }
22: }
23:
24: public void initPersitency(String[] args) {
25: try {
26: Properties p = new Properties();
27: p.load(new FileInputStream(args[0]));
28: p.setProperty("log.config.file", args[1]);
29: pmf = new SpeedoPersistenceManagerFactory();
30: //((SpeedoPersistenceManagerFactory) pmf).init(p);
31: } catch (Exception e) {
32: ExceptionHelper.getNested(e).printStackTrace();
33: System.exit(-1);
34: }
35: }
36:
37: public void run() throws Exception {
38: javax.jdo.PersistenceManager pm = pmf.getPersistenceManager();
39: javax.jdo.Transaction utx = pm.currentTransaction();
40: utx.begin();
41:
42: //---- A Story ---//
43:
44: Cat felix = new Cat("felix");
45: Dog rex = new Dog("rex", 0);
46: rex.owner = "James";
47: rex.attack(felix.name);
48: pm.makePersistent(felix);
49: //System.out.println("The enemey of the cat " + felix.name + " is " + felix.enemy);
50: //----------------//
51:
52: utx.commit();
53: pm.close();
54: }
55:
56: }
|