01: /*
02: This file is part of the PolePosition database benchmark
03: http://www.polepos.org
04:
05: This program is free software; you can redistribute it and/or
06: modify it under the terms of the GNU General Public License
07: as published by the Free Software Foundation; either version 2
08: of the License, or (at your option) any later version.
09:
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
31: MelbourneDriver {
32:
33: private final String FROM = "from org.polepos.teams.hibernate.data.HibernatePilot";
34:
35: public void write() {
36:
37: int numobjects = setup().getObjectCount();
38: int commitintervall = setup().getCommitInterval();
39:
40: int commitctr = 0;
41: try {
42:
43: Transaction tx = db().beginTransaction();
44:
45: for (int i = 1; i <= numobjects; i++) {
46:
47: HibernatePilot p = new HibernatePilot("Pilot_" + i,
48: "Herkules", i, 1);
49:
50: db().save(p);
51:
52: addToCheckSum(i);
53:
54: if (commitintervall > 0
55: && ++commitctr >= commitintervall) {
56: commitctr = 0;
57: tx.commit();
58: tx = db().beginTransaction();
59: Log.logger.fine("commit while writing at " + i + 1); //NOI18N
60: }
61: }
62: tx.commit();
63: } catch (HibernateException hex) {
64: hex.printStackTrace();
65: }
66: }
67:
68: public void read() {
69: doQuery(FROM);
70: }
71:
72: public void read_hot() {
73: read();
74: }
75:
76: public void delete() {
77: try {
78: Transaction tx = db().beginTransaction();
79: db().delete(FROM);
80: tx.commit();
81: } catch (HibernateException hex) {
82: hex.printStackTrace();
83: }
84: }
85:
86: }
|