/
MDCompleteMCF.java
446 lines (380 loc) · 11.8 KB
/
MDCompleteMCF.java
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
/*
* Copyright (c) 2009, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package com.sun.ts.tests.common.connector.whitebox.mdcomplete;
import java.io.PrintWriter;
import java.io.Serializable;
import java.util.Iterator;
import java.util.Set;
import javax.security.auth.Subject;
import com.sun.ts.lib.util.TSNamingContext;
import com.sun.ts.tests.common.connector.util.ConnectorStatus;
import com.sun.ts.tests.common.connector.whitebox.Debug;
import com.sun.ts.tests.common.connector.whitebox.TSConnection;
import com.sun.ts.tests.common.connector.whitebox.TSConnectionImpl;
import com.sun.ts.tests.common.connector.whitebox.TSEISDataSource;
import com.sun.ts.tests.common.connector.whitebox.TSManagedConnection;
import com.sun.ts.tests.common.connector.whitebox.Util;
import jakarta.resource.ResourceException;
import jakarta.resource.spi.ConfigProperty;
import jakarta.resource.spi.ConnectionManager;
import jakarta.resource.spi.ConnectionRequestInfo;
import jakarta.resource.spi.EISSystemException;
import jakarta.resource.spi.ManagedConnection;
import jakarta.resource.spi.ManagedConnectionFactory;
import jakarta.resource.spi.ResourceAdapter;
import jakarta.resource.spi.ResourceAdapterAssociation;
import jakarta.resource.spi.TransactionSupport;
import jakarta.resource.spi.security.PasswordCredential;
public class MDCompleteMCF
implements ManagedConnectionFactory, ResourceAdapterAssociation,
TransactionSupport, Serializable, jakarta.resource.Referenceable {
private javax.naming.Reference reference;
private ResourceAdapter resourceAdapter;
private int count;
private String TSRValue;
private String password;
private String user;
private String userName;
@ConfigProperty(description = "String value", ignore = false)
String factoryName = "MDCompleteMCF";
/*
* @name MDCompleteMCF
*
* @desc Default conctructor
*/
public MDCompleteMCF() {
ConnectorStatus.getConnectorStatus().logState("MDCompleteMCF constructor");
}
/*
* @name getTransactionSupport
*
* @desc this is required for interface TransacationSupport
*/
public TransactionSupportLevel getTransactionSupport() {
// this is used to assist with assertion: Connector:SPEC:206 and
// Connector:SPEC:316.
String str = "MDCompleteMCF.getTransactionSupport called";
ConnectorStatus.getConnectorStatus().logState(str);
debug(str);
return TransactionSupport.TransactionSupportLevel.NoTransaction;
}
public void setFactoryName(String name) {
debug("MDCompleteMCF.setFactoryName");
// this helps verify assertion Connector:SPEC:307 and Connector:SPEC:277
// and this behavior is described in connector 1.6 spec section 18.5
String str = "MDCompleteMCF factoryname=" + name;
debug(str);
this.factoryName = name;
}
public String getFactoryName() {
debug("MDCompleteMCF.getFactoryName");
return factoryName;
}
public String getUser() {
debug("MDCompleteMCF.getUser() returning: " + user);
return user;
}
public void setUser(String val) {
debug("MDCompleteMCF.setUser() with val = " + val);
user = val;
}
public String getUserName() {
debug("MDCompleteMCF.getUserName() returning: " + userName);
return userName;
}
public void setUserName(String val) {
debug("MDCompleteMCF.setUserName() with val = " + val);
userName = val;
}
public String getPassword() {
debug("MDCompleteMCF.getPassword() returning: " + password);
return password;
}
public void setPassword(String val) {
debug("MDCompleteMCF.setPassword() with val = " + val);
password = val;
}
public String getTSRValue() {
debug("MDCompleteMCF.getTSRValue");
return TSRValue;
}
public void setTSRValue(String name) {
debug("MDCompleteMCF.setTSRValue");
this.TSRValue = name;
}
public void lookupTSR(String lookup) {
debug("MDCompleteMCF.lookupTSR");
try {
TSNamingContext ncxt = new TSNamingContext();
String newStr = "java:".concat(lookup);
Object obj = (Object) ncxt.lookup(newStr);
if (obj != null) {
debug("TSR Lookup Successful");
} else {
debug("TSR Null");
}
} catch (Exception e) {
e.printStackTrace();
}
}
/*
* @name createConnectionFactory
*
* @desc Creates a new connection factory instance
*
* @param ConnectionManager
*
* @return Object
*
* @exception ResourceException
*/
public Object createConnectionFactory(ConnectionManager cxManager)
throws ResourceException {
ConnectorStatus.getConnectorStatus().logAPI(
"MDCompleteMCF.createConnectionFactory", "cxManager",
"TSEISDataSource");
return new TSEISDataSource(this, cxManager);
}
/*
* @name createConnectionFactory
*
* @desc Creates a new connection factory instance
*
* @return Object
*
* @exception ResourceException
*/
public Object createConnectionFactory() throws ResourceException {
ConnectorStatus.getConnectorStatus()
.logAPI("MDCompleteMCF.createConnectionFactory", "", "TSEISDataSource");
return new TSEISDataSource(this, null);
}
/*
* @name setResourceAdapter
*
* @desc sets the Resource Adapter for this ManagedConnectionFactory
*
* @return
*
* @exception ResourceException
*/
public void setResourceAdapter(ResourceAdapter ra) throws ResourceException {
count++;
String newStr1 = new String("MDCompleteMCF setResourceAdapter " + count);
debug(newStr1);
this.resourceAdapter = ra;
// if we made it here, we assume no exceptions thrown thus validating
// Connector:SPEC:226
ConnectorStatus.getConnectorStatus().logState(newStr1);
}
/*
* @name getResourceAdapter
*
* @desc gets the Resource Adapter for this ManagedConnectionFactory
*
* @return Object
*
* @exception ResourceException
*/
public ResourceAdapter getResourceAdapter() {
debug("MDCompleteMCF.getResource");
return resourceAdapter;
}
/*
* @name createManagedConnection
*
* @desc Creates a new managed connection to the underlying EIS
*
* @param Subject, ConnectionRequestInfo
*
* @return ManagedConnection
*
* @exception ResourceException
*/
public ManagedConnection createManagedConnection(Subject subject,
ConnectionRequestInfo info) throws ResourceException {
try {
ConnectorStatus.getConnectorStatus().logAPI(
"MDCompleteMCF.createManagedConnection", "subject|info",
"TSManagedConnection");
TSConnection con = null;
PasswordCredential pc = Util.getPasswordCredential(this, subject, info);
if (pc == null) {
debug("MDCompleteMCF.createManagedConnection(): pc == null");
con = new TSConnectionImpl().getConnection();
} else {
debug("MDCompleteMCF.createManagedConnection(): pc != null");
setUser(pc.getUserName());
setUserName(pc.getUserName());
setPassword(new String(pc.getPassword()));
con = new TSConnectionImpl().getConnection(pc.getUserName(),
pc.getPassword());
}
ManagedConnection mcon = new TSManagedConnection(this, pc, null, con,
false, true);
return mcon;
} catch (Exception ex) {
ResourceException re = new EISSystemException(
"Exception: " + ex.getMessage());
re.initCause(ex);
throw re;
}
}
/*
* @name matchManagedConnection
*
* @desc Return the existing connection from the connection pool
*
* @param Set, Subject, ConnectionRequestInfo
*
* @return ManagedConnection
*
* @exception ResourceException
*/
public ManagedConnection matchManagedConnections(Set connectionSet,
Subject subject, ConnectionRequestInfo info) throws ResourceException {
ConnectorStatus.getConnectorStatus().logAPI(
"MDCompleteMCF.matchManagedConnection", "connectionSet|subject|info",
"TSEISDataSource");
PasswordCredential pc = Util.getPasswordCredential(this, subject, info);
Iterator it = connectionSet.iterator();
while (it.hasNext()) {
Object obj = it.next();
if (obj instanceof TSManagedConnection) {
TSManagedConnection mc = (TSManagedConnection) obj;
ManagedConnectionFactory mcf = mc.getManagedConnectionFactory();
if (Util.isPasswordCredentialEqual(mc.getPasswordCredential(), pc)
&& mcf.equals(this)) {
return mc;
}
}
}
return null;
}
/*
* @name setLogWriter
*
* @desc Sets the Print Writer
*
* @param PrintWriter
*
* @exception ResourceException
*/
public void setLogWriter(PrintWriter out) throws ResourceException {
ConnectorStatus.getConnectorStatus().logAPI("MDCompleteMCF.setLogWriter",
"out", "");
}
/*
* @name getLogWriter
*
* @desc Gets the Print Writer
*
* @return PrintWriter
*
* @exception ResourceException
*/
public PrintWriter getLogWriter() throws ResourceException {
ConnectorStatus.getConnectorStatus().logAPI("MDCompleteMCF.getLogWriter",
"", "");
return null;
}
/*
* @name equals
*
* @desc Compares the given object to the ManagedConnectionFactory instance.
*
* @param Object
*
* @return boolean
*/
public boolean equals(Object obj) {
if ((obj == null) || !(obj instanceof MDCompleteMCF)) {
return false;
}
if (obj == this) {
return true;
}
MDCompleteMCF that = (MDCompleteMCF) obj;
if ((this.reference != null)
&& !(this.reference.equals(that.getReference()))) {
return false;
} else if ((this.reference == null) && !(that.getReference() == null)) {
return false;
}
if ((this.resourceAdapter != null)
&& !(this.resourceAdapter.equals(that.getResourceAdapter()))) {
return false;
} else if ((this.resourceAdapter == null)
&& !(that.getResourceAdapter() == null)) {
return false;
}
if (this.count != that.getCount()) {
return false;
}
if (!Util.isEqual(this.password, that.getPassword()))
return false;
if (!Util.isEqual(this.user, that.getUser()))
return false;
if (!Util.isEqual(this.userName, that.getUserName()))
return false;
if (!Util.isEqual(this.TSRValue, that.getTSRValue()))
return false;
if (!Util.isEqual(this.factoryName, that.getFactoryName()))
return false;
return true;
}
/*
* @name hashCode
*
* @desc Gives a hash value to a ManagedConnectionFactory Obejct.
*
* @return int
*/
public int hashCode() {
return this.getClass().getName().hashCode();
}
/*
* @name getReference
*
* @desc Gives the reference of the class
*
* @return javax.naming.Reference
*/
public javax.naming.Reference getReference() {
javax.naming.Reference ref;
ref = this.reference;
return ref;
}
/*
* @name setReference
*
* @desc sets the reference of the class
*
* @param javax.naming.Reference
*/
public void setReference(javax.naming.Reference ref) {
this.reference = ref;
}
public void debug(String out) {
Debug.trace("MDCompleteMCF: " + out);
}
public int getCount() {
return this.count;
}
public void setCount(int val) {
this.count = val;
}
}