KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > store > test > TestStore


1 /*
2  * Created on 17.10.2004
3  */

4 package com.nightlabs.ipanema.store.test;
5
6 import java.io.FileNotFoundException JavaDoc;
7 import java.io.IOException JavaDoc;
8 import java.io.InputStream JavaDoc;
9 import java.util.Properties JavaDoc;
10
11 import javax.jdo.JDOHelper;
12 import javax.jdo.PersistenceManager;
13 import javax.jdo.PersistenceManagerFactory;
14
15 import com.nightlabs.inheritance.InheritenceManager;
16 import com.nightlabs.ipanema.store.Product;
17 import com.nightlabs.ipanema.store.id.ProductID;
18
19 /**
20  * @author Marco Schulze - marco at nightlabs dot de
21  */

22 public class TestStore
23 {
24     private static PersistenceManager createPersistenceManager()
25     throws IOException JavaDoc
26     {
27         Properties JavaDoc properties = new Properties JavaDoc();
28
29         InputStream JavaDoc is = TestStore.class.getResourceAsStream("jpox.properties");
30         try {
31             if (is == null)
32                 throw new FileNotFoundException JavaDoc("Could not find \"jpox.properties\"!");
33             properties.load(is);
34         } finally {
35             if (is != null)
36                 is.close();
37         }
38
39         PersistenceManagerFactory pmfactory = JDOHelper.getPersistenceManagerFactory(properties);
40         PersistenceManager pm = pmfactory.getPersistenceManager();
41
42         return pm;
43     }
44
45     public static final String JavaDoc ORGANISATIONID = "schulze.nightlabs.de";
46
47     public void test() throws Exception JavaDoc
48     {
49         PersistenceManager pm = createPersistenceManager();
50         try {
51             pm.currentTransaction().begin();
52             try {
53                 Container container = new Container(ORGANISATIONID, "container", null, Product.NATURE_TYPE);
54                 pm.makePersistent(container);
55
56                 Container bottle = new Container(ORGANISATIONID, "bottle", container, Product.NATURE_TYPE);
57                 pm.makePersistent(bottle);
58
59                 container.setColor("green");
60                 container.setHeight(500);
61                 container.setWidth(200);
62
63 // container.setProperty("testProperty00", "testValue00");
64

65                 bottle.setColor("red");
66
67                 container.setColor("blue");
68
69 // InheritenceManager im = new InheritenceManager();
70
// try {
71
// im.inheritAllFields(container, bottle);
72
// } catch (Exception x) {
73
// x.printStackTrace();
74
// throw x;
75
// }
76

77                 pm.currentTransaction().commit();
78             } finally {
79                 if (pm.currentTransaction().isActive())
80                     pm.currentTransaction().rollback();
81             }
82         } finally {
83             pm.close();
84         }
85
86
87         pm = createPersistenceManager();
88         try {
89             pm.currentTransaction().begin();
90             try {
91                 Container container = (Container)pm.getObjectById(ProductID.create(ORGANISATIONID, "container"), true);
92                 Container bottle = (Container)pm.getObjectById(ProductID.create(ORGANISATIONID, "bottle"), true);
93
94 // container.setColor("green");
95
// container.setHeight(500);
96
// container.setWidth(200);
97
//
98
// container.setProperty("testProperty00", "testValue00");
99
//
100
// bottle.setColor("red");
101
//
102
// container.setColor("blue");
103

104                 InheritenceManager im = new InheritenceManager();
105                 try {
106                     im.inheritAllFields(container, bottle);
107                 } catch (Exception JavaDoc x) {
108                     x.printStackTrace();
109                     throw x;
110                 }
111
112                 pm.currentTransaction().commit();
113             } finally {
114                 if (pm.currentTransaction().isActive())
115                     pm.currentTransaction().rollback();
116             }
117         } finally {
118             pm.close();
119         }
120     }
121
122     public static void main(String JavaDoc[] args)
123     {
124         try {
125             TestStore test = new TestStore();
126             test.test();
127         } catch (Exception JavaDoc e) {
128             e.printStackTrace();
129         }
130     }
131 }
132
Popular Tags