View Javadoc

1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.tuigwaa.database.function.criteria;
17  
18  public class SubcriteriaFunction extends AbstractCriteriaFunction {
19  
20  	private CriteriaFunction sequentialFunction_;
21  
22  	public SubcriteriaFunction() {
23  		super();
24  	}
25  
26  	public SubcriteriaFunction(String field) {
27  		super(field);
28  	}
29  
30  	public SubcriteriaFunction(String field, CriteriaFunction sequentialFunction) {
31  		super(field);
32  		setSequentialFunction(sequentialFunction);
33  	}
34  
35  	public void setSequentialFunction(CriteriaFunction function) {
36  		this.sequentialFunction_ = function;
37  	}
38  
39  	public CriteriaFunction getSequentialFunction() {
40  		return sequentialFunction_;
41  	}
42  
43  	public Object evaluate(ICriteria criteria) {
44  		ICriteria subcriteria = criteria.createCriteria(getField());
45  		((UnaryCriteriaFunction) sequentialFunction_).evaluate(subcriteria);
46  		return criteria;
47  	}
48  
49  	public Object evaluate(ICriteria criteria, Object value) {
50  		if (value == null || "".equals(value)) {
51  			return criteria;
52  		}
53  		ICriteria subcriteria = criteria.createCriteria(getField());
54  		((BinaryCriteriaFunction) sequentialFunction_).evaluate(subcriteria,
55  				value);
56  		return criteria;
57  	}
58  
59  	public String getNestedAttrName() {
60  		String childAttrName = null;
61  		if (sequentialFunction_ instanceof SubcriteriaFunction) {
62  			childAttrName = ((SubcriteriaFunction) sequentialFunction_)
63  					.getNestedAttrName();
64  		} else {
65  			childAttrName = sequentialFunction_.getField();
66  		}
67  		return getField() + "." + childAttrName;
68  	}
69  }