KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > polepos > teams > hibernate > MelbourneHibernate


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.hibernate;
21
22 import org.polepos.circuits.melbourne.*;
23 import org.polepos.teams.hibernate.data.*;
24
25 import net.sf.hibernate.*;
26
27 /**
28  * @author Herkules
29  */

30 public class MelbourneHibernate extends HibernateDriver implements MelbourneDriver{
31     
32     private final String JavaDoc FROM = "from org.polepos.teams.hibernate.data.HibernatePilot";
33     
34     public void write( ){
35         
36         int numobjects = setup().getObjectCount();
37         int commitintervall = setup().getCommitInterval();
38         
39         int commitctr = 0;
40         try{
41             
42             Transaction tx = db().beginTransaction();
43             
44             for ( int i = 1; i <= numobjects; i++ ){
45                 
46                 HibernatePilot p = new HibernatePilot( "Pilot_" + i, "Herkules", i, 1 );
47                 
48                 db().save( p );
49                 
50                 addToCheckSum(i);
51                 
52                 if ( commitintervall > 0 && ++commitctr >= commitintervall )
53                 {
54                     commitctr = 0;
55                     tx.commit();
56                     tx = db().beginTransaction();
57                     Log.logger.fine( "commit while writing at " + i+1 ); //NOI18N
58
}
59             }
60             tx.commit();
61         }
62         catch ( HibernateException hex ){
63             hex.printStackTrace();
64         }
65     }
66     
67     public void read(){
68         doQuery(FROM);
69     }
70     
71     public void read_hot() {
72         read();
73     }
74
75     public void delete(){
76         try{
77             Transaction tx = db().beginTransaction();
78             db().delete(FROM);
79             tx.commit();
80         }catch ( HibernateException hex ){
81             hex.printStackTrace();
82         }
83     }
84
85 }
86
Popular Tags