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.jdbc.drivers.melbourne;
21:
22: import org.polepos.data.*;
23: import org.polepos.teams.jdbc.*;
24:
25: /**
26: * Performs a bulkwrite by employing multiple VALUES part in the SQL statement.
27: * @author Herkules
28: *
29: * Typical:
30: * BUNCH=10: 50000 objects: write 1062ms (0.02124ms/object), read 172ms (0.00344ms/object), delete 0ms (0.0ms/object)
31: * BUNCH=100: 50000 objects: write 500ms (0.01ms/object), read 156ms (0.00312ms/object), delete 0ms (0.0ms/object)
32: * BUNCH=1000: 50000 objects: write 360ms (0.0072ms/object), read 218ms (0.00436ms/object), delete 0ms (0.0ms/object)
33: */
34: public class BulkWriteMultiValue implements BulkWriteStrategy {
35: private final JdbcCar mCar;
36:
37: /**
38: * Creates a new instance of BulkWriteMultiValue.
39: */
40: public BulkWriteMultiValue(JdbcCar car) {
41: mCar = car;
42: }
43:
44: /**
45: * Dump an array of pilots to the DB by creating a loooong SQL statement.
46: */
47: public void savePilots(String tablename, Pilot[] p, int count,
48: int index) {
49: if (count == 0)
50: return;
51: StringBuffer stmt = new StringBuffer("insert into ");
52: stmt.append(tablename);
53: stmt.append(" (id,Name,FrontName,Points,LicenseID) values ");
54: for (int i = 0; i < count - 1; i++) {
55: values(stmt, p[i], index++);
56: stmt.append(",");
57: }
58: values(stmt, p[count - 1], index++);
59:
60: mCar.executeSQL(stmt.toString());
61: }
62:
63: /**
64: * Helper.
65: */
66: private void values(StringBuffer to, Pilot p, int idx) {
67: to.append("(").append(Integer.toString(idx)).append(", '");
68: to.append(p.getName()).append("', '");
69: to.append(p.getFirstName()).append("', ");
70: to.append(Integer.toString(p.getPoints())).append(", ");
71: to.append(Integer.toString(p.getLicenseID())).append(")");
72: }
73:
74: }
|