File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\command\dml\Call.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.sql.ResultSet;
10 import org.h2.command.CommandInterface;
11 import org.h2.command.Prepared;
12 import org.h2.engine.Session;
13 import org.h2.expression.Expression;
14 import org.h2.expression.ExpressionVisitor;
15 import org.h2.result.LocalResult;
16 import org.h2.result.ResultInterface;
17 import org.h2.value.Value;
18
19 /**
20 * This class represents the statement
21 * CALL.
22 */
23 public class Call extends Prepared {
24
25 private boolean isResultSet;
26 private Expression expression;
27 private Expression[] expressions;
28
29 public Call(Session session) {
30 super(session);
31 }
32
33 public ResultInterface queryMeta() {
34 LocalResult result;
35 if (isResultSet) {
36 Expression[] expr = expression.getExpressionColumns(session);
37 result = new LocalResult(session, expr, expr.length);
38 } else {
39 result = new LocalResult(session, expressions, 1);
40 }
41 result.done();
42 return result;
43 }
44
45 public int update() {
46 Value v = expression.getValue(session);
47 int type = v.getType();
48 switch(type) {
49 case Value.RESULT_SET:
50 // this will throw an exception
51 // methods returning a result set may not be called like this.
52 return super.update();
53 case Value.UNKNOWN:
54 case Value.NULL:
55 return 0;
56 default:
57 return v.getInt();
58 }
59 }
60
61 public ResultInterface query(int maxrows) {
62 setCurrentRowNumber(1);
63 Value v = expression.getValue(session);
64 if (isResultSet) {
65 v = v.convertTo(Value.RESULT_SET);
66 ResultSet rs = v.getResultSet();
67 return LocalResult.read(session, rs, maxrows);
68 }
69 LocalResult result = new LocalResult(session, expressions, 1);
70 Value[] row = { v };
71 result.addRow(row);
72 result.done();
73 return result;
74 }
75
76 public void prepare() {
77 expression = expression.optimize(session);
78 expressions = new Expression[] { expression };
79 isResultSet = expression.getType() == Value.RESULT_SET;
80 if (isResultSet) {
81 prepareAlways = true;
82 }
83 }
84
85 public void setExpression(Expression expression) {
86 this.expression = expression;
87 }
88
89 public boolean isQuery() {
90 return true;
91 }
92
93 public boolean isTransactional() {
94 return true;
95 }
96
97 public boolean isReadOnly() {
98 return expression.isEverything(ExpressionVisitor.READONLY_VISITOR);
99
100 }
101
102 public int getType() {
103 return CommandInterface.CALL;
104 }
105
106 public boolean isCacheable() {
107 return !isResultSet;
108 }
109
110 }
111