KickJava   Java API By Example, From Geeks To Geeks.

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


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.melbourne.*;
23 import org.polepos.data.*;
24
25 import com.db4o.*;
26 import com.db4o.query.*;
27
28
29 /**
30  * @author Herkules
31  */

32 public class MelbourneDb4o extends Db4oDriver implements MelbourneDriver{
33     
34     
35     public void write(){
36         
37         int numobjects = setup().getObjectCount();
38         int commitinterval = setup().getCommitInterval();
39         int commitctr = 0;
40         
41         begin();
42         for ( int i = 1; i <= numobjects; i++ ){
43             
44             Pilot p =new Pilot( "Pilot_" + i, "Herkules", i, i ) ;
45             store(p);
46             
47             if ( commitinterval > 0 && ++commitctr >= commitinterval ){
48                 commitctr = 0;
49                 commit();
50                 begin();
51             }
52             
53             addToCheckSum(i);
54         }
55         
56         commit();
57     }
58
59     public void read(){
60         readExtent(Pilot.class);
61     }
62
63     public void read_hot() {
64         read();
65     }
66     
67     public void delete(){
68         
69         begin();
70         
71         int numobjects = setup().getObjectCount();
72         int commitintervall = setup().getCommitInterval();
73         
74         int commitctr = 0;
75         
76         // By setting an activation depth of zero, we can
77
// prevent instantiating the Pilot objects.
78
db().configure().activationDepth(0);
79         
80         Query allpilots = db().query();
81         allpilots.constrain( Pilot.class );
82         ObjectSet deleteset = allpilots.execute();
83         
84         for ( int i = 0; i < numobjects; i++ ){
85             
86             Object JavaDoc o = deleteset.next();
87             
88             db().delete(o);
89             
90             if ( commitintervall > 0 && ++commitctr >= commitintervall ){
91                 commitctr = 0;
92                 commit();
93                 begin();
94             }
95         }
96         
97         commit();
98     }
99     
100 }
101
Popular Tags