01: /**********************************************************************
02: Copyright (c) 2002 Mike Martin (TJDO) and others. All rights reserved.
03: Licensed under the Apache License, Version 2.0 (the "License");
04: you may not use this file except in compliance with the License.
05: You may obtain a copy of the License at
06:
07: http://www.apache.org/licenses/LICENSE-2.0
08:
09: Unless required by applicable law or agreed to in writing, software
10: distributed under the License is distributed on an "AS IS" BASIS,
11: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: See the License for the specific language governing permissions and
13: limitations under the License.
14:
15:
16: Contributors:
17: 2003 Andy Jefferson - coding standards
18: 2004 Andy Jefferson - renamed from SubquerySetExpression
19: ...
20: **********************************************************************/package org.jpox.store.expression;
21:
22: import org.jpox.exceptions.JPOXUserException;
23:
24: /**
25: * An expression for collections whose contents are expressed as a SQL subquery.
26: *
27: * @version $Revision: 1.9 $
28: */
29: public class CollectionSubqueryExpression extends ScalarExpression {
30: private final QueryExpression subquery;
31:
32: /**
33: * Constructor.
34: * @param qs The main Query Statement
35: * @param subquery The subquery Query Statement.
36: **/
37: public CollectionSubqueryExpression(QueryExpression qs,
38: QueryExpression subquery) {
39: super (qs);
40:
41: this .subquery = subquery;
42:
43: if (subquery.getNumberOfScalarExpressions() != 1) {
44: throw new JPOXUserException(
45: "Cannot use as set expression, # of selected columns != 1. Subqueries must have at most 1 column: "
46: + subquery.toStatementText(false));
47: }
48:
49: st.append("(").append(subquery).append(')');
50: }
51:
52: /**
53: * Contains method
54: * @param expr the searched value represented by the expression
55: * @return boolean true expression if this Collection contains the element <code>expr</code>
56: */
57: public BooleanExpression containsMethod(ScalarExpression expr) {
58: return expr.in(this );
59: }
60:
61: /**
62: * isEmpty method
63: * @return boolean true expression if this Collection has no elements
64: */
65: public BooleanExpression isEmptyMethod() {
66: return new ExistsExpression(qs, subquery, false);
67: }
68: }
|