KickJava   Java API By Example, From Geeks To Geeks.

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


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: InformixDBConnection.java,v 1.1 2004/09/03 13:42:50 sinisa Exp $
22  */

23 package com.lutris.appserver.server.sql.informix;
24
25 import java.sql.SQLException JavaDoc;
26
27 import com.lutris.appserver.server.sql.ConnectionAllocator;
28 import com.lutris.appserver.server.sql.standard.StandardDBConnection;
29
30 /**
31  * An Informix database connection.
32  *
33  * @see com.lutris.appserver.server.sql.DBConnection
34  * @author Kyle Clark
35  * @since LBS1.7
36  * @version $Revision: 1.1 $
37  */

38 public class InformixDBConnection extends StandardDBConnection {
39
40     /**
41      * The amound time to wait on a query or transaction.
42      */

43     private int lockModeWait = 0;
44
45     /**
46      * The logical database for this connection.
47      */

48     protected InformixLogicalDatabase logicalDatabase;
49
50     /**
51      * Create a connection to an Informix database.
52      *
53      * @param url JDBC URL of database.
54      * @param user SQL user name.
55      * @param password SQL password.
56      * @param maxPreparedStatements Maximum number of preparse statements.
57      * A value of less than zero queries JDBC for the value.
58      * @param connectionAllocator The connection allocator that this
59      * connection belongs to.
60      * @param logging Specifying <CODE>true</CODE> enables SQL logging.
61      * @param generation A generation number used to drop old connection
62      * when they are released.
63      * @exception java.sql.SQLException If a connection can't be established.
64      */

65     protected InformixDBConnection(InformixConnectionAllocator connectionAllocator,
66             String JavaDoc url, String JavaDoc user, String JavaDoc password,
67             int maxPreparedStatements,
68             boolean logging, int generation)
69         throws SQLException JavaDoc {
70         super((ConnectionAllocator)connectionAllocator, url, user, password, maxPreparedStatements,
71                 logging, generation);
72         this.logicalDatabase = connectionAllocator.logicalDatabase;
73     }
74
75     /**
76      * Specify if you prefer to wait for locks instead of generating
77      * errors.
78      *
79      * @param on
80      * True if you prefer to wait, false otherwise.
81      * @exception java.sql.SQLException
82      * If a database access error occurs.
83      */

84     public synchronized void setLockModeToWait(boolean on)
85         throws SQLException JavaDoc {
86         if (on) {
87             setLockModeToWait(-1);
88         } else {
89             setLockModeToWait(0);
90         }
91     }
92
93     /**
94      * Specify if you prefer to wait for locks for the specified
95      * amount of time before an exception is thrown.
96      *
97      * @param seconds
98      * The number of seconds to wait. If seconds is == 0
99      * the waiting is disabled. If seconds is less than
100      * 0 then wait indefinitly.
101      * @exception java.sql.SQLException
102      * If a database access error occurs.
103      */

104     public synchronized void setLockModeToWait(int seconds)
105         throws SQLException JavaDoc {
106         if (lockModeWait != seconds) {
107             logDebug("set lock mode to wait " + seconds);
108             if (seconds > 0) {
109                 execute("SET LOCK MODE TO WAIT " + seconds);
110             } else if (seconds == 0) {
111                 execute("SET LOCK MODE TO NOT WAIT");
112             } else {
113                 execute("SET LOCK MODE TO WAIT");
114             }
115             lockModeWait = seconds;
116         }
117     }
118 }
119
Popular Tags