summaryrefslogtreecommitdiff
path: root/java/jca/src/main/java/org/apache/qpid/ra/QpidRAConnectionRequestInfo.java
blob: 779709839a1c3dcd21eefc3ac0208690ebf252ed (plain)
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
/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */

package org.apache.qpid.ra;

import javax.jms.Session;
import javax.resource.ResourceException;
import javax.resource.spi.ConnectionRequestInfo;

import org.apache.qpid.jms.ConnectionURL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Connection request information
 *
 */
public class QpidRAConnectionRequestInfo implements ConnectionRequestInfo
{
   /** The logger */
   private static final Logger _log = LoggerFactory.getLogger(QpidRAConnectionRequestInfo.class);

   /** The user name */
   private String _userName;

   /** The password */
   private String _password;

   /** The client id */
   private String _clientId;

   /** The type */
   private final int _type;

   /** Use transactions */
   private final boolean _transacted;

   /** The acknowledge mode */
   private final int _acknowledgeMode;

   /**
    * Constructor
    * @param ra The resource adapter.
    * @param type The connection type
    * @throws ResourceException
    */
   public QpidRAConnectionRequestInfo(final QpidResourceAdapter ra, final int type)
      throws ResourceException
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("constructor(" + ra + ")");
      }

      final QpidRAProperties properties = ra.getProperties() ;
      if (properties.getConnectionURL() != null)
      {
         final ConnectionURL connectionURL = ra.getDefaultAMQConnectionFactory().getConnectionURL() ;
         _userName = connectionURL.getUsername();
         _password = connectionURL.getPassword();
         _clientId = connectionURL.getClientName();
      }
      else
      {
         _userName = ra.getUserName();
         _password = ra.getPassword();
         _clientId = ra.getClientId();
      }
      this._type = type;
      _transacted = true;
      _acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
   }

   /**
    * Constructor
    * @param type The connection type
    */
   public QpidRAConnectionRequestInfo(final int type)
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("constructor(" + type + ")");
      }

      this._type = type;
      _transacted = true;
      _acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
   }

   /**
    * Constructor
    * @param transacted Use transactions
    * @param acknowledgeMode The acknowledge mode
    * @param type The connection type
    */
   public QpidRAConnectionRequestInfo(final boolean transacted, final int acknowledgeMode, final int type)
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("constructor(" + transacted +
                                                  ", " +
                                                  acknowledgeMode +
                                                  ", " +
                                                  type +
                                                  ")");
      }

      this._transacted = transacted;
      this._acknowledgeMode = acknowledgeMode;
      this._type = type;
   }

   /**
    * Fill in default values if they are missing
    * @param connectionURL The connection URL
    */
   public void setDefaults(final ConnectionURL connectionURL)
   {
      if (_userName == null)
      {
         _userName = connectionURL.getUsername();
      }
      if (_password == null)
      {
         _password = connectionURL.getPassword();
      }
      if (_clientId == null)
      {
         _clientId = connectionURL.getClientName();
      }
   }

   /**
    * Fill in default values if they are missing
    * @param ra The resource adapter
    * @throws ResourceException
    */
   public void setDefaults(final QpidResourceAdapter ra)
      throws ResourceException
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("setDefaults(" + ra + ")");
      }

      final QpidRAProperties properties = ra.getProperties() ;
      if (properties.getConnectionURL() != null)
      {
         setDefaults(ra.getDefaultAMQConnectionFactory().getConnectionURL()) ;
      }
      else
      {
         if (_userName == null)
         {
            _userName = ra.getUserName();
         }
         if (_password == null)
         {
            _password = ra.getPassword();
         }
         if (_clientId == null)
         {
            _clientId = ra.getClientId();
         }
      }
   }

   /**
    * Get the user name
    * @return The value
    */
   public String getUserName()
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("getUserName()");
      }

      return _userName;
   }

   /**
    * Set the user name
    * @param userName The value
    */
   public void setUserName(final String userName)
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("setUserName(" + userName + ")");
      }

      this._userName = userName;
   }

   /**
    * Get the password
    * @return The value
    */
   public String getPassword()
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("getPassword()");
      }

      return _password;
   }

   /**
    * Set the password
    * @param password The value
    */
   public void setPassword(final String password)
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("setPassword(****)");
      }

      this._password = password;
   }

   /**
    * Get the client id
    * @return The value
    */
   public String getClientId()
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("getClientID()");
      }

      return _clientId;
   }

   /**
    * Set the client id
    * @param clientID The value
    */
   public void setClientId(final String clientID)
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("setClientID(" + clientID + ")");
      }

      this._clientId = clientID;
   }

   /**
    * Get the connection type
    * @return The type
    */
   public int getType()
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("getType()");
      }

      return _type;
   }

   /**
    * Use transactions
    * @return True if transacted; otherwise false
    */
   public boolean isTransacted()
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("isTransacted() " + _transacted);
      }

      return _transacted;
   }

   /**
    * Get the acknowledge mode
    * @return The mode
    */
   public int getAcknowledgeMode()
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("getAcknowledgeMode()");
      }

      return _acknowledgeMode;
   }

   /**
    * Indicates whether some other object is "equal to" this one.
    * @param obj Object with which to compare
    * @return True if this object is the same as the obj argument; false otherwise.
    */
   @Override
   public boolean equals(final Object obj)
   {
      if (obj instanceof QpidRAConnectionRequestInfo)
      {
         QpidRAConnectionRequestInfo you = (QpidRAConnectionRequestInfo)obj;
         return Util.compare(_userName, you.getUserName()) && Util.compare(_password, you.getPassword()) &&
                Util.compare(_clientId, you.getClientId()) &&
                _type == you.getType() &&
                _transacted == you.isTransacted() &&
                _acknowledgeMode == you.getAcknowledgeMode();
      }
      else
      {
         return false;
      }
   }

   /**
    * Return the hash code for the object
    * @return The hash code
    */
   @Override
   public int hashCode()
   {
      int hash = 7;

      hash += 31 * hash + (_userName != null ? _userName.hashCode() : 0);
      hash += 31 * hash + (_password != null ? _password.hashCode() : 0);
      hash += 31 * hash + (_clientId != null ? _clientId.hashCode() : 0);
      hash += 31 * hash + _type;
      hash += 31 * hash + (_transacted ? 1 : 0);
      hash += 31 * hash + _acknowledgeMode;

      return hash;
   }

   @Override
   public String toString()
   {
      return "QpidRAConnectionRequestInfo[type=" + _type +
         ", transacted=" + _transacted + ", acknowledgeMode=" + _acknowledgeMode +
         ", clientID=" + _clientId + ", userName=" + _userName + ((_password != null) ? ", password=********]" :"]");
   }
}