01: /*******************************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: *******************************************************************************/package org.ofbiz.entity.condition;
19:
20: import java.util.ArrayList;
21: import java.util.List;
22: import java.util.Map;
23:
24: import javolution.util.FastList;
25:
26: import org.ofbiz.entity.GenericDelegator;
27: import org.ofbiz.entity.GenericModelException;
28: import org.ofbiz.entity.GenericEntity;
29: import org.ofbiz.entity.config.DatasourceInfo;
30: import org.ofbiz.entity.model.ModelEntity;
31:
32: /**
33: * Represents the conditions to be used to constrain a query
34: * <br/>An EntityCondition can represent various type of constraints, including:
35: * <ul>
36: * <li>EntityConditionList: a list of EntityConditions, combined with the operator specified
37: * <li>EntityExpr: for simple expressions or expressions that combine EntityConditions
38: * <li>EntityFieldMap: a map of fields where the field (key) equals the value, combined with the operator specified
39: * </ul>
40: * These can be used in various combinations using the EntityConditionList and EntityExpr objects.
41: *
42: */
43: public abstract class EntityCondition extends EntityConditionBase {
44:
45: public String toString() {
46: return makeWhereString(null, FastList.newInstance(), null);
47: }
48:
49: public void accept(EntityConditionVisitor visitor) {
50: throw new IllegalArgumentException(getClass().getName()
51: + ".accept not implemented");
52: }
53:
54: abstract public String makeWhereString(ModelEntity modelEntity,
55: List entityConditionParams, DatasourceInfo datasourceInfo);
56:
57: abstract public void checkCondition(ModelEntity modelEntity)
58: throws GenericModelException;
59:
60: public boolean entityMatches(GenericEntity entity) {
61: return mapMatches(entity.getDelegator(), entity);
62: }
63:
64: public Object eval(GenericEntity entity) {
65: return eval(entity.getDelegator(), entity);
66: }
67:
68: public Object eval(GenericDelegator delegator, Map map) {
69: return mapMatches(delegator, map) ? Boolean.TRUE
70: : Boolean.FALSE;
71: }
72:
73: abstract public boolean mapMatches(GenericDelegator delegator,
74: Map map);
75:
76: abstract public EntityCondition freeze();
77:
78: abstract public void encryptConditionFields(
79: ModelEntity modelEntity, GenericDelegator delegator);
80:
81: public void visit(EntityConditionVisitor visitor) {
82: throw new IllegalArgumentException(getClass().getName()
83: + ".visit not implemented");
84: }
85: }
|