KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > appserver > server > sql > informix > InformixDBTransaction


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: InformixDBTransaction.java,v 1.1 2004/09/03 13:42:52 sinisa Exp $
22  */

23 package com.lutris.appserver.server.sql.informix;
24
25 import java.sql.SQLException JavaDoc;
26 import org.enhydra.dods.DODS;
27 import com.lutris.appserver.server.sql.DatabaseManagerException;
28 import com.lutris.appserver.server.sql.standard.StandardDBTransaction;
29
30 /**
31  * Informix implementation of SQL database transaction.
32  *
33  * @author Kyle Clark
34  * @since LBS1.8
35  * @version $Revision: 1.1 $
36  */

37 public class InformixDBTransaction extends StandardDBTransaction {
38
39     /**
40      * The connection to the informix database.
41      */

42     protected InformixDBConnection conn;
43
44     /**
45      * Private constructor. Used if connection is already known.
46      *
47      * @param conn
48      * The database connection to use.
49      * @exception java.sql.SQLException
50      * If a database access error occurs.
51      */

52     protected InformixDBTransaction(InformixDBConnection conn)
53         throws SQLException JavaDoc {
54         super(conn);
55         this.conn = conn;
56         try {
57             setTransactionTimeout(conn.logicalDatabase.getDefaultTransactionTimeout());
58         } catch (SQLException JavaDoc sqlExcept) {
59             conn.handleException(sqlExcept);
60             conn.release();
61             throw sqlExcept;
62         }
63     }
64
65     /**
66      * Public constructor. Establishes a connection with the default
67      * logical database.
68      * The connection manager must have been initialized with
69      * a default logical database name.
70      *
71      * @exception java.sql.SQLException
72      * If a database access error occurs.
73      * @exception DatabaseManagerException
74      * If the default logical database wasn't initialized in the
75      * Database Manager.
76      * @exception ClassCastException
77      * If the default database manager doesn't allocate connections
78      * of type InformixDBConnection.
79      * @see com.lutris.appserver.server.sql.DatabaseManager#setDefaultDatabase
80      */

81     public InformixDBTransaction()
82         throws SQLException JavaDoc, DatabaseManagerException {
83         this((InformixDBConnection) DODS.getDatabaseManager().allocateConnection());
84     }
85
86     /**
87      * Public constructor. Establishes a connection with the specified
88      * logical database name.
89      *
90      * @param dbName
91      * Logical database name to access.
92      * @exception java.sql.SQLException
93      * If a database access error occurs.
94      * @exception DatabaseManagerException
95      * If a nonexistent logical database name is supplied.
96      */

97     public InformixDBTransaction(String JavaDoc dbName)
98         throws SQLException JavaDoc, DatabaseManagerException {
99         this((InformixDBConnection) DODS.getDatabaseManager().allocateConnection(dbName));
100     }
101
102     /**
103      * Set transaction time out. If a transaction blocks, then it will only
104      * block as long as specified here.
105      *
106      * @param seconds
107      * The amount of time to block in seconds. If less than zero then blocks
108      * indefinitly.
109      * @exception SQLException if a database error occurs.
110      */

111     public void setTransactionTimeout(int seconds) throws SQLException JavaDoc {
112         try {
113             logDebug("set transaction time out to " + seconds);
114             conn.setLockModeToWait(seconds);
115         } catch (SQLException JavaDoc e) {
116             handleException(e);
117             throw e;
118         }
119     }
120 }
121
Popular Tags