View Javadoc
1 /* 2 QueryJ 3 4 Copyright (C) 2002 Jose San Leandro Armend?riz 5 jsanleandro@yahoo.es 6 chousz@yahoo.com 7 8 This library is free software; you can redistribute it and/or 9 modify it under the terms of the GNU General Public 10 License as published by the Free Software Foundation; either 11 version 2.1 of the License, or (at your option) any later version. 12 13 This library is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 Lesser General Public License for more details. 17 18 You should have received a copy of the GNU General Public 19 License along with this library; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 22 Thanks to ACM S.L. for distributing this library under the GPL license. 23 Contact info: jsanleandro@yahoo.es 24 Postal Address: c/Playa de Lagoa, 1 25 Urb. Valdecaba?as 26 Boadilla del monte 27 28660 Madrid 28 Spain 29 30 ****************************************************************************** 31 * 32 * Filename: $RCSfile: TransactionTokenFactory.java,v $ 33 * 34 * Author: Jose San Leandro Armend?riz 35 * 36 * Description: Has the responsibility of creating transaction tokens. 37 * Right now, it follows the FactoryMethod pattern, but could be 38 * refactored as an abstract factory as new technologies are 39 * supported. 40 * 41 * Last modified by: $Author: chous $ at $Date: 2003/08/29 08:15:00 $ 42 * 43 * File version: $Revision: 1.1 $ 44 * 45 * Project version: $Name: $ 46 * 47 * $Id: TransactionTokenFactory.java,v 1.1 2003/08/29 08:15:00 chous Exp $ 48 * 49 */ 50 package org.acmsl.queryj.dao; 51 52 /* 53 * Importing some JDK classes. 54 */ 55 import java.lang.ref.WeakReference; 56 57 /* 58 * Importing some extension classes. 59 */ 60 import javax.sql.DataSource; 61 62 /*** 63 * Has the responsibility of creating transaction tokens. Right now, it 64 * follows the FactoryMethod pattern, but could be refactored as an abstract 65 * factory as new technologies are supported. 66 * @author <a href="mailto:jsanleandro@yahoo.es" 67 >Jose San Leandro Armend?riz</a> 68 * @version $Revision: 1.1 $ 69 */ 70 public abstract class TransactionTokenFactory 71 { 72 /*** 73 * Singleton implemented as a weak reference. 74 */ 75 private static WeakReference singleton; 76 77 /*** 78 * Protected constructor to avoid accidental instantiation. 79 */ 80 protected TransactionTokenFactory() {}; 81 82 /*** 83 * Specifies a new weak reference. 84 * @param factory the factory instance to use. 85 */ 86 protected static void setReference(TransactionTokenFactory factory) 87 { 88 singleton = new WeakReference(factory); 89 } 90 91 /*** 92 * Retrieves the weak reference. 93 * @return such reference. 94 */ 95 protected static WeakReference getReference() 96 { 97 return singleton; 98 } 99 100 /*** 101 * Retrieves a TransactionTokenFactory instance. 102 * @return such instance. 103 */ 104 public static TransactionTokenFactory getInstance() 105 { 106 TransactionTokenFactory result = null; 107 108 WeakReference reference = getReference(); 109 110 if (reference != null) 111 { 112 result = (TransactionTokenFactory) reference.get(); 113 } 114 115 if (result == null) 116 { 117 result = new TransactionTokenFactory() {}; 118 119 setReference(result); 120 } 121 122 return result; 123 } 124 125 /*** 126 * Creates a SingleConnectionTransactionToken using given connection. 127 * @param dataSource the data source to use inside the same transaction. 128 * @return the transaction token, or null if the connection is invalid. 129 */ 130 public static DataSourceTransactionToken createTransactionToken( 131 DataSource dataSource) 132 { 133 DataSourceTransactionToken result = null; 134 135 if (dataSource != null) 136 { 137 result = new DataSourceTransactionToken(dataSource) {}; 138 } 139 140 return result; 141 } 142 }

This page was automatically generated by Maven