01: // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
02:
03: package jodd.db.jtx;
04:
05: import jodd.jtx.JtxResourceManager;
06: import jodd.jtx.JtxResource;
07: import jodd.db.connection.ConnectionProvider;
08: import jodd.db.DbSqlException;
09:
10: /**
11: * Database {@link jodd.jtx.JtxResourceManager}. It creates {@link jodd.db.DbSession} resources
12: * when simple jtx mechanism is in use..
13: */
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: /**
23: * Creates resource manager for specified resource type.
24: */
25: public DbJtxResourceManager(ConnectionProvider connectionProvider,
26: String resourceType) {
27: this .connectionProvider = connectionProvider;
28: this .resourceType = resourceType;
29: }
30:
31: /**
32: * Resource manager with default resource type id. It can be used in most cases when
33: * only one connection provider is used in application.
34: */
35: public DbJtxResourceManager(ConnectionProvider connectionProvider) {
36: this (connectionProvider, DEFAULT_RESOURCE_TYPE);
37: }
38:
39: // ---------------------------------------------------------------- resource manager
40:
41: /**
42: * @see jodd.jtx.JtxResourceManager#createResource()
43: */
44: public JtxResource createResource() {
45: if (connectionProvider == null) {
46: throw new DbSqlException(
47: "Database resource manager is closed.");
48: }
49: return new DbJtxSession(connectionProvider);
50: }
51:
52: /**
53: * @see jodd.jtx.JtxResourceManager#getResourceType()
54: */
55: public String getResourceType() {
56: return resourceType;
57: }
58:
59: /**
60: * @see jodd.jtx.JtxResourceManager#close()
61: */
62: public void close() {
63: if (connectionProvider != null) {
64: connectionProvider.close();
65: }
66: connectionProvider = null;
67: }
68: }
|