Source Code Cross Referenced for PBSessionBean.java in  » Database-ORM » db-ojb » org » apache » ojb » ejb » pb » 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 » Database ORM » db ojb » org.apache.ojb.ejb.pb 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.ojb.ejb.pb;
002:
003:        /* Copyright 2004-2005 The Apache Software Foundation
004:         *
005:         * Licensed under the Apache License, Version 2.0 (the "License");
006:         * you may not use this file except in compliance with the License.
007:         * You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        import javax.ejb.SessionBean;
019:        import javax.ejb.SessionContext;
020:        import java.util.Collection;
021:        import java.util.Iterator;
022:        import java.util.List;
023:
024:        import org.apache.ojb.broker.PersistenceBroker;
025:        import org.apache.ojb.broker.core.PersistenceBrokerFactoryFactory;
026:        import org.apache.ojb.broker.core.PersistenceBrokerFactoryIF;
027:        import org.apache.ojb.broker.query.Criteria;
028:        import org.apache.ojb.broker.query.Query;
029:        import org.apache.ojb.broker.query.QueryByCriteria;
030:        import org.apache.ojb.broker.util.logging.Logger;
031:        import org.apache.ojb.broker.util.logging.LoggerFactory;
032:        import org.apache.ojb.ejb.ArticleVO;
033:        import org.apache.ojb.ejb.PersonVO;
034:
035:        /**
036:         * This is an session bean implementation using PB-api.
037:         * <br>
038:         * For more structured implementations take a look at<br/>
039:         * {@link org.apache.ojb.ejb.SessionBeanImpl}<br/>
040:         * {@link org.apache.ojb.ejb.odmg.ODMGBaseBeanImpl}<br/>
041:         * {@link org.apache.ojb.ejb.pb.PBBaseBeanImpl}<br/>
042:         *
043:         * @ejb:bean
044:         * 			type="Stateless"
045:         * 			name="PBSessionBean"
046:         * 			jndi-name="org.apache.ojb.ejb.pb.PBSessionBean"
047:         * 			local-jndi-name="org.apache.ojb.ejb.pb.PBSessionBeanLocal"
048:         * 			view-type="both"
049:         * 			transaction-type="Container"
050:         *
051:         * @ejb:interface
052:         * 		remote-class="org.apache.ojb.ejb.pb.PBSessionRemote"
053:         * 		local-class="org.apache.ojb.ejb.pb.PBSessionLocal"
054:         * 		extends="javax.ejb.EJBObject"
055:         *
056:         * @ejb:home
057:         * 		remote-class="org.apache.ojb.ejb.pb.PBSessionHome"
058:         * 		local-class="org.apache.ojb.ejb.pb.PBSessionLocalHome"
059:         * 		extends="javax.ejb.EJBHome"
060:         *
061:         * @ejb:transaction
062:         * 		type="Required"
063:         *
064:         * @jonas.bean
065:         *      ejb-name="org.apache.ojb.ejb.pb.PBSessionBean"
066:         *      jndi-name="org.apache.ojb.ejb.pb.PBSessionBean"
067:         *
068:         * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
069:         * @version $Id: PBSessionBean.java,v 1.5.2.3 2005/12/21 22:21:38 tomdz Exp $
070:         */
071:        public class PBSessionBean implements  SessionBean {
072:            private Logger log = LoggerFactory.getLogger(PBSessionBean.class);
073:            private SessionContext ctx;
074:            private PersistenceBrokerFactoryIF pbf;
075:
076:            public PBSessionBean() {
077:            }
078:
079:            public void ejbActivate() {/* unused */
080:            }
081:
082:            public void ejbPassivate() {/* unused */
083:            }
084:
085:            public void setSessionContext(SessionContext ctx) {
086:                this .ctx = ctx;
087:            }
088:
089:            public SessionContext getSessionContext() {
090:                return ctx;
091:            }
092:
093:            public void ejbRemove() {
094:                ctx = null;
095:            }
096:
097:            public void ejbCreate() {
098:                log.info("ejbCreate was called");
099:                pbf = PersistenceBrokerFactoryFactory.instance();
100:            }
101:
102:            protected PersistenceBroker getBroker() {
103:                if (log.isDebugEnabled())
104:                    log.debug("getBroker was called");
105:                return pbf.defaultPersistenceBroker();
106:            }
107:
108:            protected List storeObjects(PersistenceBroker broker, List objects) {
109:                for (Iterator it = objects.iterator(); it.hasNext();) {
110:                    broker.store(it.next());
111:                }
112:                return objects;
113:            }
114:
115:            protected void deleteObjects(PersistenceBroker broker, List objects) {
116:                for (Iterator it = objects.iterator(); it.hasNext();) {
117:                    broker.delete(it.next());
118:                }
119:            }
120:
121:            protected int getCount(Class target) {
122:                PersistenceBroker broker = getBroker();
123:                int result = broker.getCount(new QueryByCriteria(target));
124:                broker.close();
125:                return result;
126:            }
127:
128:            /**
129:             * @ejb:interface-method
130:             */
131:            public Collection getAllObjects(Class target) {
132:                if (log.isDebugEnabled())
133:                    log.debug("getAllObjects was called");
134:                PersistenceBroker broker = getBroker();
135:                Query q = new QueryByCriteria(target);
136:                Collection result = broker.getCollectionByQuery(q);
137:                broker.close();
138:                return result;
139:            }
140:
141:            /**
142:             * @ejb:interface-method
143:             */
144:            public Iterator iterateAllObjects(Class target) {
145:                if (log.isDebugEnabled())
146:                    log.debug("getAllObjects was called");
147:                PersistenceBroker broker = getBroker();
148:                Query q = new QueryByCriteria(target);
149:                Iterator result = broker.getIteratorByQuery(q);
150:                broker.close();
151:                return result;
152:            }
153:
154:            /**
155:             * @ejb:interface-method
156:             */
157:            public int getArticleCount() {
158:                if (log.isDebugEnabled())
159:                    log.debug("getArticleCount was called");
160:                return getCount(ArticleVO.class);
161:            }
162:
163:            /**
164:             * @ejb:interface-method
165:             */
166:            public Collection getArticlesByName(String articleName) {
167:                if (log.isDebugEnabled())
168:                    log.debug("getArticlesByName was called");
169:                PersistenceBroker broker = getBroker();
170:                Criteria crit = new Criteria();
171:                crit.addLike("name", articleName);
172:                Query q = new QueryByCriteria(ArticleVO.class, crit);
173:                Collection result = broker.getCollectionByQuery(q);
174:                broker.close();
175:                return result;
176:            }
177:
178:            /**
179:             * @ejb:interface-method
180:             */
181:            public int getPersonCount() {
182:                if (log.isDebugEnabled())
183:                    log.debug("getPersonCount was called");
184:                return getCount(PersonVO.class);
185:            }
186:
187:            /**
188:             * @ejb:interface-method
189:             */
190:            public List storeObjects(List objects) {
191:                if (log.isDebugEnabled())
192:                    log.debug("storeObjects was called");
193:                PersistenceBroker broker = getBroker();
194:                List stored = this .storeObjects(broker, objects);
195:                broker.close();
196:                return stored;
197:            }
198:
199:            /**
200:             * @ejb:interface-method
201:             */
202:            public void deleteObjects(List objects) {
203:                if (log.isDebugEnabled())
204:                    log.debug("deleteObjects was called");
205:                PersistenceBroker broker = getBroker();
206:                this .deleteObjects(broker, objects);
207:                broker.close();
208:            }
209:
210:            /**
211:             * @ejb:interface-method
212:             */
213:            public boolean allInOne(List articles, List persons) {
214:                if (log.isDebugEnabled())
215:                    log.debug("allInOne was called");
216:                StringBuffer buf = new StringBuffer();
217:                boolean passedWell = true;
218:                String sep = System.getProperty("line.separator");
219:
220:                int personsBefore = getPersonCount();
221:                int articlesBefore = getArticleCount();
222:                buf.append(sep + "# Start with " + personsBefore + " persons");
223:                buf
224:                        .append(sep + "# Start with " + articlesBefore
225:                                + " articles");
226:                storeObjects(articles);
227:                storeObjects(persons);
228:                int personsAfterStore = getPersonCount();
229:                int articlesAfterStore = getArticleCount();
230:                buf.append(sep + "# After store: " + personsAfterStore
231:                        + " persons");
232:                buf.append(sep + "# After store: " + articlesAfterStore
233:                        + " articles");
234:                deleteObjects(articles);
235:                deleteObjects(persons);
236:                int personsAfterDelete = getPersonCount();
237:                int articlesAfterDelete = getArticleCount();
238:                buf.append(sep + "# After delete: " + personsAfterDelete
239:                        + " persons");
240:                buf.append(sep + "# After delete: " + articlesAfterDelete
241:                        + " articles");
242:                log.info("## allInOne-Method call: " + buf.toString());
243:                passedWell = (personsBefore + persons.size()) == personsAfterStore
244:                        && (articlesBefore + articles.size()) == articlesAfterStore
245:                        && (personsBefore) == personsAfterDelete
246:                        && (personsBefore) == personsAfterDelete;
247:                return passedWell;
248:            }
249:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.