KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > polepos > teams > jdo > JdoDriver


1 /*
2 This file is part of the PolePosition database benchmark
3 http://www.polepos.org
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
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 /**
30  * @author Herkules
31  */

32 public abstract class JdoDriver extends Driver{
33     
34     private transient PersistenceManager mPersistenceManager;
35     
36     public void takeSeatIn( Car car, TurnSetup setup) 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 JavaDoc obj){
70         db().makePersistent(obj);
71     }
72     
73     protected void doQuery( Query q, Object JavaDoc param){
74         Collection result = (Collection)q.execute(param);
75         Iterator it = result.iterator();
76         while(it.hasNext()){
77             Object JavaDoc o = it.next();
78             if(o instanceof CheckSummable){
79                 addToCheckSum(((CheckSummable)o).checkSum());
80             }
81         }
82     }
83     
84     protected void readExtent(Class JavaDoc clazz){
85         Extent extent = db().getExtent( clazz, false );
86         Iterator itr = extent.iterator();
87         while (itr.hasNext()){
88             Object JavaDoc o = itr.next();
89             if(o instanceof CheckSummable){
90                 addToCheckSum(((CheckSummable)o).checkSum());
91             }
92         }
93         extent.closeAll();
94     }
95     
96     
97
98 }
99
Popular Tags