KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mckoi > database > CorrelatedVariable


1 /**
2  * com.mckoi.database.CorrelatedVariable 08 Nov 2001
3  *
4  * Mckoi SQL Database ( http://www.mckoi.com/database )
5  * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * Version 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License Version 2 for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * Version 2 along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  *
20  * Change Log:
21  *
22  *
23  */

24
25 package com.mckoi.database;
26
27 /**
28  * A wrapper for a variable in a sub-query that references a column outside
29  * of the current query. A correlated variable differs from a regular
30  * variable because its value is constant in an operation, but may vary over
31  * future iterations of the operation.
32  * <p>
33  * This object is NOT immutable.
34  *
35  * @author Tobias Downer
36  */

37
38 public class CorrelatedVariable implements Cloneable JavaDoc, java.io.Serializable JavaDoc {
39
40   static final long serialVersionUID = -607848111230634419L;
41
42   /**
43    * The Variable reference itself.
44    */

45   private Variable variable;
46
47   /**
48    * The number of sub-query branches back that the reference for this
49    * variable can be found.
50    */

51   private int query_level_offset;
52
53   /**
54    * The temporary value this variable has been set to evaluate to.
55    */

56   private transient TObject eval_result;
57
58
59   /**
60    * Constructs the CorrelatedVariable.
61    */

62   public CorrelatedVariable(Variable variable, int level_offset) {
63     this.variable = variable;
64     this.query_level_offset = level_offset;
65   }
66
67   /**
68    * Returns the wrapped Variable.
69    */

70   public Variable getVariable() {
71     return variable;
72   }
73
74   /**
75    * Returns the number of sub-query branches back that the reference for this
76    * variable can be found. For example, if the correlated variable references
77    * the direct descendant this will return 1.
78    */

79   public int getQueryLevelOffset() {
80     return query_level_offset;
81   }
82
83   /**
84    * Sets the value this correlated variable evaluates to.
85    */

86   public void setEvalResult(TObject ob) {
87     this.eval_result = ob;
88   }
89
90   /**
91    * Given a VariableResolver this will set the value of the correlated
92    * variable.
93    */

94   public void setFromResolver(VariableResolver resolver) {
95     Variable v = getVariable();
96     setEvalResult(resolver.resolve(v));
97   }
98
99   /**
100    * Returns the value this correlated variable evaluates to.
101    */

102   public TObject getEvalResult() {
103     return eval_result;
104   }
105
106   /**
107    * Returns the TType this correlated variable evaluates to.
108    */

109   public TType returnTType() {
110     return eval_result.getTType();
111   }
112
113
114   /**
115    * Clones the object.
116    */

117   public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
118     CorrelatedVariable v = (CorrelatedVariable) super.clone();
119     v.variable = (Variable) variable.clone();
120     return v;
121   }
122
123   public String JavaDoc toString() {
124     return "CORRELATED: " + getVariable() + " = " + getEvalResult();
125   }
126
127 }
128
Popular Tags