01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.sail.rdbms.postgresql;
07:
08: import java.sql.PreparedStatement;
09: import java.sql.SQLException;
10:
11: import org.openrdf.sail.rdbms.schema.HashTable;
12: import org.openrdf.sail.rdbms.schema.ValueTable;
13:
14: /**
15: *
16: * @author james
17: */
18: public class PgSqlHashtable extends HashTable {
19: private ValueTable table;
20: private String execute;
21:
22: public PgSqlHashtable(ValueTable table) {
23: super (table);
24: this .table = table;
25: }
26:
27: @Override
28: public void close() throws SQLException {
29: if (execute != null) {
30: table.getRdbmsTable().execute(
31: "DEALLOCATE " + getName() + "_select");
32: }
33: super .close();
34: }
35:
36: @Override
37: protected PreparedStatement prepareSelect(String sql)
38: throws SQLException {
39: if (execute == null) {
40: StringBuilder sb = new StringBuilder();
41: sb.append("PREPARE ").append(getName()).append("_select (");
42: for (int i = 0, n = getSelectChunkSize(); i < n; i++) {
43: sb.append("bigint,");
44: }
45: sb.setCharAt(sb.length() - 1, ')');
46: sb.append(" AS\n");
47: sb.append("SELECT id, value\nFROM ").append(getName());
48: sb.append("\nWHERE value IN (");
49: for (int i = 0, n = getSelectChunkSize(); i < n; i++) {
50: sb.append("$").append(i + 1).append(",");
51: }
52: sb.setCharAt(sb.length() - 1, ')');
53: table.getRdbmsTable().execute(sb.toString());
54: sb.delete(0, sb.length());
55: sb.append("EXECUTE ").append(getName()).append("_select (");
56: for (int i = 0, n = getSelectChunkSize(); i < n; i++) {
57: sb.append("?,");
58: }
59: sb.setCharAt(sb.length() - 1, ')');
60: execute = sb.toString();
61: }
62: return super.prepareSelect(execute);
63: }
64:
65: }
|