01: /**
02: * Copyright (C) 2001-2006 France Telecom R&D
03: */package secondarytable;
04:
05: import org.objectweb.util.monolog.api.BasicLevel;
06:
07: import java.util.ArrayList;
08: import java.util.Collection;
09: import java.util.Iterator;
10: import java.util.List;
11:
12: import javax.jdo.PersistenceManager;
13: import javax.jdo.Query;
14:
15: import common.MainHelper;
16:
17: public class Main extends MainHelper {
18:
19: public static void main(String[] args) {
20: new Main().init(args).run().end();
21: }
22:
23: public MainHelper run() {
24: final int size = 5;
25: List as = getData(size);
26: logger.log(BasicLevel.INFO, "Create " + size
27: + "' multi table addresses :" + as);
28: PersistenceManager pm = pmf.getPersistenceManager();
29: pm.currentTransaction().begin();
30: pm.makePersistentAll(as);
31: pm.currentTransaction().commit();
32:
33: logger.log(BasicLevel.INFO, "Empty Cache.");
34: as = null;
35: pm.evictAll();
36:
37: pm.currentTransaction().begin();
38: logger.log(BasicLevel.INFO, "Find all multi table addresses.");
39: Query q = pm.newQuery(Address.class);
40: Collection c = (Collection) q.execute();
41: for (Iterator it = c.iterator(); it.hasNext();) {
42: Address a = (Address) it.next();
43: logger.log(BasicLevel.INFO, "- Address found:"
44: + a.toString());
45: }
46: as = new ArrayList(c);
47: q.closeAll();
48: pm.currentTransaction().commit();
49:
50: pm.currentTransaction().begin();
51: logger.log(BasicLevel.INFO, "Delete " + as.size()
52: + " multi table addresses.");
53: pm.deletePersistentAll(as);
54: pm.currentTransaction().commit();
55: pm.close();
56: return this ;
57: }
58:
59: private List getData(final int size) {
60: List as = new ArrayList(size);
61: for (int i = 0; i < size; i++) {
62: Address a = new Address();
63: a.setCity("city_" + i);
64: a.setDeliveryInstructions("deliv_" + i);
65: byte[] map = new byte[20 * (i + 1)];
66: for (int j = 0; j < map.length; j++) {
67: map[j] = (byte) i;
68: }
69: a.setMapJPG(map);
70: a.setSignatureRequired(i % 2 == 1);
71: a.setState("state_" + i);
72: a.setStreet("street_" + i);
73: a.setZip("zip_" + i);
74: as.add(a);
75: }
76: return as;
77: }
78: }
|