KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > db > jtx > DbJtxResourceManager


1 // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
2

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 /**
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 JavaDoc resourceType;
19
20     public static final String JavaDoc DEFAULT_RESOURCE_TYPE = "jodd.db.tx";
21
22     /**
23      * Creates resource manager for specified resource type.
24      */

25     public DbJtxResourceManager(ConnectionProvider connectionProvider, String JavaDoc resourceType) {
26         this.connectionProvider = connectionProvider;
27         this.resourceType = resourceType;
28     }
29
30     /**
31      * Resource manager with default resource type id. It can be used in most cases when
32      * only one connection provider is used in application.
33      */

34     public DbJtxResourceManager(ConnectionProvider connectionProvider) {
35         this(connectionProvider, DEFAULT_RESOURCE_TYPE);
36     }
37
38     // ---------------------------------------------------------------- resource manager
39

40     /**
41      * @see jodd.jtx.JtxResourceManager#createResource()
42      */

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     /**
51      * @see jodd.jtx.JtxResourceManager#getResourceType()
52      */

53     public String JavaDoc getResourceType() {
54         return resourceType;
55     }
56
57     /**
58      * @see jodd.jtx.JtxResourceManager#close()
59      */

60     public void close() {
61         if (connectionProvider != null) {
62             connectionProvider.close();
63         }
64         connectionProvider = null;
65     }
66 }
67
Popular Tags