Source Code Cross Referenced for PooledDataSourceFactoryFactory.java in  » Portal » uPortal_rel-2-6-1-GA » org » jasig » portal » rdbm » pool » 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 » Portal » uPortal_rel 2 6 1 GA » org.jasig.portal.rdbm.pool 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright 2004-2005 The JA-SIG Collaborative.  All rights reserved.
002:         *  See license distributed with this file and
003:         *  available online at http://www.uportal.org/license.html
004:         */
005:
006:        package org.jasig.portal.rdbm.pool;
007:
008:        import org.apache.commons.logging.Log;
009:        import org.apache.commons.logging.LogFactory;
010:        import org.jasig.portal.properties.MissingPropertyException;
011:        import org.jasig.portal.properties.PropertiesManager;
012:
013:        /**
014:         * @author Eric Dalquist <a href="mailto:edalquist@unicon.net">edalquist@unicon.net</a>
015:         * @version $Revision: 36214 $ $Date: 2005-10-19 09:25:55 -0700 (Wed, 19 Oct 2005) $
016:         * @since uPortal 2.5
017:         */
018:        public final class PooledDataSourceFactoryFactory {
019:
020:            /**
021:             * The name of the portal.properties property the value of which will be the name of the
022:             * IPooledDataSourceFactory implementation that we will use.
023:             */
024:            public static final String POOLED_DATA_SOURCE_FACTORY_PROPERTY = "org.jasig.portal.PooledDataSourceFactory.implementation";
025:
026:            /**
027:             * A Commons Logging log instance.
028:             */
029:            private static final Log LOG = LogFactory
030:                    .getLog(PooledDataSourceFactoryFactory.class);
031:
032:            /**
033:             * Our default IPooledDataSourceFactory implementation upon which we will fall back if
034:             * our property is not set or we cannot instantiate the implementation specified by
035:             * our property.
036:             * 
037:             * Default scoped to be accessible to our testcase.
038:             */
039:            static final Class DEFAULT_POOLED_DATASOURCE_FACTORY = DBCPDataSourceFactory.class;
040:
041:            /**
042:             * Our static singleton instance that we're managing.
043:             */
044:            private static IPooledDataSourceFactory pooledDataSourceFactoryImpl = null;
045:
046:            /**
047:             * Get a reference to our static singleton instance of IPooledDataSourceFactory
048:             * as specified in our portal.properties property, or our default implementation, or null.
049:             * 
050:             * That is, this method returns our static singleton instance of IPooledDataSourceFactory.
051:             * That instance will be an instance of the implementation named in our portal.properties property
052:             * if we are able to instantiate that, or an instance of our default implementation if we were
053:             * unable to instantiate the configured implementation, or null if we can instantiate neither.
054:             * 
055:             * This method is synchronized to avoid using the much-feared Double Checked Locking
056:             * idiom.  By synchronizing we force the change we make when we first (lazily) initialize 
057:             * our pooledDataSourceFactoryImpl to be written back to main memory and thereby
058:             * be available to other threads when they succeed in obtaining the lock and entering
059:             * this method.
060:             * 
061:             * @return the configured or default IPooledDataSourceFactory, or null if neither can be instantiated.
062:             */
063:            public static synchronized IPooledDataSourceFactory getPooledDataSourceFactory() {
064:
065:                // if we already have instantiated our static singleton instance, return it
066:                if (pooledDataSourceFactoryImpl != null) {
067:                    return pooledDataSourceFactoryImpl;
068:                }
069:
070:                // initialize the class name so we can try to use it in our error logging
071:                // on failure
072:                String className = "unknown";
073:                try {
074:                    className = PropertiesManager
075:                            .getProperty(POOLED_DATA_SOURCE_FACTORY_PROPERTY);
076:                    pooledDataSourceFactoryImpl = (IPooledDataSourceFactory) Class
077:                            .forName(className).newInstance();
078:                    return pooledDataSourceFactoryImpl;
079:                } catch (MissingPropertyException mpe) {
080:                    // we recover from our property not having been set by falling back on our default.
081:                    // This is not necessarily an error condition.  The deployer may simply have chosen
082:                    // not to set our property and expects us to fall back on our default.
083:                    LOG
084:                            .info("The portal.properties property "
085:                                    + POOLED_DATA_SOURCE_FACTORY_PROPERTY
086:                                    + " was not set, so PooledDataSourceFactoryFactory will fall back on its default "
087:                                    + "IPooledDataSourceFactory implementation, which is "
088:                                    + DEFAULT_POOLED_DATASOURCE_FACTORY);
089:                } catch (Exception e) {
090:                    // we also recover from any other problem that happened in instantiating the configured
091:                    // IPooledDataSourceFactory by falling back on our default.  However, this is an error
092:                    // condition and logged as such.
093:
094:                    LOG.error(
095:                            "Unable to instantiate the configured IPooledDataSourceFactory :"
096:                                    + className
097:                                    + ", so falling back on default of "
098:                                    + DEFAULT_POOLED_DATASOURCE_FACTORY, e);
099:
100:                }
101:
102:                try {
103:                    pooledDataSourceFactoryImpl = (IPooledDataSourceFactory) DEFAULT_POOLED_DATASOURCE_FACTORY
104:                            .newInstance();
105:                } catch (Exception e2) {
106:                    LOG.error(
107:                            "Could not instantiate our default IPooledDataSourceFactory "
108:                                    + DEFAULT_POOLED_DATASOURCE_FACTORY, e2);
109:                }
110:
111:                // the field will either be our default if we succeeded in instantiating our default
112:                // or will be null if we failed.
113:                return pooledDataSourceFactoryImpl;
114:
115:            }
116:
117:            /**
118:             * This private constructor prevents instantiation of this static 
119:             * factory class.
120:             */
121:            private PooledDataSourceFactoryFactory() {
122:                // do nothing
123:            }
124:
125:            /**
126:             * Clears this static factory's static singleton instance of 
127:             * IPooledDataSourceFactory.  This method exists to support the unit test
128:             * for this class and should not be considered part of the API exported
129:             * by this class.
130:             */
131:            static void reset() {
132:                pooledDataSourceFactoryImpl = null;
133:            }
134:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.