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


001:        package org.apache.ojb.ejb.odmg;
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.EJBException;
019:        import java.util.Collection;
020:        import java.util.Iterator;
021:
022:        import org.apache.ojb.broker.PersistenceBroker;
023:        import org.apache.ojb.broker.query.QueryByCriteria;
024:        import org.apache.ojb.broker.util.logging.Logger;
025:        import org.apache.ojb.broker.util.logging.LoggerFactory;
026:        import org.apache.ojb.ejb.SessionBeanImpl;
027:        import org.apache.ojb.odmg.HasBroker;
028:        import org.apache.ojb.odmg.TransactionExt;
029:        import org.odmg.Database;
030:        import org.odmg.Implementation;
031:        import org.odmg.LockNotGrantedException;
032:        import org.odmg.OQLQuery;
033:        import org.odmg.Transaction;
034:
035:        /**
036:         * Base class for using OJB-ODMG api within SessionBeans,
037:         * subclass this class to implement your own bean
038:         * implementations.
039:         *
040:         * To keep this example as simple as possible, we lookup a static OJB ODMG
041:         * implementation instance from an helper class.
042:         * But it's recommended to bind an instances of the ODMG main/access classes in JNDI
043:         * (at appServer start), open the database and lookup these instances instance via JNDI in
044:         * ejbCreate(), instead of lookup a static instance on each bean creation.
045:         *
046:         * To get the {@link org.odmg.Database} or
047:         * {@link org.odmg.Implementation} instance use
048:         * the {@link #getDatabase} and {@link #getImplementation}
049:         * methods.
050:         *
051:         * Additionally there are some basic methods for
052:         * storing, deleting, counting, get all objects
053:         * implemented.
054:         *
055:         * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
056:         * @version $Id: ODMGBaseBeanImpl.java,v 1.5.2.4 2005/12/21 22:21:39 tomdz Exp $
057:         */
058:        public abstract class ODMGBaseBeanImpl extends SessionBeanImpl {
059:            private Logger log = LoggerFactory
060:                    .getLogger(ODMGBaseBeanImpl.class);
061:            private Implementation odmg;
062:
063:            /**
064:             * Lookup the OJB ODMG implementation.
065:             * It's recommended to bind an instance of the Implementation class in JNDI
066:             * (at appServer start), open the database and lookup this instance via JNDI in
067:             * ejbCreate().
068:             */
069:            public void ejbCreate() {
070:                if (log.isDebugEnabled())
071:                    log.debug("ejbCreate was called");
072:                odmg = ODMGHelper.getODMG();
073:            }
074:
075:            /**
076:             * Here we do the OJB cleanup.
077:             */
078:            public void ejbRemove() {
079:                super .ejbRemove();
080:                odmg = null;
081:            }
082:
083:            /**
084:             * Return the Database associated with
085:             * this bean.
086:             */
087:            public Database getDatabase() {
088:                return odmg.getDatabase(null);
089:            }
090:
091:            /**
092:             * Return the Implementation instance associated
093:             * with this bean.
094:             */
095:            public Implementation getImplementation() {
096:                return odmg;
097:            }
098:
099:            /**
100:             * Store an object.
101:             */
102:            public Object storeObject(Object object) {
103:                /* One possibility of storing objects is to use the current transaction
104:                 associated with the container */
105:                try {
106:                    TransactionExt tx = (TransactionExt) odmg
107:                            .currentTransaction();
108:                    tx.lock(object, Transaction.WRITE);
109:                    tx.markDirty(object);
110:                } catch (LockNotGrantedException e) {
111:                    log.error("Failure while storing object " + object, e);
112:                    throw new EJBException("Failure while storing object", e);
113:                }
114:                return object;
115:            }
116:
117:            /**
118:             * Delete an object.
119:             */
120:            public void deleteObject(Object object) {
121:                getDatabase().deletePersistent(object);
122:            }
123:
124:            /**
125:             * Store a collection of objects.
126:             */
127:            public Collection storeObjects(Collection objects) {
128:                try {
129:                    /* One possibility of storing objects is to use the current transaction
130:                     associated with the container */
131:                    Transaction tx = odmg.currentTransaction();
132:                    for (Iterator iterator = objects.iterator(); iterator
133:                            .hasNext();) {
134:                        tx.lock(iterator.next(), Transaction.WRITE);
135:                    }
136:                } catch (LockNotGrantedException e) {
137:                    log.error("Failure while storing objects " + objects, e);
138:                    throw new EJBException("Failure while storing objects", e);
139:                }
140:                return objects;
141:            }
142:
143:            /**
144:             * Delete a Collection of objects.
145:             */
146:            public void deleteObjects(Collection objects) {
147:                for (Iterator iterator = objects.iterator(); iterator.hasNext();) {
148:                    getDatabase().deletePersistent(iterator.next());
149:                }
150:            }
151:
152:            /**
153:             * Return the count of all objects found
154:             * for given class, using the PB-api within
155:             * ODMG - this may change in further versions.
156:             */
157:            public int getCount(Class target) {
158:                PersistenceBroker broker = ((HasBroker) odmg
159:                        .currentTransaction()).getBroker();
160:                int result = broker.getCount(new QueryByCriteria(target));
161:                return result;
162:            }
163:
164:            public Collection getAllObjects(Class target) {
165:                OQLQuery query = odmg.newOQLQuery();
166:                try {
167:                    query.create("select allObjects from " + target.getName());
168:                    return (Collection) query.execute();
169:                } catch (Exception e) {
170:                    log.error("OQLQuery failed", e);
171:                    throw new EJBException("OQLQuery failed", e);
172:                }
173:            }
174:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.