KickJava   Java API By Example, From Geeks To Geeks.

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


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: InformixDBQuery.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.StandardDBQuery;
29
30 /**
31  * An Informix database query object.
32  *
33  * @author Kyle Clark
34  * @since LBS1.7
35  * @version $Revision: 1.1 $
36  */

37 public class InformixDBQuery extends StandardDBQuery {
38
39     /**
40      * Amount of time (seconds) to wait on locks before
41      * throwing an exception.
42      * @see setQueryTimeOut
43      */

44     private int queryTimeout = 0;
45
46     /**
47      * The informix database connection.
48      */

49     protected InformixDBConnection conn;
50
51     /**
52      * Private constructor.
53      *
54      * @param dbConnection
55      * The database connection to use.
56      * @exception SQLException
57      * If a database access error occurs.
58      */

59     protected InformixDBQuery(InformixDBConnection dbConnection)
60         throws SQLException JavaDoc {
61         super(dbConnection);
62         this.conn = dbConnection;
63         try {
64             setQueryTimeout(dbConnection.logicalDatabase.getDefaultQueryTimeout());
65         } catch (SQLException JavaDoc sqlExcept) {
66             handleException(sqlExcept);
67             dbConnection.release();
68             throw sqlExcept;
69         }
70     }
71
72     /**
73      * Public constructor. Establishes a connection with the default
74      * logical database. The connection manager must have been
75      * initialized with a default logical database name.
76      *
77      *
78      * @exception SQLException
79      * If a database access error occurs.
80      * @exception DatabaseManagerException
81      * If the default logical database wasn't initialized in the
82      * Database Manager.
83      * @see
84      * com.lutris.appserver.server.sql.DatabaseManager#setDefaultDatabase
85      */

86     public InformixDBQuery()
87         throws SQLException JavaDoc, DatabaseManagerException {
88         this((InformixDBConnection) DODS.getDatabaseManager().allocateConnection());
89     }
90
91     /**
92      * Public constructor. Establishes a connection to the specified
93      * logical database name.
94      *
95      * @param dbName
96      * Logical database name to access.
97      * @exception SQLException
98      * If a database access error occurs.
99      * @exception DatabaseManagerException
100      * If a nonexistant logical database name is supplied.
101      */

102     public InformixDBQuery(String JavaDoc dbName)
103         throws SQLException JavaDoc, DatabaseManagerException {
104         this((InformixDBConnection) DODS.getDatabaseManager().allocateConnection(dbName));
105     }
106
107     /**
108      * Set query time out. If a query blocks, then it will only
109      * block as long as specified here.
110      *
111      * @param seconds
112      * The amount of time to block.
113      * @exception SQLException if a database error occurs.
114      */

115     public void setQueryTimeout(int seconds)
116         throws SQLException JavaDoc {
117         try {
118             logDebug("set query time out to " + seconds);
119             conn.setLockModeToWait(queryTimeout);
120             queryTimeout = seconds;
121         } catch (SQLException JavaDoc e) {
122             handleException(e);
123             throw e;
124         }
125     }
126 }
127
Popular Tags