Source Code Cross Referenced for BaseEntityCondExprBldr.java in  » ERP-CRM-Financial » ofbiz » org » ofbiz » shark » expression » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » ofbiz » org.ofbiz.shark.expression 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements.  See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership.  The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License.  You may obtain a copy of the License at
009:         * 
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied.  See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         *******************************************************************************/package org.ofbiz.shark.expression;
019:
020:        import java.io.Serializable;
021:        import java.util.ArrayList;
022:        import java.util.HashMap;
023:        import java.util.Iterator;
024:        import java.util.List;
025:        import java.util.Map;
026:
027:        import org.apache.commons.collections.map.LinkedMap;
028:        import org.enhydra.shark.api.common.ExpressionBuilder;
029:        import org.ofbiz.base.util.StringUtil;
030:        import org.ofbiz.base.util.UtilMisc;
031:        import org.ofbiz.base.util.UtilObject;
032:        import org.ofbiz.entity.GenericDelegator;
033:        import org.ofbiz.entity.GenericEntityException;
034:        import org.ofbiz.entity.util.EntityListIterator;
035:        import org.ofbiz.entity.condition.EntityCondition;
036:        import org.ofbiz.entity.condition.EntityConditionList;
037:        import org.ofbiz.entity.condition.EntityOperator;
038:        import org.ofbiz.entity.model.DynamicViewEntity;
039:        import org.ofbiz.shark.container.SharkContainer;
040:
041:        public abstract class BaseEntityCondExprBldr implements 
042:                ExpressionBuilder, Serializable {
043:
044:            public static final String module = BaseEntityCondExprBldr.class
045:                    .getName();
046:
047:            protected EntityCondition condition = null;
048:            protected Map entityNames = new LinkedMap();
049:            protected Map fieldNames = new LinkedMap();
050:            protected List autoFields = new ArrayList();
051:            protected List viewLinks = new ArrayList();
052:
053:            protected boolean isOrSet = false;
054:            protected boolean isNotSet = false;
055:            protected boolean isComplete = true;
056:
057:            // ExpressionBuilder Methods
058:
059:            public boolean isComplete() {
060:                return this .isComplete;
061:            }
062:
063:            public String toSQL() {
064:                return BaseEntityCondExprBldr.getHexString(this );
065:            }
066:
067:            public String toScript() {
068:                return "";
069:            }
070:
071:            public String toExpression() {
072:                StringBuffer ret = new StringBuffer();
073:                if (!this .isComplete()) {
074:                    ret.append("/*FORCE*/\n");
075:                }
076:
077:                ret.append(this .toScript());
078:                ret.append("\n/*sql ").append(this .toSQL()).append(" sql*/");
079:
080:                return ret.toString();
081:            }
082:
083:            // Special Purpose Methods
084:
085:            public EntityCondition getCondition() {
086:                return this .condition;
087:            }
088:
089:            public List runQuery() throws GenericEntityException {
090:                GenericDelegator delegator = this .getDelegator();
091:                DynamicViewEntity view = this .makeView();
092:                EntityListIterator eli = null;
093:                List result = null;
094:                try {
095:                    eli = delegator.findListIteratorByCondition(view, this 
096:                            .getCondition(), null, null, null, null);
097:                    result = eli.getCompleteList();
098:                } catch (GenericEntityException e) {
099:                    throw e;
100:                } finally {
101:                    eli.close();
102:                }
103:                return result;
104:            }
105:
106:            protected void setNot(boolean not) {
107:                this .isNotSet = not;
108:            }
109:
110:            protected void setOr(boolean or) {
111:                this .isOrSet = or;
112:            }
113:
114:            protected void addCondition(EntityCondition current) {
115:                if (condition == null) {
116:                    condition = current;
117:                } else {
118:                    List condList = UtilMisc.toList(condition, current);
119:                    if (this .isOrSet) {
120:                        condition = new EntityConditionList(condList,
121:                                EntityOperator.OR);
122:                    } else {
123:                        condition = new EntityConditionList(condList,
124:                                EntityOperator.AND);
125:                    }
126:                }
127:                // reset the NOT value
128:                this .setNot(false);
129:            }
130:
131:            protected synchronized void addEntity(String alias, String entity) {
132:                entityNames.put(alias, entity);
133:            }
134:
135:            protected synchronized void addField(String entityAlias,
136:                    String fieldName, String fieldAlias) {
137:                Map fieldAliasMap = (Map) fieldNames.get(entityAlias);
138:                if (fieldAliasMap == null) {
139:                    fieldAliasMap = new HashMap();
140:                    fieldNames.put(entityAlias, fieldAliasMap);
141:                }
142:                fieldAliasMap.put(fieldName, fieldAlias);
143:            }
144:
145:            protected synchronized void addAllFields(String entityAlias) {
146:                autoFields.add(entityAlias);
147:            }
148:
149:            protected synchronized void addLink(String entityAlias,
150:                    String relEntityAlias, boolean opt, List keyMap) {
151:                this .viewLinks.add(new ViewLink(entityAlias, relEntityAlias,
152:                        opt, keyMap));
153:            }
154:
155:            protected GenericDelegator getDelegator() {
156:                return SharkContainer.getDelegator();
157:            }
158:
159:            private DynamicViewEntity makeView() {
160:                DynamicViewEntity view = new DynamicViewEntity();
161:
162:                // create the members
163:                Iterator eni = this .entityNames.entrySet().iterator();
164:                while (eni.hasNext()) {
165:                    Map.Entry entry = (Map.Entry) eni.next();
166:                    view.addMemberEntity((String) entry.getKey(),
167:                            (String) entry.getValue());
168:                }
169:
170:                // set alias all fields
171:                Iterator aai = autoFields.iterator();
172:                while (aai.hasNext()) {
173:                    String alias = (String) aai.next();
174:                    view.addAliasAll(alias, "");
175:                }
176:
177:                // create the other field aliases
178:                Iterator fni = fieldNames.keySet().iterator();
179:                while (fni.hasNext()) {
180:                    String entityAlias = (String) fni.next();
181:                    Map fieldMap = (Map) fieldNames.get(entityAlias);
182:                    Iterator fmi = fieldMap.entrySet().iterator();
183:                    while (fmi.hasNext()) {
184:                        Map.Entry entry = (Map.Entry) fmi.next();
185:                        view
186:                                .addAlias(entityAlias, (String) entry
187:                                        .getValue(), (String) entry.getKey(),
188:                                        null, null, null, null);
189:                    }
190:                }
191:
192:                // add the view links
193:                Iterator vli = this .viewLinks.iterator();
194:                while (vli.hasNext()) {
195:                    ViewLink vl = (ViewLink) vli.next();
196:                    view.addViewLink(vl.entityAlias, vl.relEntityAlias,
197:                            new Boolean(vl.relOptional), vl.keyMaps);
198:                }
199:
200:                return view;
201:            }
202:
203:            // Standard Static Serialization Methods
204:
205:            public static String getHexString(BaseEntityCondExprBldr builder) {
206:                byte[] builderBytes = UtilObject.getBytes(builder);
207:                return StringUtil.toHexString(builderBytes);
208:            }
209:
210:            public static BaseEntityCondExprBldr getBuilder(String hexString) {
211:                byte[] builderBytes = StringUtil.fromHexString(hexString);
212:                return (BaseEntityCondExprBldr) UtilObject
213:                        .getObject(builderBytes);
214:            }
215:
216:            class ViewLink implements  Serializable {
217:
218:                public String entityAlias;
219:                public String relEntityAlias;
220:                public boolean relOptional = false;
221:                public List keyMaps = new ArrayList();
222:
223:                public ViewLink(String entityAlias, String relEntityAlias,
224:                        boolean optional, List keyMaps) {
225:                    this.entityAlias = entityAlias;
226:                    this.relEntityAlias = relEntityAlias;
227:                    this.relOptional = optional;
228:                    this.keyMaps = keyMaps;
229:                }
230:            }
231:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.