01: /*
02: This file is part of the PolePosition database benchmark
03: http://www.polepos.org
04:
05: This program is free software; you can redistribute it and/or
06: modify it under the terms of the GNU General Public License
07: as published by the Free Software Foundation; either version 2
08: of the License, or (at your option) any later version.
09:
10: This program is distributed in the hope that it will be useful,
11: but WITHOUT ANY WARRANTY; without even the implied warranty of
12: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: GNU General Public License for more details.
14:
15: You should have received a copy of the GNU General Public
16: License along with this program; if not, write to the Free
17: Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18: MA 02111-1307, USA. */
19:
20: package org.polepos.teams.jdo;
21:
22: import java.util.*;
23:
24: import javax.jdo.*;
25:
26: import org.polepos.framework.*;
27:
28: /**
29: * @author Herkules
30: */
31: public abstract class JdoDriver extends Driver {
32:
33: private transient PersistenceManager mPersistenceManager;
34:
35: public void takeSeatIn(Car car, TurnSetup setup)
36: throws CarMotorFailureException {
37: super .takeSeatIn(car, setup);
38: prepare();
39: }
40:
41: public void prepare() {
42: mPersistenceManager = jdoCar().getPersistenceManager();
43: }
44:
45: public void backToPit() {
46: Transaction tx = db().currentTransaction();
47: if (tx.isActive()) {
48: tx.commit();
49: }
50: mPersistenceManager.close();
51: }
52:
53: protected JdoCar jdoCar() {
54: return (JdoCar) car();
55: }
56:
57: protected PersistenceManager db() {
58: return mPersistenceManager;
59: }
60:
61: public void begin() {
62: db().currentTransaction().begin();
63: }
64:
65: public void commit() {
66: db().currentTransaction().commit();
67: }
68:
69: public void store(Object obj) {
70: db().makePersistent(obj);
71: }
72:
73: protected void doQuery(Query q, Object param) {
74: Collection result = (Collection) q.execute(param);
75: Iterator it = result.iterator();
76: while (it.hasNext()) {
77: Object o = it.next();
78: if (o instanceof CheckSummable) {
79: addToCheckSum(((CheckSummable) o).checkSum());
80: }
81: }
82: }
83:
84: protected void readExtent(Class clazz) {
85: Extent extent = db().getExtent(clazz, false);
86: Iterator itr = extent.iterator();
87: while (itr.hasNext()) {
88: Object o = itr.next();
89: if (o instanceof CheckSummable) {
90: addToCheckSum(((CheckSummable) o).checkSum());
91: }
92: }
93: extent.closeAll();
94: }
95:
96: }
|