001: /*
002: This file is part of the PolePosition database benchmark
003: http://www.polepos.org
004:
005: This program is free software; you can redistribute it and/or
006: modify it under the terms of the GNU General Public License
007: as published by the Free Software Foundation; either version 2
008: of the License, or (at your option) any later version.
009:
010: This program is distributed in the hope that it will be useful,
011: but WITHOUT ANY WARRANTY; without even the implied warranty of
012: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: GNU General Public License for more details.
014:
015: You should have received a copy of the GNU General Public
016: License along with this program; if not, write to the Free
017: Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
018: MA 02111-1307, USA. */
019:
020: package org.polepos.teams.hibernate;
021:
022: import java.util.Iterator;
023:
024: import org.polepos.circuits.bahrain.*;
025: import org.polepos.teams.hibernate.data.*;
026:
027: import net.sf.hibernate.*;
028:
029: /**
030: * @author Herkules
031: */
032: public class BahrainHibernate extends HibernateDriver implements
033: BahrainDriver {
034:
035: private final String FROM = "from org.polepos.teams.hibernate.data.HibernateIndexedPilot";
036:
037: public void write() {
038:
039: try {
040:
041: Transaction tx = db().beginTransaction();
042:
043: int commitctr = 0;
044: int count = setup().getObjectCount();
045: int commitInterval = setup().getCommitInterval();
046:
047: for (int i = 1; i <= count; i++) {
048:
049: db().save(
050: new HibernateIndexedPilot("Pilot_" + i,
051: "Jonny_" + i, i, i));
052: if (commitInterval > 0 && ++commitctr >= commitInterval) {
053: commitctr = 0;
054: tx.commit();
055: Log.logger.fine("commit while writing at " + i + 1); //NOI18N
056: }
057:
058: addToCheckSum(i);
059:
060: }
061:
062: tx.commit();
063: } catch (HibernateException hex) {
064: hex.printStackTrace();
065: }
066:
067: }
068:
069: public void query_indexed_string() {
070:
071: int count = setup().getSelectCount();
072:
073: for (int i = 1; i <= count; i++) {
074: doSingleResultQuery(FROM + " where Name='Pilot_" + i + "'");
075: }
076:
077: }
078:
079: public void query_string() {
080:
081: int count = setup().getSelectCount();
082:
083: for (int i = 1; i <= count; i++) {
084: doSingleResultQuery(FROM + " where FirstName='Jonny_" + i
085: + "'");
086: }
087:
088: }
089:
090: public void query_indexed_int() {
091:
092: int count = setup().getSelectCount();
093:
094: for (int i = 1; i <= count; i++) {
095: doSingleResultQuery(FROM + " where LicenseID=" + i);
096: }
097:
098: }
099:
100: public void query_int() {
101:
102: int count = setup().getSelectCount();
103:
104: for (int i = 1; i <= count; i++) {
105: doQuery(FROM + " where Points=" + i);
106: }
107:
108: }
109:
110: public void update() {
111:
112: try {
113: int updateCount = setup().getUpdateCount();
114:
115: Transaction tx = db().beginTransaction();
116: Iterator it = db().iterate(FROM);
117: for (int i = 0; i < updateCount; i++) {
118: HibernateIndexedPilot p = (HibernateIndexedPilot) it
119: .next();
120: p.setName(p.getName().toUpperCase());
121: db().update(p);
122: addToCheckSum(1);
123: }
124: tx.commit();
125: } catch (HibernateException hex) {
126: hex.printStackTrace();
127: }
128: }
129:
130: public void delete() {
131: try {
132: Transaction tx = db().beginTransaction();
133: Iterator it = db().iterate(FROM);
134: while (it.hasNext()) {
135: db().delete(it.next());
136: addToCheckSum(1);
137: }
138: tx.commit();
139: } catch (HibernateException hex) {
140: hex.printStackTrace();
141: }
142: }
143:
144: }
|