KickJava   Java API By Example, From Geeks To Geeks.

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


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.ExpressionColumn;
12 import org.h2.result.LocalResult;
13 import org.h2.table.Column;
14 import org.h2.util.ObjectArray;
15 import org.h2.value.Value;
16 import org.h2.value.ValueString;
17
18 public class ExplainPlan extends Prepared {
19
20     private Prepared command;
21     private LocalResult result;
22     
23     public ExplainPlan(Session session) {
24         super(session);
25     }
26     
27     public void setCommand(Prepared command) {
28         this.command = command;
29     }
30     
31     public void prepare() throws SQLException JavaDoc {
32         command.prepare();
33     }
34
35     public LocalResult query(int maxrows) throws SQLException JavaDoc {
36         // TODO rights: are rights required for explain?
37
ObjectArray expressions = new ObjectArray();
38         Column column = new Column("PLAN", Value.STRING, 0, 0);
39         ExpressionColumn expr = new ExpressionColumn(session.getDatabase(), null, column);
40         expressions.add(expr);
41         result = new LocalResult(session, expressions, 1);
42         String JavaDoc plan = command.getPlan();
43         add(plan);
44         result.done();
45         return result;
46     }
47     
48     private void add(String JavaDoc text) throws SQLException JavaDoc {
49         Value[] row = new Value[1];
50         Value value = ValueString.get(text);
51         row[0] = value;
52         result.addRow(row);
53     }
54     
55     public boolean isQuery() {
56         return true;
57     }
58     
59     public boolean isTransactional() {
60         return true;
61     }
62
63     public boolean isReadOnly() {
64         return true;
65     }
66 }
67
Popular Tags