KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > animals > Story


1 package animals;
2
3 import org.objectweb.speedo.runtime.SpeedoPersistenceManagerFactory;
4 import org.objectweb.speedo.api.ExceptionHelper;
5
6 import java.io.FileInputStream JavaDoc;
7 import java.util.Properties JavaDoc;
8
9 public class Story {
10
11     javax.jdo.PersistenceManagerFactory pmf;
12
13     public static void main(String JavaDoc args[]) {
14         Story story = new Story();
15         story.initPersitency(args);
16         try {
17             story.run();
18         } catch (Exception JavaDoc e) {
19             ExceptionHelper.getNested(e).printStackTrace();
20             System.exit(-1);
21         }
22     }
23
24     public void initPersitency(String JavaDoc[] args) {
25         try {
26             Properties JavaDoc p = new Properties JavaDoc();
27             p.load(new FileInputStream JavaDoc(args[0]));
28             p.setProperty("log.config.file", args[1]);
29             pmf = new SpeedoPersistenceManagerFactory();
30             //((SpeedoPersistenceManagerFactory) pmf).init(p);
31
} catch (Exception JavaDoc e) {
32             ExceptionHelper.getNested(e).printStackTrace();
33             System.exit(-1);
34         }
35     }
36
37     public void run() throws Exception JavaDoc {
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
57 }
58
Popular Tags