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.dml;
07:
08: import java.sql.SQLException;
09:
10: import org.h2.command.Prepared;
11: import org.h2.engine.Procedure;
12: import org.h2.engine.Session;
13: import org.h2.expression.Expression;
14: import org.h2.expression.Parameter;
15: import org.h2.result.LocalResult;
16: import org.h2.util.ObjectArray;
17:
18: /**
19: * This class represents the statement
20: * EXECUTE
21: */
22: public class ExecuteProcedure extends Prepared {
23:
24: private ObjectArray expressions = new ObjectArray();
25: private Procedure procedure;
26:
27: public ExecuteProcedure(Session session) {
28: super (session);
29: }
30:
31: public void setProcedure(Procedure procedure) {
32: this .procedure = procedure;
33: }
34:
35: /**
36: * Set the expression at the given index.
37: *
38: * @param index the index (0 based)
39: * @param expr the expression
40: */
41: public void setExpression(int index, Expression expr)
42: throws SQLException {
43: expressions.add(index, expr);
44: }
45:
46: private void setParameters() throws SQLException {
47: Prepared prepared = procedure.getPrepared();
48: ObjectArray params = prepared.getParameters();
49: for (int i = 0; params != null && i < params.size()
50: && i < expressions.size(); i++) {
51: Expression expr = (Expression) expressions.get(i);
52: Parameter p = (Parameter) params.get(i);
53: p.setValue(expr.getValue(session));
54: }
55: }
56:
57: public boolean isQuery() {
58: Prepared prepared = procedure.getPrepared();
59: return prepared.isQuery();
60: }
61:
62: public int update() throws SQLException {
63: setParameters();
64: Prepared prepared = procedure.getPrepared();
65: return prepared.update();
66: }
67:
68: public final LocalResult query(int limit) throws SQLException {
69: setParameters();
70: Prepared prepared = procedure.getPrepared();
71: return prepared.query(limit);
72: }
73:
74: public boolean isTransactional() {
75: return true;
76: }
77:
78: public LocalResult queryMeta() throws SQLException {
79: Prepared prepared = procedure.getPrepared();
80: return prepared.queryMeta();
81: }
82:
83: }
|