View Javadoc

1   package org.csc.phynixx.xa;
2   
3   /*
4    * #%L
5    * phynixx-xa
6    * %%
7    * Copyright (C) 2014 csc
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  
24  import org.csc.phynixx.connection.*;
25  
26  
27  /**
28   * @author Christoph Schmidt-Casdorff
29   */
30  class LocalTransactionProxy<C extends IPhynixxConnection> extends PhynixxManagedConnectionListenerAdapter<C> implements IPhynixxManagedConnectionListener<C>, ITransactionBinding<C> {
31  
32      // private TransactionManager tmMgr = null;
33  
34      private IPhynixxManagedConnection<C> connection;
35  
36  
37      LocalTransactionProxy(IPhynixxManagedConnection<C> connection) {
38          this.connection = connection;
39          this.connection.addConnectionListener(this);
40      }
41  
42      /**
43       * @return indicates if the transaction has uncomnmitted transactional data
44       */
45      boolean hasTransactionalData() {
46          return this.connection!=null && connection.hasTransactionalData();
47      }
48  
49      boolean isClosed() {
50          return this.getConnection() == null || this.getConnection().isClosed();
51      }
52  
53  
54      @Override
55      public TransactionBindingType getTransactionBindingType() {
56          return TransactionBindingType.LocalTransaction;
57      }
58  
59      /**
60       * releases and closes the associated TransactionalBranch
61       */
62      @Override
63      public void release() {
64          if (connection != null) {
65              this.connection.removeConnectionListener(this);
66          }
67          this.connection = null;
68      }
69  
70      @Override
71      public void close() {
72          if (connection != null) {
73              IPhynixxManagedConnection<C> connection=this.connection;
74          this.release();
75          connection.close();
76      }
77  
78      }
79  
80      @Override
81      public IPhynixxManagedConnection<C> getConnection() {
82          return connection;
83      }
84  
85  
86  
87  
88      @Override
89      public void connectionReleased(IManagedConnectionEvent<C> event) {
90          event.getManagedConnection().removeConnectionListener(this);
91      }
92  
93      @Override
94      public void connectionFreed(IManagedConnectionEvent<C> event) {
95          event.getManagedConnection().removeConnectionListener(this);
96      }
97  }