KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > resource > LocalTxConnectorAllocator


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.resource;
25
26 import javax.transaction.xa.XAResource JavaDoc;
27 import javax.resource.spi.*;
28 import javax.resource.ResourceException JavaDoc;
29 import javax.security.auth.Subject JavaDoc;
30 import java.util.logging.*;
31
32 import com.sun.enterprise.deployment.ConnectorDescriptor;
33 import com.sun.enterprise.PoolManager;
34
35 /**
36  * @author Tony Ng
37  */

38 public class LocalTxConnectorAllocator extends AbstractConnectorAllocator {
39
40
41     public LocalTxConnectorAllocator(PoolManager poolMgr,
42                                      ManagedConnectionFactory mcf,
43                                      ResourceSpec spec,
44                                      Subject JavaDoc subject,
45                                      ConnectionRequestInfo reqInfo,
46                                      ClientSecurityInfo info,
47                                      ConnectorDescriptor desc) {
48         super(poolMgr, mcf, spec, subject, reqInfo, info, desc);
49     }
50
51     
52     public ResourceHandle createResource()
53          throws PoolingException
54     {
55         try {
56             ManagedConnection mc =
57                 mcf.createManagedConnection(subject, reqInfo);
58             
59             ResourceHandle resource =
60                 new ResourceHandle(mc, spec, this, info);
61             ConnectionEventListener l =
62                 new LocalTxConnectionEventListener(resource);
63             mc.addConnectionEventListener(l);
64             resource.setListener(l);
65
66             XAResource JavaDoc xares =
67                 new ConnectorXAResource(resource, spec, this, info);
68             resource.fillInResourceObjects(null, xares);
69
70             return resource;
71         } catch (ResourceException JavaDoc ex) {
72             _logger.log(Level.WARNING,"poolmgr.create_resource_error",ex.getMessage());
73             _logger.log(Level.FINE,"Resource Exception while creating resource",ex);
74
75             if (ex.getLinkedException() != null) {
76                 _logger.log(Level.WARNING,"poolmgr.create_resource_error",ex.getLinkedException().getMessage());
77             }
78             throw new PoolingException(ex);
79         }
80     }
81
82     public void fillInResourceObjects(ResourceHandle resource)
83         throws PoolingException
84     {
85         try {
86             ManagedConnection mc = (ManagedConnection) resource.getResource();
87
88             Object JavaDoc con = mc.getConnection(subject, reqInfo);
89         
90         ConnectorXAResource xares = (ConnectorXAResource) resource.getXAResource();
91         xares.setUserHandle(con);
92             resource.fillInResourceObjects(con, xares);
93         } catch (ResourceException JavaDoc ex) {
94             throw new PoolingException(ex);
95         }
96     }
97
98     public void destroyResource(ResourceHandle resource)
99         throws PoolingException {
100         try {
101             ManagedConnection mc = (ManagedConnection) resource.getResource();
102             ConnectorXAResource.freeListener(mc);
103             mc.destroy();
104             if (_logger.isLoggable( Level.FINEST ) ) {
105                 _logger.finest( "destroyResource for LocalTxConnectorAllocator done");
106             }
107         
108         } catch (Exception JavaDoc ex) {
109             _logger.log(Level.WARNING, ex.getMessage());
110             throw new PoolingException(ex);
111         }
112     }
113
114    
115     public boolean shareableWithinComponent() {
116         //For local transactions, a resource is always shareable within components
117
//within the same transaction
118
return true;
119     }
120
121 }
122
Popular Tags