Source Code Cross Referenced for GenericHelperDAO.java in  » ERP-CRM-Financial » ofbiz » org » ofbiz » entity » datasource » 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.entity.datasource 
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.entity.datasource;
019:
020:        import java.util.Collection;
021:        import java.util.Iterator;
022:        import java.util.LinkedList;
023:        import java.util.List;
024:        import java.util.Map;
025:        import java.util.Set;
026:
027:        import org.ofbiz.base.util.Debug;
028:        import org.ofbiz.entity.GenericEntityException;
029:        import org.ofbiz.entity.GenericPK;
030:        import org.ofbiz.entity.GenericValue;
031:        import org.ofbiz.entity.condition.EntityCondition;
032:        import org.ofbiz.entity.model.ModelEntity;
033:        import org.ofbiz.entity.model.ModelRelation;
034:        import org.ofbiz.entity.util.EntityFindOptions;
035:        import org.ofbiz.entity.util.EntityListIterator;
036:
037:        /**
038:         * Generic Entity Helper Class
039:         *
040:         */
041:        public class GenericHelperDAO implements  GenericHelper {
042:
043:            public static final String module = GenericHelperDAO.class
044:                    .getName();
045:
046:            protected GenericDAO genericDAO;
047:            protected String helperName;
048:
049:            public GenericHelperDAO(String helperName) {
050:                this .helperName = helperName;
051:                genericDAO = GenericDAO.getGenericDAO(helperName);
052:            }
053:
054:            public String getHelperName() {
055:                return helperName;
056:            }
057:
058:            /** Creates a Entity in the form of a GenericValue and write it to the database
059:             *@return GenericValue instance containing the new instance
060:             */
061:            public GenericValue create(GenericValue value)
062:                    throws GenericEntityException {
063:                if (value == null) {
064:                    return null;
065:                }
066:                int retVal = genericDAO.insert(value);
067:                if (Debug.verboseOn())
068:                    Debug.logVerbose("Insert Return Value : " + retVal, module);
069:                return value;
070:            }
071:
072:            /** Find a Generic Entity by its Primary Key
073:             *@param primaryKey The primary key to find by.
074:             *@return The GenericValue corresponding to the primaryKey
075:             */
076:            public GenericValue findByPrimaryKey(GenericPK primaryKey)
077:                    throws GenericEntityException {
078:                if (primaryKey == null) {
079:                    return null;
080:                }
081:                GenericValue genericValue = GenericValue.create(primaryKey);
082:
083:                genericDAO.select(genericValue);
084:                return genericValue;
085:            }
086:
087:            /** Find a Generic Entity by its Primary Key and only returns the values requested by the passed keys (names)
088:             *@param primaryKey The primary key to find by.
089:             *@param keys The keys, or names, of the values to retrieve; only these values will be retrieved
090:             *@return The GenericValue corresponding to the primaryKey
091:             */
092:            public GenericValue findByPrimaryKeyPartial(GenericPK primaryKey,
093:                    Set keys) throws GenericEntityException {
094:                if (primaryKey == null) {
095:                    return null;
096:                }
097:                GenericValue genericValue = GenericValue.create(primaryKey);
098:
099:                genericDAO.partialSelect(genericValue, keys);
100:                return genericValue;
101:            }
102:
103:            /** Find a number of Generic Value objects by their Primary Keys, all at once
104:             * This is done here for the DAO GenericHelper; for a client-server helper it
105:             * would be done on the server side to reduce network round trips.
106:             *@param primaryKeys A List of primary keys to find by.
107:             *@return List of GenericValue objects corresponding to the passed primaryKey objects
108:             */
109:            public List findAllByPrimaryKeys(List primaryKeys)
110:                    throws GenericEntityException {
111:                if (primaryKeys == null)
112:                    return null;
113:                List results = new LinkedList();
114:
115:                Iterator pkiter = primaryKeys.iterator();
116:
117:                while (pkiter.hasNext()) {
118:                    GenericPK primaryKey = (GenericPK) pkiter.next();
119:                    GenericValue result = this .findByPrimaryKey(primaryKey);
120:
121:                    if (result != null)
122:                        results.add(result);
123:                }
124:                return results;
125:            }
126:
127:            /** Remove a Generic Entity corresponding to the primaryKey
128:             *@param  primaryKey  The primary key of the entity to remove.
129:             *@return int representing number of rows effected by this operation
130:             */
131:            public int removeByPrimaryKey(GenericPK primaryKey)
132:                    throws GenericEntityException {
133:                if (primaryKey == null)
134:                    return 0;
135:                if (Debug.verboseOn())
136:                    Debug.logVerbose("Removing GenericPK: "
137:                            + primaryKey.toString(), module);
138:                return genericDAO.delete(primaryKey);
139:            }
140:
141:            /** Finds GenericValues by the conditions specified in the EntityCondition object, the the EntityCondition javadoc for more details.
142:             *@param modelEntity The ModelEntity of the Entity as defined in the entity XML file
143:             *@param whereEntityCondition The EntityCondition object that specifies how to constrain this query before any groupings are done (if this is a view entity with group-by aliases)
144:             *@param havingEntityCondition The EntityCondition object that specifies how to constrain this query after any groupings are done (if this is a view entity with group-by aliases)
145:             *@param fieldsToSelect The fields of the named entity to get from the database; if empty or null all fields will be retreived
146:             *@param orderBy The fields of the named entity to order the query by; optionally add a " ASC" for ascending or " DESC" for descending
147:             *@param findOptions An instance of EntityFindOptions that specifies advanced query options. See the EntityFindOptions JavaDoc for more details.
148:             *@return EntityListIterator representing the result of the query: NOTE THAT THIS MUST BE CLOSED WHEN YOU ARE
149:             *      DONE WITH IT, AND DON'T LEAVE IT OPEN TOO LONG BEACUSE IT WILL MAINTAIN A DATABASE CONNECTION.
150:             */
151:            public EntityListIterator findListIteratorByCondition(
152:                    ModelEntity modelEntity,
153:                    EntityCondition whereEntityCondition,
154:                    EntityCondition havingEntityCondition,
155:                    Collection fieldsToSelect, List orderBy,
156:                    EntityFindOptions findOptions)
157:                    throws GenericEntityException {
158:                return genericDAO.selectListIteratorByCondition(modelEntity,
159:                        whereEntityCondition, havingEntityCondition,
160:                        fieldsToSelect, orderBy, findOptions);
161:            }
162:
163:            public List findByMultiRelation(GenericValue value,
164:                    ModelRelation modelRelationOne, ModelEntity modelEntityOne,
165:                    ModelRelation modelRelationTwo, ModelEntity modelEntityTwo,
166:                    List orderBy) throws GenericEntityException {
167:                return genericDAO.selectByMultiRelation(value,
168:                        modelRelationOne, modelEntityOne, modelRelationTwo,
169:                        modelEntityTwo, orderBy);
170:            }
171:
172:            public long findCountByCondition(ModelEntity modelEntity,
173:                    EntityCondition whereEntityCondition,
174:                    EntityCondition havingEntityCondition,
175:                    EntityFindOptions findOptions)
176:                    throws GenericEntityException {
177:                return genericDAO.selectCountByCondition(modelEntity,
178:                        whereEntityCondition, havingEntityCondition,
179:                        findOptions);
180:            }
181:
182:            /** Removes/deletes Generic Entity records found by all the specified condition
183:             *@param modelEntity The ModelEntity of the Entity as defined in the entity XML file
184:             *@param condition The condition that restricts the list of removed values
185:             *@return int representing number of rows effected by this operation
186:             */
187:            public int removeByCondition(ModelEntity modelEntity,
188:                    EntityCondition condition) throws GenericEntityException {
189:                if (modelEntity == null || condition == null) {
190:                    return 0;
191:                }
192:                return genericDAO.deleteByCondition(modelEntity, condition);
193:            }
194:
195:            /** Store the Entity from the GenericValue to the persistent store
196:             *@param value GenericValue instance containing the entity
197:             *@return int representing number of rows effected by this operation
198:             */
199:            public int store(GenericValue value) throws GenericEntityException {
200:                if (value == null) {
201:                    return 0;
202:                }
203:                return genericDAO.update(value);
204:            }
205:
206:            /** Updates a group of values in a single pass.
207:             *@param modelEntity The ModelEntity of the Entity as defined in the entity XML file
208:             *@param fieldsToSet The fields of the named entity to set in the database
209:             *@param condition The condition that restricts the list of removed values
210:             *@return int representing number of rows effected by this operation
211:             *@throws GenericEntityException
212:             */
213:            public int storeByCondition(ModelEntity modelEntity,
214:                    Map fieldsToSet, EntityCondition condition)
215:                    throws GenericEntityException {
216:                if (modelEntity == null || condition == null) {
217:                    return 0;
218:                }
219:                return genericDAO.updateByCondition(modelEntity, fieldsToSet,
220:                        condition);
221:            }
222:
223:            /** Check the datasource to make sure the entity definitions are correct, optionally adding missing entities or fields on the server
224:             *@param modelEntities Map of entityName names and ModelEntity values
225:             *@param messages List to put any result messages in
226:             *@param addMissing Flag indicating whether or not to add missing entities and fields on the server
227:             */
228:            public void checkDataSource(Map modelEntities, List messages,
229:                    boolean addMissing) throws GenericEntityException {
230:                genericDAO.checkDb(modelEntities, messages, addMissing);
231:            }
232:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.