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


001:        package org.apache.ojb.broker.core;
002:
003:        /* Copyright 2003-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 org.apache.ojb.broker.PBFactoryException;
019:        import org.apache.ojb.broker.PBKey;
020:        import org.apache.ojb.broker.PersistenceBroker;
021:        import org.apache.ojb.broker.PersistenceBrokerInternal;
022:        import org.apache.ojb.broker.accesslayer.ConnectionFactoryFactory;
023:        import org.apache.ojb.broker.metadata.MetadataManager;
024:        import org.apache.ojb.broker.util.BrokerHelper;
025:        import org.apache.ojb.broker.util.ClassHelper;
026:        import org.apache.ojb.broker.util.configuration.Configuration;
027:        import org.apache.ojb.broker.util.configuration.ConfigurationException;
028:        import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
029:        import org.apache.ojb.broker.util.interceptor.InterceptorFactory;
030:        import org.apache.ojb.broker.util.logging.Logger;
031:        import org.apache.ojb.broker.util.logging.LoggerFactory;
032:
033:        /**
034:         * This is an base implementation of the {@link PersistenceBrokerFactoryIF}
035:         * interface. Each request ({@link PersistenceBrokerFactoryIF#createPersistenceBroker} or
036:         * {@link PersistenceBrokerFactoryIF#defaultPersistenceBroker} call) creates a new
037:         * {@link PersistenceBroker} instance. No pooling of broker instances is used.
038:         *
039:         * @see PersistenceBrokerFactoryDefaultImpl
040:         *
041:         * @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
042:         * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
043:         * @version $Id: PersistenceBrokerFactoryBaseImpl.java,v 1.3.2.3 2005/12/21 22:25:00 tomdz Exp $
044:         */
045:        public class PersistenceBrokerFactoryBaseImpl implements 
046:                PersistenceBrokerFactoryIF {
047:            private static Logger log = LoggerFactory
048:                    .getLogger(PersistenceBrokerFactoryBaseImpl.class);
049:
050:            private Class implementationClass;
051:            private long instanceCount;
052:
053:            public PersistenceBrokerFactoryBaseImpl() {
054:                configure(OjbConfigurator.getInstance().getConfigurationFor(
055:                        null));
056:            }
057:
058:            /**
059:             * @see PersistenceBrokerFactoryIF#setDefaultKey
060:             */
061:            public void setDefaultKey(PBKey key) {
062:                try {
063:                    MetadataManager.getInstance().setDefaultPBKey(key);
064:                } catch (Exception e) {
065:                    throw new PBFactoryException(e);
066:                }
067:            }
068:
069:            /**
070:             * @see PersistenceBrokerFactoryIF#getDefaultKey()
071:             */
072:            public PBKey getDefaultKey() {
073:                return MetadataManager.getInstance().getDefaultPBKey();
074:            }
075:
076:            /**
077:             * For internal use! This method creates real new PB instances
078:             */
079:            protected PersistenceBrokerInternal createNewBrokerInstance(
080:                    PBKey key) throws PBFactoryException {
081:                if (key == null)
082:                    throw new PBFactoryException(
083:                            "Could not create new broker with PBkey argument 'null'");
084:                // check if the given key really exists
085:                if (MetadataManager.getInstance().connectionRepository()
086:                        .getDescriptor(key) == null) {
087:                    throw new PBFactoryException("Given PBKey " + key
088:                            + " does not match in metadata configuration");
089:                }
090:                if (log.isEnabledFor(Logger.INFO)) {
091:                    // only count created instances when INFO-Log-Level
092:                    log
093:                            .info("Create new PB instance for PBKey "
094:                                    + key
095:                                    + ", already created persistence broker instances: "
096:                                    + instanceCount);
097:                    // useful for testing
098:                    ++this .instanceCount;
099:                }
100:
101:                PersistenceBrokerInternal instance = null;
102:                Class[] types = { PBKey.class, PersistenceBrokerFactoryIF.class };
103:                Object[] args = { key, this  };
104:                try {
105:                    instance = (PersistenceBrokerInternal) ClassHelper
106:                            .newInstance(implementationClass, types, args);
107:                    OjbConfigurator.getInstance().configure(instance);
108:                    instance = (PersistenceBrokerInternal) InterceptorFactory
109:                            .getInstance().createInterceptorFor(instance);
110:                } catch (Exception e) {
111:                    log.error("Creation of a new PB instance failed", e);
112:                    throw new PBFactoryException(
113:                            "Creation of a new PB instance failed", e);
114:                }
115:                return instance;
116:            }
117:
118:            /**
119:             * Always return a new created {@link PersistenceBroker} instance
120:             *
121:             * @param pbKey
122:             * @return
123:             * @throws PBFactoryException
124:             */
125:            public PersistenceBrokerInternal createPersistenceBroker(PBKey pbKey)
126:                    throws PBFactoryException {
127:                if (log.isDebugEnabled())
128:                    log
129:                            .debug("Obtain broker from pool, used PBKey is "
130:                                    + pbKey);
131:
132:                /*
133:                try to find a valid PBKey, if given key does not full match
134:                 */
135:                pbKey = BrokerHelper.crossCheckPBKey(pbKey);
136:
137:                try {
138:                    return createNewBrokerInstance(pbKey);
139:
140:                } catch (Exception e) {
141:                    throw new PBFactoryException(
142:                            "Borrow broker from pool failed, using PBKey "
143:                                    + pbKey, e);
144:                }
145:            }
146:
147:            /**
148:             * @see PersistenceBrokerFactoryIF#createPersistenceBroker(
149:             * String jcdAlias, String user, String password)
150:             */
151:            public PersistenceBrokerInternal createPersistenceBroker(
152:                    String jcdAlias, String user, String password)
153:                    throws PBFactoryException {
154:                return this .createPersistenceBroker(new PBKey(jcdAlias, user,
155:                        password));
156:            }
157:
158:            /**
159:             * @see PersistenceBrokerFactoryIF#createPersistenceBroker(PBKey key)
160:             */
161:            public PersistenceBrokerInternal defaultPersistenceBroker()
162:                    throws PBFactoryException {
163:                if (getDefaultKey() == null)
164:                    throw new PBFactoryException(
165:                            "There was no 'default-connection' attribute"
166:                                    + " enabled in the jdbc connection descriptor");
167:                return this .createPersistenceBroker(getDefaultKey());
168:            }
169:
170:            /*
171:             * @see org.apache.ojb.broker.util.configuration.Configurable#configure(Configuration)
172:             */
173:            public void configure(Configuration config)
174:                    throws ConfigurationException {
175:                implementationClass = ((PersistenceBrokerConfiguration) config)
176:                        .getPersistenceBrokerClass();
177:            }
178:
179:            /**
180:             * @see PersistenceBrokerFactoryIF#releaseAllInstances()
181:             */
182:            public synchronized void releaseAllInstances() {
183:                instanceCount = 0;
184:            }
185:
186:            /**
187:             * Not implemented!
188:             *
189:             * @return always 0
190:             */
191:            public int activePersistenceBroker() {
192:                return 0;
193:            }
194:
195:            public void shutdown() {
196:                try {
197:                    ConnectionFactoryFactory.getInstance()
198:                            .createConnectionFactory().releaseAllResources();
199:                    PersistenceBrokerThreadMapping.shutdown();
200:                    MetadataManager.getInstance().shutdown();
201:                } catch (RuntimeException e) {
202:                    log.error("Error while shutdown of OJB", e);
203:                    throw e;
204:                }
205:            }
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.