01: /*
02: * $Id: EntityCondition.java,v 1.4 2003/11/07 00:33:56 jonesde Exp $
03: *
04: * <p>Copyright (c) 2001 The Open For Business Project - www.ofbiz.org
05: *
06: * <p>Permission is hereby granted, free of charge, to any person obtaining a
07: * copy of this software and associated documentation files (the "Software"),
08: * to deal in the Software without restriction, including without limitation
09: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10: * and/or sell copies of the Software, and to permit persons to whom the
11: * Software is furnished to do so, subject to the following conditions:
12: *
13: * <p>The above copyright notice and this permission notice shall be included
14: * in all copies or substantial portions of the Software.
15: *
16: * <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23: */
24:
25: package org.ofbiz.entity.condition;
26:
27: import java.io.Serializable;
28: import java.util.List;
29: import java.util.ArrayList;
30:
31: import org.ofbiz.entity.GenericModelException;
32: import org.ofbiz.entity.GenericEntity;
33: import org.ofbiz.entity.jdbc.SqlJdbcUtil;
34: import org.ofbiz.entity.model.ModelEntity;
35: import org.ofbiz.entity.model.ModelField;
36:
37: /**
38: * Represents the conditions to be used to constrain a query
39: * <br>An EntityCondition can represent various type of constraints, including:
40: * <ul>
41: * <li>EntityConditionList: a list of EntityConditions, combined with the operator specified
42: * <li>EntityExpr: for simple expressions or expressions that combine EntityConditions
43: * <li>EntityFieldMap: a map of fields where the field (key) equals the value, combined with the operator specified
44: * </ul>
45: * These can be used in various combinations using the EntityConditionList and EntityExpr objects.
46: *
47: * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
48: * @version $Revision: 1.4 $
49: * @since 2.0
50: */
51: public abstract class EntityCondition implements Serializable {
52: protected ModelField getField(ModelEntity modelEntity,
53: String fieldName) {
54: ModelField modelField = null;
55: if (modelEntity != null) {
56: modelField = (ModelField) modelEntity.getField(fieldName);
57: }
58: return modelField;
59: }
60:
61: protected String getColName(ModelField modelField, String fieldName) {
62: String colName = null;
63: if (modelField != null) {
64: colName = modelField.getColName();
65: } else {
66: colName = (String) fieldName;
67: }
68: return colName;
69: }
70:
71: protected void addValue(StringBuffer buffer, ModelField field,
72: Object value, List params) {
73: SqlJdbcUtil.addValue(buffer, params == null ? null : field,
74: value, params);
75: }
76:
77: public String toString() {
78: return makeWhereString(null, new ArrayList());
79: }
80:
81: abstract public String makeWhereString(ModelEntity modelEntity,
82: List entityConditionParams);
83:
84: abstract public void checkCondition(ModelEntity modelEntity)
85: throws GenericModelException;
86:
87: abstract public boolean entityMatches(GenericEntity entity);
88: }
|