1 | /* |
2 | * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0, |
3 | * and the EPL 1.0 (http://h2database.com/html/license.html). |
4 | * Initial Developer: H2 Group |
5 | */ |
6 | package org.h2.command; |
7 | |
8 | import java.util.ArrayList; |
9 | import org.h2.expression.ParameterInterface; |
10 | import org.h2.result.ResultInterface; |
11 | |
12 | /** |
13 | * Represents a list of SQL statements. |
14 | */ |
15 | class CommandList extends Command { |
16 | |
17 | private final Command command; |
18 | private final String remaining; |
19 | |
20 | CommandList(Parser parser, String sql, Command c, String remaining) { |
21 | super(parser, sql); |
22 | this.command = c; |
23 | this.remaining = remaining; |
24 | } |
25 | |
26 | @Override |
27 | public ArrayList<? extends ParameterInterface> getParameters() { |
28 | return command.getParameters(); |
29 | } |
30 | |
31 | private void executeRemaining() { |
32 | Command remainingCommand = session.prepareLocal(remaining); |
33 | if (remainingCommand.isQuery()) { |
34 | remainingCommand.query(0); |
35 | } else { |
36 | remainingCommand.update(); |
37 | } |
38 | } |
39 | |
40 | @Override |
41 | public int update() { |
42 | int updateCount = command.executeUpdate(); |
43 | executeRemaining(); |
44 | return updateCount; |
45 | } |
46 | |
47 | @Override |
48 | public ResultInterface query(int maxrows) { |
49 | ResultInterface result = command.query(maxrows); |
50 | executeRemaining(); |
51 | return result; |
52 | } |
53 | |
54 | @Override |
55 | public boolean isQuery() { |
56 | return command.isQuery(); |
57 | } |
58 | |
59 | @Override |
60 | public boolean isTransactional() { |
61 | return true; |
62 | } |
63 | |
64 | @Override |
65 | public boolean isReadOnly() { |
66 | return false; |
67 | } |
68 | |
69 | @Override |
70 | public ResultInterface queryMeta() { |
71 | return command.queryMeta(); |
72 | } |
73 | |
74 | @Override |
75 | public int getCommandType() { |
76 | return command.getCommandType(); |
77 | } |
78 | |
79 | } |