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 | 0 | private transient Log logger = LogFactory.getLog(this.getClass()); |
39 | |
|
40 | |
public DefaultConnectionManager() |
41 | |
{ |
42 | 0 | super(); |
43 | 0 | } |
44 | |
|
45 | |
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException |
46 | |
{ |
47 | 0 | ois.defaultReadObject(); |
48 | 0 | this.logger = LogFactory.getLog(this.getClass()); |
49 | 0 | } |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
public Object allocateConnection(ManagedConnectionFactory connectionFactory, ConnectionRequestInfo info) |
56 | |
throws ResourceException |
57 | |
{ |
58 | 0 | Subject subject = null; |
59 | 0 | ManagedConnection connection = connectionFactory.createManagedConnection(subject, info); |
60 | 0 | connection.addConnectionEventListener(this); |
61 | 0 | return connection.getConnection(subject, info); |
62 | |
} |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
public void connectionClosed(ConnectionEvent event) |
68 | |
{ |
69 | |
try |
70 | |
{ |
71 | 0 | ((ManagedConnection)event.getSource()).cleanup(); |
72 | |
} |
73 | 0 | catch (ResourceException e) |
74 | |
{ |
75 | 0 | logger.warn("Error occured during the cleanup of a managed connection: ", e); |
76 | 0 | } |
77 | |
try |
78 | |
{ |
79 | 0 | ((ManagedConnection)event.getSource()).destroy(); |
80 | |
} |
81 | 0 | catch (ResourceException e) |
82 | |
{ |
83 | 0 | logger.warn("Error occured during the destruction of a managed connection: ", e); |
84 | 0 | } |
85 | 0 | } |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
public void localTransactionStarted(ConnectionEvent event) |
91 | |
{ |
92 | |
|
93 | 0 | } |
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
public void localTransactionCommitted(ConnectionEvent event) |
99 | |
{ |
100 | |
|
101 | 0 | } |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
public void localTransactionRolledback(ConnectionEvent event) |
107 | |
{ |
108 | |
|
109 | 0 | } |
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
public void connectionErrorOccurred(ConnectionEvent event) |
115 | |
{ |
116 | 0 | logger.warn("Managed connection experiened an error: ", event.getException()); |
117 | |
try |
118 | |
{ |
119 | 0 | ((ManagedConnection)event.getSource()).cleanup(); |
120 | |
} |
121 | 0 | catch (ResourceException e) |
122 | |
{ |
123 | 0 | logger.warn("Error occured during the cleanup of a managed connection: ", e); |
124 | 0 | } |
125 | |
try |
126 | |
{ |
127 | 0 | ((ManagedConnection)event.getSource()).destroy(); |
128 | |
} |
129 | 0 | catch (ResourceException e) |
130 | |
{ |
131 | 0 | logger.warn("Error occured during the destruction of a managed connection: ", e); |
132 | 0 | } |
133 | 0 | } |
134 | |
|
135 | |
} |