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