01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (http://h2database.com/html/license.html).
04: * Initial Developer: H2 Group
05: */
06: package org.h2.command;
07:
08: import java.sql.SQLException;
09:
10: import org.h2.result.LocalResult;
11: import org.h2.util.ObjectArray;
12:
13: /**
14: * Represents a list of SQL statements.
15: */
16: public class CommandList extends Command {
17:
18: private final Command command;
19: private final String remaining;
20:
21: // TODO lock if possible!
22:
23: public CommandList(Parser parser, String sql, Command c,
24: String remaining) {
25: super (parser, sql);
26: this .command = c;
27: this .remaining = remaining;
28: }
29:
30: public ObjectArray getParameters() {
31: return command.getParameters();
32: }
33:
34: private void executeRemaining() throws SQLException {
35: Command command = session.prepareLocal(remaining);
36: if (command.isQuery()) {
37: command.query(0);
38: } else {
39: command.update();
40: }
41: }
42:
43: public int update() throws SQLException {
44: int updateCount = command.executeUpdate();
45: executeRemaining();
46: return updateCount;
47: }
48:
49: public LocalResult query(int maxrows) throws SQLException {
50: LocalResult result = command.query(maxrows);
51: executeRemaining();
52: return result;
53: }
54:
55: public boolean isQuery() {
56: return command.isQuery();
57: }
58:
59: public boolean isTransactional() {
60: return true;
61: }
62:
63: public boolean isReadOnly() {
64: return false;
65: }
66:
67: public LocalResult queryMeta() throws SQLException {
68: return command.queryMeta();
69: }
70:
71: }
|