KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > store > impl > rdbms > expression > RDBMSMergeExpression


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/expression/RDBMSMergeExpression.java,v 1.4.2.1 2004/09/27 12:54:00 unico Exp $
3  * $Revision: 1.4.2.1 $
4  * $Date: 2004/09/27 12:54:00 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2004 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23 package org.apache.slide.store.impl.rdbms.expression;
24
25 import java.util.Collection JavaDoc;
26 import java.util.Iterator JavaDoc;
27
28 import org.apache.slide.search.BadQueryException;
29 import org.apache.slide.search.SearchException;
30 import org.apache.slide.search.basic.IBasicExpression;
31 import org.apache.slide.search.basic.IBasicResultSet;
32
33 /**
34  */

35 public class RDBMSMergeExpression extends RDBMSExpression {
36
37     private final String JavaDoc _name;
38     private final String JavaDoc _namespace;
39     private final Collection JavaDoc _rdbmsExpressions;
40     private final Collection JavaDoc _otherExpressions;
41
42     public RDBMSMergeExpression(String JavaDoc name,
43                                 String JavaDoc namespace,
44                                 RDBMSQueryContext context,
45                                 Collection JavaDoc rdbmsExpressions,
46                                 Collection JavaDoc otherExpressions) throws BadQueryException {
47         super(context);
48         _name = name;
49         _namespace = namespace;
50         _rdbmsExpressions = rdbmsExpressions;
51         _otherExpressions = otherExpressions;
52     }
53
54     public IBasicResultSet execute() throws SearchException {
55         return compile(null);
56     }
57     
58     protected IBasicResultSet compile(RDBMSMergeExpression expression) throws SearchException {
59         if (_rdbmsExpressions != null && _rdbmsExpressions.size() > 0) {
60             _context.criteria().add(" ( ");
61             Iterator JavaDoc iter = _rdbmsExpressions.iterator();
62             while (iter.hasNext()) {
63                 ((RDBMSExpression) iter.next()).compile(this);
64                 if (iter.hasNext()) {
65                     _context.criteria().add(" " + _name + " ");
66                 }
67             }
68             _context.criteria().add(" ) ");
69         }
70         if (_otherExpressions != null) {
71             IBasicExpression merger = _factory.createStandardMergeExpression(
72                     _name, _namespace, _otherExpressions);
73             return merger.execute();
74         }
75         return _context.results();
76     }
77     
78     protected String JavaDoc getName() {
79         return _name;
80     }
81
82     protected Collection JavaDoc getRDBMSExpressions() {
83         return _rdbmsExpressions;
84     }
85
86 }
Popular Tags