1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.jca;
12
13 import java.io.IOException;
14 import java.io.ObjectInputStream;
15
16 import javax.resource.ResourceException;
17 import javax.resource.spi.ConnectionEvent;
18 import javax.resource.spi.ConnectionEventListener;
19 import javax.resource.spi.ConnectionManager;
20 import javax.resource.spi.ConnectionRequestInfo;
21 import javax.resource.spi.ManagedConnection;
22 import javax.resource.spi.ManagedConnectionFactory;
23 import javax.security.auth.Subject;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27
28
29
30
31 public class DefaultConnectionManager implements ConnectionManager, ConnectionEventListener
32 {
33
34
35
36 private static final long serialVersionUID = 1967602190602154760L;
37
38 private transient Log logger = LogFactory.getLog(this.getClass());
39
40 public DefaultConnectionManager()
41 {
42 super();
43 }
44
45 private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException
46 {
47 ois.defaultReadObject();
48 this.logger = LogFactory.getLog(this.getClass());
49 }
50
51
52
53
54
55 public Object allocateConnection(ManagedConnectionFactory connectionFactory, ConnectionRequestInfo info)
56 throws ResourceException
57 {
58 Subject subject = null;
59 ManagedConnection connection = connectionFactory.createManagedConnection(subject, info);
60 connection.addConnectionEventListener(this);
61 return connection.getConnection(subject, info);
62 }
63
64
65
66
67 public void connectionClosed(ConnectionEvent event)
68 {
69 try
70 {
71 ((ManagedConnection)event.getSource()).cleanup();
72 }
73 catch (ResourceException e)
74 {
75 logger.warn("Error occured during the cleanup of a managed connection: ", e);
76 }
77 try
78 {
79 ((ManagedConnection)event.getSource()).destroy();
80 }
81 catch (ResourceException e)
82 {
83 logger.warn("Error occured during the destruction of a managed connection: ", e);
84 }
85 }
86
87
88
89
90 public void localTransactionStarted(ConnectionEvent event)
91 {
92
93 }
94
95
96
97
98 public void localTransactionCommitted(ConnectionEvent event)
99 {
100
101 }
102
103
104
105
106 public void localTransactionRolledback(ConnectionEvent event)
107 {
108
109 }
110
111
112
113
114 public void connectionErrorOccurred(ConnectionEvent event)
115 {
116 logger.warn("Managed connection experiened an error: ", event.getException());
117 try
118 {
119 ((ManagedConnection)event.getSource()).cleanup();
120 }
121 catch (ResourceException e)
122 {
123 logger.warn("Error occured during the cleanup of a managed connection: ", e);
124 }
125 try
126 {
127 ((ManagedConnection)event.getSource()).destroy();
128 }
129 catch (ResourceException e)
130 {
131 logger.warn("Error occured during the destruction of a managed connection: ", e);
132 }
133 }
134
135 }