1 3 package jodd.db.jtx; 4 5 import jodd.jtx.JtxResourceManager; 6 import jodd.jtx.JtxResource; 7 import jodd.db.connection.ConnectionProvider; 8 import jodd.db.DbSqlException; 9 10 14 public class DbJtxResourceManager implements JtxResourceManager { 15 16 protected ConnectionProvider connectionProvider; 17 18 protected String resourceType; 19 20 public static final String DEFAULT_RESOURCE_TYPE = "jodd.db.tx"; 21 22 25 public DbJtxResourceManager(ConnectionProvider connectionProvider, String resourceType) { 26 this.connectionProvider = connectionProvider; 27 this.resourceType = resourceType; 28 } 29 30 34 public DbJtxResourceManager(ConnectionProvider connectionProvider) { 35 this(connectionProvider, DEFAULT_RESOURCE_TYPE); 36 } 37 38 40 43 public JtxResource createResource() { 44 if (connectionProvider == null) { 45 throw new DbSqlException("Database resource manager is closed."); 46 } 47 return new DbJtxSession(connectionProvider); 48 } 49 50 53 public String getResourceType() { 54 return resourceType; 55 } 56 57 60 public void close() { 61 if (connectionProvider != null) { 62 connectionProvider.close(); 63 } 64 connectionProvider = null; 65 } 66 } 67 | Popular Tags |