1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 package org.jomc.standalone.ri.naming.support;
38
39 import com.arjuna.ats.arjuna.coordinator.TransactionReaper;
40 import com.arjuna.ats.arjuna.recovery.RecoveryManager;
41 import com.arjuna.ats.jdbc.TransactionalDriver;
42 import com.arjuna.ats.jdbc.common.jdbcPropertyManager;
43 import com.arjuna.ats.jta.common.jtaPropertyManager;
44 import com.arjuna.ats.jta.utils.JNDIManager;
45 import java.io.PrintWriter;
46 import java.sql.Connection;
47 import java.sql.SQLException;
48 import java.util.Hashtable;
49 import java.util.Properties;
50 import javax.naming.Context;
51 import javax.naming.NamingException;
52 import javax.sql.DataSource;
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
76
77
78 public final class JBossJTAContextFactory extends AbstractContextFactory
79 {
80
81
82 public Context getInitialContext( final Hashtable<?, ?> environment ) throws NamingException
83 {
84 jdbcPropertyManager.getPropertyManager().setProperty(
85 "Context.INITIAL_CONTEXT_FACTORY", (String) environment.get( Context.INITIAL_CONTEXT_FACTORY ) );
86
87 jdbcPropertyManager.getPropertyManager().setProperty(
88 "Context.URL_PKG_PREFIXES", (String) environment.get( Context.URL_PKG_PREFIXES ) );
89
90 jtaPropertyManager.getPropertyManager().setProperty(
91 com.arjuna.ats.jta.common.Environment.TM_JNDI_CONTEXT,
92 this.getStandaloneEnvironment().getTransactionManagerJndiName() );
93
94 jtaPropertyManager.getPropertyManager().setProperty(
95 com.arjuna.ats.jta.common.Environment.UT_JNDI_CONTEXT,
96 this.getStandaloneEnvironment().getUserTransactionJndiName() );
97
98 jtaPropertyManager.getPropertyManager().setProperty(
99 com.arjuna.ats.jta.common.Environment.TSR_JNDI_CONTEXT,
100 this.getStandaloneEnvironment().getTransactionSynchronizationRegistryJndiName() );
101
102 JNDIManager.bindJTAImplementation();
103
104 TransactionReaper.create();
105
106 final RecoveryManager recoveryManager = RecoveryManager.manager();
107 recoveryManager.startRecoveryManagerThread();
108
109 if ( this.isTransactionalDriverEnabled() )
110 {
111 this.getStandaloneContext().rebind( this.getStandaloneEnvironment().getJtaDataSourceJndiName(),
112 this.getTransactionalDataSource() );
113
114 }
115
116 return null;
117 }
118
119 private DataSource getTransactionalDataSource()
120 {
121 return new DataSource()
122 {
123
124 private final TransactionalDriver driver = new TransactionalDriver();
125
126 private PrintWriter logWriter;
127
128 private boolean logWriterSet;
129
130 private int loginTimeout;
131
132 public Connection getConnection() throws SQLException
133 {
134 return this.getConnection( getStandaloneEnvironment().getDataSourceUser(),
135 getStandaloneEnvironment().getDataSourcePassword() );
136
137 }
138
139 public Connection getConnection( final String username, final String password ) throws SQLException
140 {
141 final String url =
142 TransactionalDriver.arjunaDriver + getStandaloneEnvironment().getDataSourceJndiName();
143
144 final Properties properties = new Properties();
145 properties.setProperty( TransactionalDriver.userName, username );
146 properties.setProperty( TransactionalDriver.password, password );
147 return this.driver.connect( url, properties );
148 }
149
150 public PrintWriter getLogWriter() throws SQLException
151 {
152 if ( this.logWriter == null && !this.logWriterSet )
153 {
154 this.logWriter = new PrintWriter( System.out );
155 }
156
157 return this.logWriter;
158 }
159
160 public void setLogWriter( final PrintWriter out ) throws SQLException
161 {
162 this.logWriter = out;
163 this.logWriterSet = true;
164 }
165
166 public void setLoginTimeout( final int seconds ) throws SQLException
167 {
168 this.loginTimeout = seconds;
169 }
170
171 public int getLoginTimeout() throws SQLException
172 {
173 return this.loginTimeout;
174 }
175
176 public <T> T unwrap( final Class<T> iface ) throws SQLException
177 {
178 return (T) ( this.isWrapperFor( iface ) ? this : null );
179 }
180
181 public boolean isWrapperFor( final Class<?> iface ) throws SQLException
182 {
183 return iface.isAssignableFrom( DataSource.class );
184 }
185
186 };
187 }
188
189
190
191
192
193
194
195
196 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
197 public JBossJTAContextFactory()
198 {
199
200 super();
201
202 }
203
204
205
206
207
208
209
210
211
212
213
214
215 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
216 private boolean isTransactionalDriverEnabled()
217 {
218 final java.lang.Boolean _p = (java.lang.Boolean) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "transactionalDriverEnabled" );
219 assert _p != null : "'transactionalDriverEnabled' property not found.";
220 return _p.booleanValue();
221 }
222
223
224
225
226 }