KickJava   Java API By Example, From Geeks To Geeks.

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


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
23 import java.util.Iterator JavaDoc;
24 import javax.jdo.Extent;
25
26 import org.polepos.circuits.melbourne.*;
27 import org.polepos.teams.jdo.data.*;
28
29 /**
30  * @author Herkules
31  */

32 public class MelbourneJdo extends JdoDriver implements MelbourneDriver{
33     
34     public void write(){
35         
36         begin();
37         
38         int numobjects = setup().getObjectCount();
39         int commitinterval = setup().getCommitInterval();
40         
41         int commitctr = 0;
42         for ( int i = 1; i <= numobjects; i++ ){
43             
44             JdoPilot p = new JdoPilot( "Pilot_" + i, i );
45             db().makePersistent( p );
46             
47             if ( commitinterval > 0 && ++commitctr >= commitinterval ){
48                 commitctr = 0;
49                 commit();
50                 begin();
51                 Log.logger.fine( "commit while writing at " + i+1 ); //NOI18N
52
}
53             addToCheckSum(i);
54         }
55         
56         commit();
57     }
58     
59     public void read(){
60         readExtent(JdoPilot.class);
61     }
62     
63     public void read_hot() {
64         read();
65     }
66     
67     public void delete(){
68         
69         int numobjects =setup().getObjectCount();
70         int commitinterval = setup().getCommitInterval();
71
72         begin();
73         
74         Extent extent = db().getExtent( JdoPilot.class, false );
75         Iterator JavaDoc itr = extent.iterator();
76         int commitctr = 0;
77         for ( int i = 0; i < numobjects; i++ ){
78             
79             JdoPilot p = (JdoPilot)itr.next();
80             db().deletePersistent( p );
81             
82             if ( commitinterval > 0 && ++commitctr >= commitinterval ){
83                 commitctr = 0;
84                 
85                 // Debugging VOA: commit() seems to close the extent anyway
86
// so we can do it here
87
extent.closeAll();
88                 
89                 commit();
90                 begin();
91                 Log.logger.fine( "commit while deleting at " + i+1 ); //NOI18N
92

93                 // Debugging VOA: If we close the extent, we have to open it
94
// again of course.
95
extent = db().getExtent( JdoPilot.class, false );
96                 itr = extent.iterator();
97             }
98         }
99         
100         commit();
101         
102         extent.closeAll();
103     }
104 }
105
Popular Tags