Source Code Cross Referenced for EntityHelper.java in  » ERP-CRM-Financial » SourceTap-CRM » com » sourcetap » sfa » util » 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 » SourceTap CRM » com.sourcetap.sfa.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * 
003:         * Copyright (c) 2004 SourceTap - www.sourcetap.com
004:         *
005:         *  The contents of this file are subject to the SourceTap Public License 
006:         * ("License"); You may not use this file except in compliance with the 
007:         * License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
008:         * Software distributed under the License is distributed on an  "AS IS"  basis,
009:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
010:         * the specific language governing rights and limitations under the License.
011:         *
012:         * The above copyright notice and this permission notice shall be included
013:         * in all copies or substantial portions of the Software.
014:         *
015:         */
016:
017:        package com.sourcetap.sfa.util;
018:
019:        import java.util.ArrayList;
020:        import java.util.Iterator;
021:        import java.util.List;
022:        import java.util.Map;
023:
024:        import org.ofbiz.base.util.Debug;
025:        import org.ofbiz.entity.GenericDelegator;
026:        import org.ofbiz.entity.GenericEntityException;
027:        import org.ofbiz.entity.GenericValue;
028:        import org.ofbiz.entity.condition.EntityCondition;
029:        import org.ofbiz.entity.model.DynamicViewEntity;
030:        import org.ofbiz.entity.model.ModelEntity;
031:        import org.ofbiz.entity.model.ModelField;
032:        import org.ofbiz.entity.model.ModelViewEntity;
033:        import org.ofbiz.entity.util.EntityFindOptions;
034:        import org.ofbiz.entity.util.EntityListIterator;
035:
036:        /**
037:         * @author Steve Fowler
038:         *	
039:         *
040:         *
041:         */
042:        public class EntityHelper {
043:
044:            public static final String module = EntityHelper.class.getName();
045:
046:            /**
047:             * Create a dynamic view entity using the specified entity as the source.  This can be used
048:             * as a starting point when building a dynamic view with most fields from a single entity.
049:             * All fields from the specified entity will be added to the view entity.  Other entities
050:             * and fields can be added to the returned dynamic view
051:             * @param modelEntiy Primary Entity to be used to create the dynamic view entity.
052:             * @return a dynamic view entity that is based on the specified modelEntity
053:             */
054:            public static DynamicViewEntity createDynamicViewEntity(
055:                    GenericDelegator delegator, String entityName) {
056:                try {
057:                    ModelEntity modelEntity = delegator.getModelReader()
058:                            .getModelEntity(entityName);
059:                    return createDynamicViewEntity(delegator, modelEntity);
060:                } catch (Exception e) {
061:                    Debug.logError(e, module);
062:                    throw new IllegalArgumentException(
063:                            "Error finding Entity with name " + entityName
064:                                    + " for createDynamicViewEntity");
065:                }
066:            }
067:
068:            /**
069:             * Create a dynamic view entity using the specified entity as the source.  This can be used
070:             * as a starting point when building a dynamic view with most fields from a single entity.
071:             * All fields from the specified entity will be added to the view entity.  Other entities
072:             * and fields can be added to the returned dynamic view
073:             * @param modelEntiy Primary Entity to be used to create the dynamic view entity.
074:             * @return a dynamic view entity that is based on the specified modelEntity
075:             */
076:            public static DynamicViewEntity createDynamicViewEntity(
077:                    GenericDelegator delegator, ModelEntity modelEntity) {
078:                String entityName = modelEntity.getEntityName();
079:                DynamicViewEntity dve = new DynamicViewEntity();
080:                dve.addMemberEntity(entityName, entityName);
081:
082:                Iterator modelFieldIter = modelEntity.getFieldsIterator();
083:                while (modelFieldIter.hasNext()) {
084:                    ModelField modelField = (ModelField) modelFieldIter.next();
085:                    dve.addAlias(entityName, modelField.getName(), null, null,
086:                            Boolean.valueOf(modelField.getIsPk()), null, null);
087:                }
088:
089:                return dve;
090:            }
091:
092:            public static List findByCondition(GenericDelegator delegator,
093:                    DynamicViewEntity dve, EntityCondition condition,
094:                    List orderBy) throws GenericEntityException {
095:                ModelViewEntity mve = dve.makeModelViewEntity(delegator);
096:                List fields = mve.getAllFieldNames();
097:                EntityListIterator eliOne = delegator
098:                        .findListIteratorByCondition(dve, condition, null,
099:                                fields, orderBy, null);
100:                List valueList = eliOne.getCompleteList();
101:                eliOne.close();
102:                return valueList;
103:            }
104:
105:            public static EntityListIterator findIteratorByCondition(
106:                    GenericDelegator delegator, DynamicViewEntity dve,
107:                    EntityCondition condition, List orderBy)
108:                    throws GenericEntityException {
109:                return findIteratorByCondition(delegator, dve, condition, null,
110:                        orderBy);
111:            }
112:
113:            public static EntityListIterator findIteratorByCondition(
114:                    GenericDelegator delegator, DynamicViewEntity dve,
115:                    EntityCondition condition, List selectFields, List orderBy)
116:                    throws GenericEntityException {
117:                EntityListIterator eliOne = delegator
118:                        .findListIteratorByCondition(
119:                                dve,
120:                                condition,
121:                                null,
122:                                selectFields,
123:                                orderBy,
124:                                new EntityFindOptions(
125:                                        true,
126:                                        EntityFindOptions.TYPE_SCROLL_INSENSITIVE,
127:                                        EntityFindOptions.CONCUR_READ_ONLY,
128:                                        true));
129:                return eliOne;
130:            }
131:
132:            public static String getEntityOperator(int operatorId) {
133:                switch (operatorId) {
134:                case 1:
135:                    return "equals";
136:                case 2:
137:                    return "notEqual";
138:                case 3:
139:                    return "lessThan";
140:                case 4:
141:                    return "greaterThan";
142:                case 5:
143:                    return "lessThanEqualTo";
144:                case 6:
145:                    return "greaterThanEqualTo";
146:                case 7:
147:                    return "in";
148:                case 8:
149:                    return "between";
150:                case 9:
151:                    return "not";
152:                case 10:
153:                    return "and";
154:                case 11:
155:                    return "or";
156:                case 12:
157:                    return "like";
158:                case 13:
159:                    return "not-in";
160:                default:
161:                    throw new IllegalArgumentException(
162:                            "Unknown operator with Id:" + operatorId);
163:                }
164:            }
165:
166:            public static List findByClause(GenericDelegator delegator,
167:                    String mainEntityName, List entityClauses, Map fields,
168:                    List orderBy) {
169:                throw new RuntimeException(
170:                        "EntityHelper.findByClause is not implemented");
171:            }
172:
173:            public static GenericValue getPrimaryGVFromDynamicGV(
174:                    GenericDelegator delegator, GenericValue dynamicGV,
175:                    String primaryEntityName) {
176:                if (dynamicGV == null)
177:                    return null;
178:
179:                if (primaryEntityName.equals(dynamicGV.getEntityName()))
180:                    return dynamicGV;
181:
182:                GenericValue retValue = delegator.makeValidValue(
183:                        primaryEntityName, dynamicGV.getAllFields());
184:                return retValue;
185:            }
186:
187:            public static List getPrimaryGVLFromDynamicGVL(
188:                    GenericDelegator delegator, List dynamicGVL,
189:                    String primaryEntityName) {
190:                if (dynamicGVL == null)
191:                    return null;
192:
193:                Iterator dgvI = dynamicGVL.iterator();
194:                List list = new ArrayList();
195:
196:                while (dgvI.hasNext()) {
197:                    GenericValue gv = (GenericValue) dgvI.next();
198:                    list.add(getPrimaryGVFromDynamicGV(delegator, gv,
199:                            primaryEntityName));
200:
201:                }
202:                return list;
203:            }
204:
205:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.