KickJava   Java API By Example, From Geeks To Geeks.

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


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
23
24 import java.util.Iterator JavaDoc;
25
26 import org.polepos.circuits.bahrain.*;
27 import org.polepos.teams.hibernate.data.*;
28
29 import net.sf.hibernate.*;
30
31
32 /**
33  * @author Herkules
34  */

35 public class BahrainHibernate extends HibernateDriver implements BahrainDriver{
36      
37     private final String JavaDoc FROM = "from org.polepos.teams.hibernate.data.HibernateIndexedPilot";
38     
39     public void write(){
40         
41         try{
42             
43             Transaction tx = db().beginTransaction();
44     
45             int commitctr = 0;
46             int count = setup().getObjectCount();
47             int commitInterval = setup().getCommitInterval();
48             
49             for ( int i = 1; i <= count; i++ ){
50                 
51                 db().save( new HibernateIndexedPilot( "Pilot_" + i, "Jonny_" + i, i , i ) );
52                 if ( commitInterval> 0 && ++commitctr >= commitInterval ){
53                     commitctr = 0;
54                     tx.commit();
55                     Log.logger.fine( "commit while writing at " + i+1 ); //NOI18N
56
}
57                 
58                 addToCheckSum(i);
59                 
60             }
61             
62             tx.commit();
63         }
64         catch ( HibernateException hex ){
65             hex.printStackTrace();
66         }
67             
68     }
69
70     
71     public void query_indexed_string(){
72         
73         int count = setup().getSelectCount();
74         
75         for (int i = 1; i <= count; i++) {
76             doSingleResultQuery( FROM + " where Name='Pilot_" + i + "'" );
77         }
78         
79     }
80
81     
82     public void query_string(){
83         
84         int count = setup().getSelectCount();
85         
86         for (int i = 1; i <= count; i++) {
87             doSingleResultQuery( FROM + " where FirstName='Jonny_" + i + "'" );
88         }
89         
90     }
91     
92
93     public void query_indexed_int(){
94         
95         int count = setup().getSelectCount();
96         
97         for (int i = 1; i <= count; i++) {
98             doSingleResultQuery( FROM + " where LicenseID=" + i );
99         }
100         
101     }
102
103     public void query_int(){
104         
105         int count = setup().getSelectCount();
106         
107         for (int i = 1; i <= count; i++) {
108             doQuery( FROM + " where Points=" + i );
109         }
110         
111     }
112     
113     public void update(){
114         
115         try{
116             int updateCount = setup().getUpdateCount();
117             
118             Transaction tx = db().beginTransaction();
119             Iterator JavaDoc it = db().iterate(FROM);
120             for (int i = 0; i < updateCount; i++) {
121                 HibernateIndexedPilot p = (HibernateIndexedPilot) it.next();
122                 p.setName( p.getName().toUpperCase() );
123                 db().update( p );
124                 addToCheckSum(1);
125             }
126             tx.commit();
127         }
128         catch ( HibernateException hex ){
129             hex.printStackTrace();
130         }
131     }
132     
133     public void delete(){
134         try{
135             Transaction tx = db().beginTransaction();
136             Iterator JavaDoc it = db().iterate(FROM);
137             while(it.hasNext()){
138                 db().delete(it.next());
139                 addToCheckSum(1);
140             }
141             tx.commit();
142         }
143         catch ( HibernateException hex ){
144             hex.printStackTrace();
145         }
146     }
147     
148 }
149
Popular Tags