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;
17  
18  import org.seasar.tuigwaa.database.function.criteria.CriteriaFunction;
19  import org.seasar.tuigwaa.database.function.criteria.CriteriaListFunction;
20  import org.seasar.tuigwaa.database.function.criteria.ICriteria;
21  import org.seasar.tuigwaa.database.function.criteria.SearchCriteriaFunction;
22  
23  import com.isenshi.util.functor.UnaryFunction;
24  
25  public class SearchExeFunction extends AbstractCriteriaExeFunction implements
26  		UnaryFunction {
27  
28  	private CriteriaListFunction criteriaListFunction;
29  
30  	public void setCriteriaListFunction(
31  			CriteriaListFunction criteriaListFunction) {
32  		this.criteriaListFunction = criteriaListFunction;
33  	}
34  
35  	public CriteriaListFunction getCriteriaListFunction() {
36  		return criteriaListFunction;
37  	}
38  
39  	public SearchCriteriaFunction createCriteriaFunction(Object dto){
40  		return new SearchCriteriaFunction(criteriaListFunction, dto);
41  	}
42  	
43  	public Object evaluate(Object dto) {
44  		return evaluate(dto, null);
45  	}
46  
47  	public Object evaluate(Object dto, Object extraCriteria) {
48  		ICriteria criteria = createHibernateCriteria();
49  		criteria = (ICriteria) getCriteriaListFunction()
50  				.evaluate(criteria, dto);
51  		if (extraCriteria != null) {
52  			criteria = (ICriteria) ((CriteriaFunction) extraCriteria)
53  					.evaluate(criteria);
54  		}
55  		return criteria.list();
56  	}
57  	
58  	
59  }