KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > polepos > teams > db4o > BahrainDb4o


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.db4o;
21
22 import org.polepos.circuits.bahrain.*;
23 import org.polepos.data.*;
24 import org.polepos.framework.*;
25
26 import com.db4o.*;
27 import com.db4o.query.*;
28
29
30
31 /**
32  * @author Herkules
33  */

34 public class BahrainDb4o extends Db4oDriver implements BahrainDriver{
35         
36     
37     public void takeSeatIn(Car car, TurnSetup setup) throws CarMotorFailureException{
38
39         Db4o.configure().objectClass( Pilot.class ).objectField( "mName" ).indexed( true );
40         Db4o.configure().objectClass( Pilot.class ).objectField( "mLicenseID" ).indexed( true );
41
42         super.takeSeatIn(car, setup);
43     }
44     
45     public void write(){
46         int commitctr = 0;
47         int count = setup().getObjectCount();
48         int commitInterval = setup().getCommitInterval();
49         begin();
50         for ( int i = 1; i <= count; i++ ){
51             store( new Pilot( "Pilot_" + i, "Jonny_" + i, i , i ) );
52             if ( commitInterval> 0 && ++commitctr >= commitInterval ){
53                 commitctr = 0;
54                 commit();
55                 begin();
56             }
57             addToCheckSum(i);
58         }
59         commit();
60     }
61  
62     public void query_indexed_string() {
63         int count = setup().getSelectCount();
64         for (int i = 1; i <= count; i++) {
65             Query q = db().query();
66             q.constrain( Pilot.class );
67             q.descend( "mName" ).constrain("Pilot_" + i);
68             doQuery( q );
69         }
70         
71     }
72             
73     public void query_string() {
74         int count = setup().getSelectCount();
75         for (int i = 1; i <= count; i++) {
76             Query q = db().query();
77             q.constrain( Pilot.class );
78             q.descend( "mFirstName" ).constrain("Jonny_" + i);
79             doQuery( q );
80         }
81     }
82
83     public void query_indexed_int() {
84         int count = setup().getSelectCount();
85         for (int i = 1; i <= count; i++) {
86             Query q = db().query();
87             q.constrain( Pilot.class );
88             q.descend( "mLicenseID" ).constrain(new Integer JavaDoc(i));
89             doQuery( q );
90         }
91     }
92
93     public void query_int() {
94         int count = setup().getSelectCount();
95         for (int i = 1; i <= count; i++) {
96             Query q = db().query();
97             q.constrain( Pilot.class );
98             q.descend( "mPoints" ).constrain(new Integer JavaDoc(i));
99             doQuery( q );
100         }
101     }
102
103     public void update() {
104         int updateCount = setup().getUpdateCount();
105         Query q = db().query();
106         q.constrain( Pilot.class );
107         ObjectSet set = q.execute();
108         for (int i = 1; i <= updateCount; i++) {
109             Pilot p = (Pilot)set.next();
110             p.setName( p.getName().toUpperCase() );
111             db().set(p);
112             addToCheckSum(1);
113         }
114         db().commit();
115     }
116     
117     public void delete() {
118         Query q = db().query();
119         q.constrain( Pilot.class );
120         ObjectSet deleteset = q.execute();
121         while ( deleteset.hasNext() ){
122             db().delete( deleteset.next() );
123             addToCheckSum(1);
124         }
125         db().commit();
126     }
127     
128 }
129
Popular Tags