1 /**
2  *  Copyright Terracotta, Inc.
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  */

16 package net.sf.ehcache.transaction.manager.selector;
17
18 import net.sf.ehcache.transaction.xa.EhcacheXAResource;
19
20 import javax.transaction.TransactionManager;
21
22 /**
23  * Abstract class which is used to do various things related to JTA transaction managers,
24  * like looking them up, registering XAResources for recovery...
25  *
26  * @author Ludovic Orban
27  */

28 public abstract class Selector {
29
30     private final String vendor;
31     private volatile TransactionManager transactionManager;
32
33     /**
34      * Constructor
35      *
36      * @param vendor an indicative transaction manager vendor name
37      *               this selector is working with.
38      */

39     protected Selector(String vendor) {
40         this.vendor = vendor;
41     }
42
43     /**
44      * Get the vendor name
45      * @return the vendor name
46      */

47     public String getVendor() {
48         return vendor;
49     }
50
51     /**
52      * Get the transaction manager, looking it up if necessary.
53      * Once the transaction manager has been looked up, its reference is cached.
54      * @return the transaction manager
55      */

56     public TransactionManager getTransactionManager() {
57         if (transactionManager == null) {
58             transactionManager = doLookup();
59         }
60         return transactionManager;
61     }
62
63     /**
64      * Register an XAResource with the transaction manager.
65      *
66      * @param ehcacheXAResource the XAResource
67      * @param forRecovery true if this XAResource is being registered purely for recovery purpose
68      */

69     public void registerResource(EhcacheXAResource ehcacheXAResource, boolean forRecovery) {
70     }
71
72     /**
73      * Unregister an XAResource from the transaction manager.
74      *
75      * @param ehcacheXAResource the XAResource
76      * @param forRecovery true if this XAResource was registered purely for recovery purpose
77      */

78     public void unregisterResource(EhcacheXAResource ehcacheXAResource, boolean forRecovery) {
79     }
80
81     /**
82      * Lookup the transaction manager.
83      *
84      * @return the transaction manager, or null if it could not be looked up.
85      */

86     protected abstract TransactionManager doLookup();
87
88 }
89