KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mckoi > database > interpret > SearchExpression


1 /**
2  * com.mckoi.database.interpret.SearchExpression 09 Sep 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.interpret;
26
27 import com.mckoi.database.*;
28 import java.util.*;
29
30 /**
31  * Search expression is a form of an Expression that is split up into
32  * component parts that can be easily formed into a search query.
33  *
34  * @author Tobias Downer
35  */

36
37 public final class SearchExpression
38             implements java.io.Serializable JavaDoc, StatementTreeObject, Cloneable JavaDoc {
39
40   static final long serialVersionUID = 2888486150597671440L;
41
42   /**
43    * The originating expression.
44    */

45   private Expression search_expression;
46
47   /**
48    * Sets this search expression from the given expression.
49    */

50   public void setFromExpression(Expression expression) {
51     this.search_expression = expression;
52   }
53
54   /**
55    * Returns the search expression as an Expression object.
56    */

57   public Expression getFromExpression() {
58     return search_expression;
59   }
60
61   /**
62    * Concatinates a new expression to the end of this expression and uses the
63    * 'AND' operator to seperate the expressions. This is very useful for
64    * adding new logical conditions to the expression at runtime.
65    */

66   void appendExpression(Expression expression) {
67     if (search_expression == null) {
68       search_expression = expression;
69     }
70     else {
71       search_expression = new Expression(search_expression,
72                                          Operator.get("and"), expression);
73     }
74   }
75
76
77 // /**
78
// * Given a SelectStatement, this will resolve all the conditions found in
79
// * this expression (reversively) to their proper full name. If any
80
// * ambiguity is found then an error is thrown.
81
// */
82
// void resolveColumnNames(Statement statement) {
83
// if (search_expression != null) {
84
// statement.resolveExpression(search_expression);
85
// }
86
// }
87
//
88
// /**
89
// * Evaluates the search expression.
90
// */
91
// TableSet evaluate(TableSet table_in, JoiningSet join_set) {
92
// // Evalute the expression as a set of logical parts.
93
// table_in.logicalEvaluate(search_expression, join_set);
94
// return table_in;
95
// }
96

97   /**
98    * Prepares the expression.
99    */

100   public void prepare(ExpressionPreparer preparer) throws DatabaseException {
101     if (search_expression != null) {
102       search_expression.prepare(preparer);
103     }
104   }
105
106   /**
107    * Returns all the Elements from all expressions in this condition tree.
108    */

109   List allElements() {
110     if (search_expression != null) {
111       return search_expression.allElements();
112     }
113     else {
114       return new ArrayList();
115     }
116   }
117
118   // Implemented from StatementTreeObject
119
public void prepareExpressions(ExpressionPreparer preparer)
120                                                   throws DatabaseException {
121     prepare(preparer);
122   }
123
124   public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
125     SearchExpression v = (SearchExpression) super.clone();
126     if (search_expression != null) {
127       v.search_expression = (Expression) search_expression.clone();
128     }
129     return v;
130   }
131
132   public String JavaDoc toString() {
133     if (search_expression != null) {
134       return search_expression.toString();
135     }
136     else {
137       return "NO SEARCH EXPRESSION";
138     }
139   }
140
141 }
142
Popular Tags