Source Code Cross Referenced for ManagedConnectionFactoryImpl.java in  » EJB-Server-resin-3.1.5 » examples » example » 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 » EJB Server resin 3.1.5 » examples » example 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package example;
002:
003:        import java.io.*;
004:        import java.util.*;
005:
006:        import javax.resource.spi.ResourceAdapter;
007:
008:        import javax.resource.spi.ManagedConnectionFactory;
009:        import javax.resource.spi.ManagedConnection;
010:        import javax.resource.spi.ConnectionManager;
011:
012:        import javax.resource.spi.ManagedConnectionMetaData;
013:        import javax.resource.spi.ConnectionRequestInfo;
014:
015:        import javax.security.auth.Subject;
016:
017:        /**
018:         * Main interface between Resin and the connector.  It's the
019:         * top-level SPI class for creating the SPI ManagedConnections.
020:         *
021:         * The resource configuration in Resin's web.xml will use bean-style
022:         * configuration to configure the ManagecConnectionFactory.
023:         */
024:        public class ManagedConnectionFactoryImpl implements 
025:                ManagedConnectionFactory {
026:            private String _name;
027:
028:            // A counter for the example to keep track of the underlying connections.
029:            // Each ManagedConnectionImpl will get its own id.
030:            private int _mcCount;
031:
032:            // A counter for the example to keep track of the user connections.
033:            // Each ConnectionImpl will get its own id.
034:            private int _cCount;
035:
036:            /**
037:             * Sets the name for the connector
038:             */
039:            public void setName(String name) {
040:                _name = name;
041:            }
042:
043:            /**
044:             * Creates the application's view of the connection factory.
045:             *
046:             * The ConnectionFactory is the equivalent of the JDBC DataSource.
047:             * Applications will use the ConnectionFactory to create connections.
048:             *
049:             * The connector can use any API that makes sense for it.  JDBC
050:             * connectors will return a DataSource.  JMS connectors will return
051:             * SessionFactory, etc.
052:             *
053:             * @param manager ConnectionManager provided by Resin gives access to
054:             *   some application server resources.
055:             */
056:            public Object createConnectionFactory(ConnectionManager manager) {
057:                return new ConnectionFactoryImpl(this , manager);
058:            }
059:
060:            /**
061:             * Creates the SPI-side of a connection, like the <code>XAConnection</code> of
062:             * JDBC.  Resin will use the returned <code>ManagedConnection</code>
063:             * to create the application connections, manage transactions,
064:             * and manage the pool.
065:             *
066:             * The <code>ConnectionRequestInfo</code> is not used in this example.
067:             * When needed, the <code>ConnectionFactoryImpl</code> will create a
068:             * <code>ConnectionRequestInfo</code> and pass it to Resin with
069:             * the <code>allocateConnection</code> call.
070:             *
071:             * @param subject security identifier of the application requesting
072:             *   the connection.
073:             * @param reqInfo connection-specific configuration information
074:             */
075:            public ManagedConnection createManagedConnection(Subject subject,
076:                    ConnectionRequestInfo reqInfo) {
077:                return new ManagedConnectionImpl(_name + "-" + _mcCount++, this );
078:            }
079:
080:            /**
081:             * A connection pool method which lets the connector choose which
082:             * idle connection are allowed to be reused for a request.
083:             * It returns a connection from the set matching the subject and request
084:             * info.
085:             *
086:             * Many connectors can just return the first connection, if it doesn't
087:             * matter which connection is used.  However, the pool might contain
088:             * connections with different configurations and subjects.  This method
089:             * lets the connector return a connection that properly matches the
090:             * request.
091:             *
092:             * @param set Resin's current pool of idle connections
093:             * @param subject the application id asking for a connection
094:             * @param reqInfo connector-specific information used to configure
095:             *   the connection
096:             *
097:             * @return a connection matching the subject and reqInfo requirements or
098:             *   null if none match
099:             */
100:            public ManagedConnection matchManagedConnections(Set set,
101:                    Subject subject, ConnectionRequestInfo reqInfo) {
102:                Iterator iter = set.iterator();
103:
104:                while (iter.hasNext()) {
105:                    ManagedConnectionImpl mConn = (ManagedConnectionImpl) iter
106:                            .next();
107:
108:                    // In this example, all connections are equivalent
109:                    return mConn;
110:                }
111:
112:                return null;
113:            }
114:
115:            /**
116:             * This connection factory does not have a separate resource adapter.
117:             *
118:             * More complicated connection factories will have a
119:             * separate ResourceAdapter object to share state among multiple
120:             * connection factories and to manage threads, etc, using
121:             * the application server.
122:             */
123:            public void setResourceAdapter(ResourceAdapter ra) {
124:            }
125:
126:            /**
127:             * This connection factory does not have a separate resource adapter.
128:             *
129:             * More complicated connection factories will have a
130:             * separate ResourceAdapter object to share state among multiple
131:             * connection factories and to manage threads, etc, using
132:             * the application server.
133:             */
134:            public ResourceAdapter getResourceAdapter() {
135:                return null;
136:            }
137:
138:            /**
139:             * createConnectionFactory with no arguments is for a connection factory
140:             * outside of an application server.  Although most connection factories
141:             * will implement it, Resin never uses it.
142:             */
143:            public Object createConnectionFactory() {
144:                throw new UnsupportedOperationException();
145:            }
146:
147:            /**
148:             * Logging should use JDK 1.4 java.util.logging.
149:             */
150:            public PrintWriter getLogWriter() {
151:                return null;
152:            }
153:
154:            /**
155:             * Logging should use JDK 1.4 java.util.logging.
156:             */
157:            public void setLogWriter(PrintWriter out) {
158:            }
159:
160:            /**
161:             * Returns the connection name.
162:             */
163:            public String generateConnectionName() {
164:                return _name + "-" + _cCount++ + "-conn";
165:            }
166:
167:            public String toString() {
168:                return "ManagedConnectionFactoryImpl[" + _name + "]";
169:            }
170:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.