KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > entity > condition > EntityWhereString


1 /*
2  * $Id: EntityWhereString.java 5831 2005-09-26 06:52:24Z jonesde $
3  *
4  * Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * 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  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * 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.util.List JavaDoc;
28 import java.util.Map JavaDoc;
29
30 import org.ofbiz.base.util.Debug;
31 import org.ofbiz.entity.EntityCryptoException;
32 import org.ofbiz.entity.GenericDelegator;
33 import org.ofbiz.entity.GenericModelException;
34 import org.ofbiz.entity.GenericEntity;
35 import org.ofbiz.entity.model.ModelEntity;
36 import org.ofbiz.entity.model.ModelField;
37
38 /**
39  * <p>Encapsulates SQL expressions used for where clause snippets.
40  * NOTE: This is UNSAFE and BREAKS the idea behind the Entity Engine where
41  * you avoid directly specifying SQL. So, KEEP IT MINIMAL and preferrably replace
42  * it when the feature you are getting at is implemented in a more automatic way for you.</p>
43  *
44  * <p>By minimal I mean use this in conjunction with other EntityConditions like the
45  * EntityExpr, EntityConditionList and EntityFieldMap objects which more cleanly
46  * encapsulate where conditions and don't require you to directly write SQL.</p>
47  *
48  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
49  * @version $Rev: 5831 $
50  * @since 2.0
51  */

52 public class EntityWhereString extends EntityCondition {
53
54     protected String JavaDoc sqlString;
55
56     protected EntityWhereString() {}
57
58     public EntityWhereString(String JavaDoc sqlString) {
59         this.sqlString = sqlString;
60     }
61
62     public String JavaDoc makeWhereString(ModelEntity modelEntity, List JavaDoc entityConditionParams) {
63         return sqlString;
64     }
65
66     public void checkCondition(ModelEntity modelEntity) throws GenericModelException {// no nothing, this is always assumed to be fine... could do funky SQL syntax checking, but hey this is a HACK anyway
67
}
68
69     public boolean entityMatches(GenericEntity entity) {
70         throw new UnsupportedOperationException JavaDoc("Cannot do entityMatches on a WhereString, ie no SQL evaluation in EE; Where String is: " + sqlString);
71     }
72
73     public boolean mapMatches(GenericDelegator delegator, Map JavaDoc map) {
74         throw new UnsupportedOperationException JavaDoc("Cannot do mapMatches on a WhereString, ie no SQL evaluation in EE; Where String is: " + sqlString);
75     }
76
77     public String JavaDoc getWhereString() {
78         return sqlString;
79     }
80
81     public EntityCondition freeze() {
82         return this;
83     }
84
85     public void encryptConditionFields(ModelEntity modelEntity, GenericDelegator delegator) {
86         // nothing to do here...
87
}
88
89     public void visit(EntityConditionVisitor visitor) {
90         visitor.acceptEntityWhereString(this);
91     }
92
93     public boolean equals(Object JavaDoc obj) {
94         if (!(obj instanceof EntityWhereString)) return false;
95         EntityWhereString other = (EntityWhereString) obj;
96         return equals(sqlString, other.sqlString);
97     }
98
99     public int hashCode() {
100         return hashCode(sqlString);
101     }
102 }
103
Popular Tags