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.db4o;
021:
022: import org.polepos.circuits.bahrain.*;
023: import org.polepos.data.*;
024: import org.polepos.framework.*;
025:
026: import com.db4o.*;
027: import com.db4o.query.*;
028:
029: /**
030: * @author Herkules
031: */
032: public class BahrainDb4o extends Db4oDriver implements BahrainDriver {
033:
034: public void takeSeatIn(Car car, TurnSetup setup)
035: throws CarMotorFailureException {
036:
037: Db4o.configure().objectClass(Pilot.class).objectField("mName")
038: .indexed(true);
039: Db4o.configure().objectClass(Pilot.class).objectField(
040: "mLicenseID").indexed(true);
041:
042: super .takeSeatIn(car, setup);
043: }
044:
045: public void write() {
046: int commitctr = 0;
047: int count = setup().getObjectCount();
048: int commitInterval = setup().getCommitInterval();
049: begin();
050: for (int i = 1; i <= count; i++) {
051: store(new Pilot("Pilot_" + i, "Jonny_" + i, i, i));
052: if (commitInterval > 0 && ++commitctr >= commitInterval) {
053: commitctr = 0;
054: commit();
055: begin();
056: }
057: addToCheckSum(i);
058: }
059: commit();
060: }
061:
062: public void query_indexed_string() {
063: int count = setup().getSelectCount();
064: for (int i = 1; i <= count; i++) {
065: Query q = db().query();
066: q.constrain(Pilot.class);
067: q.descend("mName").constrain("Pilot_" + i);
068: doQuery(q);
069: }
070:
071: }
072:
073: public void query_string() {
074: int count = setup().getSelectCount();
075: for (int i = 1; i <= count; i++) {
076: Query q = db().query();
077: q.constrain(Pilot.class);
078: q.descend("mFirstName").constrain("Jonny_" + i);
079: doQuery(q);
080: }
081: }
082:
083: public void query_indexed_int() {
084: int count = setup().getSelectCount();
085: for (int i = 1; i <= count; i++) {
086: Query q = db().query();
087: q.constrain(Pilot.class);
088: q.descend("mLicenseID").constrain(new Integer(i));
089: doQuery(q);
090: }
091: }
092:
093: public void query_int() {
094: int count = setup().getSelectCount();
095: for (int i = 1; i <= count; i++) {
096: Query q = db().query();
097: q.constrain(Pilot.class);
098: q.descend("mPoints").constrain(new Integer(i));
099: doQuery(q);
100: }
101: }
102:
103: public void update() {
104: int updateCount = setup().getUpdateCount();
105: Query q = db().query();
106: q.constrain(Pilot.class);
107: ObjectSet set = q.execute();
108: for (int i = 1; i <= updateCount; i++) {
109: Pilot p = (Pilot) set.next();
110: p.setName(p.getName().toUpperCase());
111: db().set(p);
112: addToCheckSum(1);
113: }
114: db().commit();
115: }
116:
117: public void delete() {
118: Query q = db().query();
119: q.constrain(Pilot.class);
120: ObjectSet deleteset = q.execute();
121: while (deleteset.hasNext()) {
122: db().delete(deleteset.next());
123: addToCheckSum(1);
124: }
125: db().commit();
126: }
127:
128: }
|