KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > command > dml > Call


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.command.dml;
6
7 import java.sql.SQLException JavaDoc;
8
9 import org.h2.command.Prepared;
10 import org.h2.engine.Session;
11 import org.h2.expression.Expression;
12 import org.h2.expression.ExpressionColumn;
13 import org.h2.expression.ExpressionVisitor;
14 import org.h2.result.LocalResult;
15 import org.h2.table.Column;
16 import org.h2.util.ObjectArray;
17 import org.h2.value.Value;
18 import org.h2.value.ValueArray;
19 import org.h2.value.ValueResultSet;
20
21
22 /**
23  * @author Thomas
24  */

25
26 public class Call extends Prepared {
27     private Expression value;
28     private ObjectArray expressions;
29
30     public Call(Session session) {
31         super(session);
32     }
33
34     public LocalResult query(int maxrows) throws SQLException JavaDoc {
35         setCurrentRowNumber(1);
36         Value v = value.getValue(session);
37         if(v.getType() == Value.RESULT_SET) {
38             return LocalResult.read(session, ((ValueResultSet)v).getResultSet());
39         } else if(v.getType() == Value.ARRAY) {
40             Value[] list = ((ValueArray)v).getList();
41             ObjectArray expr = new ObjectArray();
42             for(int i = 0; i<list.length; i++) {
43                 Value e = list[i];
44                 Column col = new Column("C" + (i+1), e.getType(), e.getPrecision(), e.getScale());
45                 expr.add(new ExpressionColumn(session.getDatabase(), null, col));
46             }
47             LocalResult result = new LocalResult(session, expr, list.length);
48             result.addRow(list);
49             result.done();
50             return result;
51         }
52         LocalResult result = new LocalResult(session, expressions, 1);
53         Value[] row = new Value[1];
54         row[0] = v;
55         result.addRow(row);
56         result.done();
57         return result;
58     }
59
60     public void prepare() throws SQLException JavaDoc {
61         value = value.optimize(session);
62         expressions = new ObjectArray();
63         expressions.add(value);
64     }
65
66     public void setValue(Expression expression) {
67         value = expression;
68     }
69
70     public boolean isQuery() {
71         return true;
72     }
73
74     public boolean isTransactional() {
75         return true;
76     }
77     
78     public boolean isReadOnly() {
79         return value.isEverything(ExpressionVisitor.READONLY);
80         
81     }
82     
83 }
84
Popular Tags