01: /*-------------------------------------------------------------------------
02: *
03: * Copyright (c) 2004-2005, PostgreSQL Global Development Group
04: * Copyright (c) 2004, Open Cloud Limited.
05: *
06: * IDENTIFICATION
07: * $PostgreSQL: pgjdbc/org/postgresql/core/v3/CompositeQuery.java,v 1.4 2005/01/11 08:25:44 jurka Exp $
08: *
09: *-------------------------------------------------------------------------
10: */
11: package org.postgresql.core.v3;
12:
13: import org.postgresql.core.*;
14:
15: /**
16: * V3 Query implementation for queries that involve multiple statements.
17: * We split it up into one SimpleQuery per statement, and wrap the
18: * corresponding per-statement SimpleParameterList objects in
19: * a CompositeParameterList.
20: *
21: * @author Oliver Jowett (oliver@opencloud.com)
22: */
23: class CompositeQuery implements V3Query {
24: CompositeQuery(SimpleQuery[] subqueries, int[] offsets) {
25: this .subqueries = subqueries;
26: this .offsets = offsets;
27: }
28:
29: public ParameterList createParameterList() {
30: SimpleParameterList[] subparams = new SimpleParameterList[subqueries.length];
31: for (int i = 0; i < subqueries.length; ++i)
32: subparams[i] = (SimpleParameterList) subqueries[i]
33: .createParameterList();
34: return new CompositeParameterList(subparams, offsets);
35: }
36:
37: public String toString(ParameterList parameters) {
38: StringBuffer sbuf = new StringBuffer(subqueries[0].toString());
39: for (int i = 1; i < subqueries.length; ++i) {
40: sbuf.append(';');
41: sbuf.append(subqueries[i]);
42: }
43: return sbuf.toString();
44: }
45:
46: public String toString() {
47: return toString(null);
48: }
49:
50: public void close() {
51: for (int i = 0; i < subqueries.length; ++i)
52: subqueries[i].close();
53: }
54:
55: public SimpleQuery[] getSubqueries() {
56: return subqueries;
57: }
58:
59: private final SimpleQuery[] subqueries;
60: private final int[] offsets;
61: }
|