KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdbc > fetch > FetchOp


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdbc.fetch;
13
14 import com.versant.core.common.BindingSupportImpl;
15 import com.versant.core.jdbc.sql.exp.SelectExp;
16 import com.versant.core.jdbc.sql.exp.SqlExp;
17
18 import java.sql.SQLException JavaDoc;
19 import java.io.PrintStream JavaDoc;
20
21 /**
22  * On object or field fetch in an EJBQL query. An array of these is contructed
23  * for the select list of an EJBQL query and any eager fetched fields (i.e.
24  * fields in the default fetch group).
25  */

26 public abstract class FetchOp {
27
28     protected final FetchSpec spec;
29     private int index;
30
31     public FetchOp(FetchSpec spec) {
32         this.spec = spec;
33     }
34
35     /**
36      * Init this FetchOp and return the expressions that we need to be added
37      * to the select list of the query or null if none. The FetchOp may
38      * add additional FetchOp's to the spec.
39      */

40     public abstract SqlExp init(SelectExp root, int firstColIndex);
41
42     /**
43      * Return a FetchOpData that accesses the output we produce. This can be
44      * used when creating other FetchOp's that need this output.
45      */

46     public abstract FetchOpData getOutputData();
47
48     /**
49      * Fetch our data.
50      */

51     public abstract void fetch(FetchResultImp fetchResult) throws SQLException JavaDoc;
52
53     /**
54      * Get a one line user understandable description of this operation.
55      */

56     public abstract String JavaDoc getDescription();
57
58     /**
59      * Print a user understandable description of this operation.
60      */

61     public void printPlan(PrintStream JavaDoc p, String JavaDoc indent) {
62         p.println(indent + getIndex() + ": " + getName() + " " +
63                 getDescription());
64     }
65
66     /**
67      * Get the name of this op. The default is the unqualified class name with
68      * any Fop prefix removed.
69      */

70     public String JavaDoc getName() {
71         String JavaDoc cname = getClass().getName();
72         int i = cname.lastIndexOf(".Fop");
73         if (i < 0) {
74             i = cname.lastIndexOf('.') + 1;
75         } else {
76             i += 4;
77         }
78         return cname.substring(i);
79     }
80
81     /**
82      * This is called after our spec has generated its SQL. Generate SQL for
83      * any nested FetchSpec's and clear fields no longer needed (e.g. any
84      * SqlExp type fields).
85      */

86     public void generateSQL() {
87     }
88
89     /**
90      * This is invoked when a FetchResult from our FetchSpec is closed.
91      * Closed any nested queries etc.
92      */

93     public void fetchResultClosed(FetchResult fetchResult) {
94     }
95
96     /**
97      * Get an object to be included in fetch projection.
98      */

99     public Object JavaDoc getResult(FetchResultImp fetchResult) {
100         throw notImplemented();
101     }
102
103     /**
104      * Get the type of our result (INTW, OID, STRING etc).
105      *
106      * @see com.versant.core.metadata.MDStatics.OID
107      */

108     public int getResultType() {
109         throw notImplemented();
110     }
111
112     public FetchSpec getSpec() {
113         return spec;
114     }
115
116     public int getIndex() {
117         return index;
118     }
119
120     public void setIndex(int index) {
121         this.index = index;
122     }
123
124     public RuntimeException JavaDoc notImplemented() {
125         return notImplemented("Not implemented for " + toString());
126     }
127
128     public RuntimeException JavaDoc notImplemented(String JavaDoc msg) {
129         return internal(msg);
130     }
131
132     public RuntimeException JavaDoc internal(String JavaDoc msg) {
133         return BindingSupportImpl.getInstance().internal(msg);
134     }
135
136     public String JavaDoc toString() {
137         String JavaDoc s;
138         try {
139             s = toStringImp();
140         } catch (Exception JavaDoc e) {
141             s = "<toStringImp failed: " + e + ">";
142         }
143         return index + ": " + getName() + " " + getDescription() +
144                 (s == null ? "" : " " + s);
145     }
146
147     /**
148      * Override this to provide subclass specific info for toString that is
149      * not already provided by getDescription.
150      */

151     protected String JavaDoc toStringImp() {
152         return null;
153     }
154
155 }
156
157
Popular Tags