File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\command\dml\ExecuteProcedure.java.html

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.command.dml;
8
9 import java.util.ArrayList;
10 import org.h2.command.CommandInterface;
11 import org.h2.command.Prepared;
12 import org.h2.engine.Procedure;
13 import org.h2.engine.Session;
14 import org.h2.expression.Expression;
15 import org.h2.expression.Parameter;
16 import org.h2.result.ResultInterface;
17 import org.h2.util.New;
18
19 /**
20 * This class represents the statement
21 * EXECUTE
22 */
23 public class ExecuteProcedure extends Prepared {
24
25 private final ArrayList<Expression> expressions = New.arrayList();
26 private Procedure procedure;
27
28 public ExecuteProcedure(Session session) {
29 super(session);
30 }
31
32 public void setProcedure(Procedure procedure) {
33 this.procedure = procedure;
34 }
35
36 /**
37 * Set the expression at the given index.
38 *
39 * @param index the index (0 based)
40 * @param expr the expression
41 */
42 public void setExpression(int index, Expression expr) {
43 expressions.add(index, expr);
44 }
45
46 private void setParameters() {
47 Prepared prepared = procedure.getPrepared();
48 ArrayList<Parameter> params = prepared.getParameters();
49 for (int i = 0; params != null && i < params.size() && i < expressions.size(); i++) {
50 Expression expr = expressions.get(i);
51 Parameter p = params.get(i);
52 p.setValue(expr.getValue(session));
53 }
54 }
55
56 public boolean isQuery() {
57 Prepared prepared = procedure.getPrepared();
58 return prepared.isQuery();
59 }
60
61 public int update() {
62 setParameters();
63 Prepared prepared = procedure.getPrepared();
64 return prepared.update();
65 }
66
67 public ResultInterface query(int limit) {
68 setParameters();
69 Prepared prepared = procedure.getPrepared();
70 return prepared.query(limit);
71 }
72
73 public boolean isTransactional() {
74 return true;
75 }
76
77 public ResultInterface queryMeta() {
78 Prepared prepared = procedure.getPrepared();
79 return prepared.queryMeta();
80 }
81
82 public int getType() {
83 return CommandInterface.EXECUTE;
84 }
85
86 }
87