KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > appserver > server > sql > standard > StandardDBConnection


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: StandardDBConnection.java,v 1.3 2005/03/24 13:44:51 predrag Exp $
22  *
23  * formatted with JxBeauty (c) johann.langhofer@nextra.at
24  */

25 package com.lutris.appserver.server.sql.standard;
26
27 import com.lutris.appserver.server.sql.*;
28 import java.sql.*;
29
30 import com.lutris.logging.Logger;
31 import java.util.Enumeration JavaDoc;
32 import java.util.Hashtable JavaDoc;
33 import org.enhydra.dods.Common;
34 import org.enhydra.dods.DODS;
35
36 /**
37  * Standard implementation of the DBConnection object.
38  *
39  * @see DBConnection
40  * @author Mark Diekhans
41  * @author Kyle Clark
42  * @since LBS1.7
43  * @version $Revision: 1.3 $
44  */

45 public class StandardDBConnection implements ExtendedDBConnection {
46
47     /** JDBC connection object. */
48     protected Connection connection;
49
50     /** Database URL, used for error messages. */
51     protected String JavaDoc url;
52
53     /** Database user, for error messages. */
54     protected String JavaDoc user;
55
56     /** Database user password. */
57     protected String JavaDoc password;
58     // Identifier for this connection.
59
protected int id;
60     // Next available identifier for a connection.
61
protected static int nextId = 0;
62     // Table of prepared (compiled) statements, keyed by SQL.
63
protected Hashtable JavaDoc preparedStmtCache;
64     // The last statement used by this connection.
65
protected Statement currentStmt = null;
66     // The connection allocator this connection is associated with.
67
protected ConnectionAllocator connectionAllocator;
68     // Indicates if logging is enabled.
69
protected boolean logging;
70     // Generation number assigned and used by StandardConnectionAllocator.
71
protected int generation;
72     // Has this connection been closed.
73
protected boolean closed = false;
74     // Do we need to drop this connection?
75
protected boolean dropConnection = false;
76     // Has this connection been dropped?
77
protected boolean dropped = false;
78     // Has this connectio been closed.
79
protected boolean reset = true;
80     // Is this connection currently in use.
81
protected boolean allocated = false;
82     // Maximum number of open statements.
83
protected int maxPreparedStmts;
84     // the number of times a particular DBConnection was allocated;
85
protected int connectionUsageCounter=0;
86     // Time when connection is released to pool;
87
protected long connectionEnterPoolTime = -1;
88     /**
89      * The log channel.
90      */

91     // private LogChannel channel = DODS.getLogChannel();
92

93     /**
94      * Initialize the connection to a database.
95      *
96      * @param url JDBC URL of database.
97      * @param user SQL user name.
98      * @param password SQL password.
99      * @param connectionAllocatorObj The connection allocator that this
100      * connection belongs to.
101      * @param maxPreparedStatements Maximum number of preparse statements.
102      * a value of less than zero queries JDBC for the value.
103      * @param logging Specifying <CODE>true</CODE> enables SQL logging.
104      * @param generation A generation number used to drop old connection
105      * when they are released.
106      * @exception java.sql.SQLException If a connection can't be established.
107      */

108     public StandardDBConnection(ConnectionAllocator connectionAllocatorObj,
109                                 String JavaDoc url, String JavaDoc user, String JavaDoc password, int maxPreparedStatements,
110                                 boolean logging, int generation)
111         throws SQLException {
112         id = nextId++;
113         this.preparedStmtCache = new Hashtable JavaDoc();
114         this.connectionAllocator = connectionAllocatorObj;
115         this.url = url;
116         this.user = user;
117         this.password = password;
118         this.logging = logging;
119         this.generation = generation;
120         connection = DriverManager.getConnection(url, user, password);
121         currentStmt = connection.createStatement();
122         if (maxPreparedStatements < 0) {
123             // One UN-prepared statement is used up.
124
this.maxPreparedStmts = connection.getMetaData().getMaxStatements()
125                 - 1;
126             if (this.maxPreparedStmts == 0) {
127                 // Some (Microsoft) JDBC drivers return apparently incorrect
128
// value of 1, so we set this to 1, instead of throwing an
129
// error since it still works.
130
this.maxPreparedStmts = 1;
131             }
132             if (this.maxPreparedStmts < 0) {
133                 // Take a wild guess here and assume that if
134
// getMaxStatements returns '0', then it really
135
// means 'unlimited'. Assign an arbitrary number.
136
this.maxPreparedStmts = 256;
137             }
138         } else {
139             this.maxPreparedStmts = maxPreparedStatements;
140         }
141         logDebug("DBConnection[" + id + "]: " + url
142                      + "\nNew connection allocated.\n");
143         connectionEnterPoolTime = System.currentTimeMillis();
144     }
145
146     /**
147      * Method called when this connection object is allocated from the
148      * connection allocator.
149      *
150      * @exception java.sql.SQLException If <CODE>reset</CODE> had no
151      * been called on the previous operation.
152      */

153     public synchronized void allocate() throws SQLException {
154         logDebug("allocate");
155         try {
156             closedCheck();
157             reset();
158         } catch (SQLException e) {
159             handleException(e);
160             //
161
// If this connection is no longer valid we need
162
// to drop it.
163
//
164
if (dropConnection) {
165                 drop();
166             } else {
167                 release();
168             }
169             throw e;
170         }
171         reset = false;
172         allocated = true;
173     }
174
175     /**
176      * Check to see that the previous database connection
177      * has had reset called. This ensures that the database
178      * resources have always been freed in a timely manner.
179      *
180      * @exception java.sql.SQLException
181      * If <CODE>reset</CODE> has not
182      * been called on the previous operation.
183      */

184     protected void resetCheck() throws SQLException {
185         logDebug("resetCheck()");
186         if (!reset) {
187             throw new java.sql.SQLException JavaDoc("DBConnection.reset() was not called after the previous "
188                                                  + "operation completed");
189         }
190     }
191
192     /**
193      * Check to see that this database connection has
194      * has been properly allocated before is is used.
195      *
196      * @exception java.sql.SQLException
197      * If it was not properly allocated.
198      */

199     protected void allocatedCheck() throws SQLException {
200         logDebug("allocatedCheck()");
201         if (!allocated) {
202             throw new java.sql.SQLException JavaDoc("attempt to access connection which was released.");
203         }
204     }
205
206     /**
207      * Check to see that this database connection has
208      * has not been closed.
209      *
210      * @exception java.sql.SQLException
211      * If it is closed.
212      */

213     protected void closedCheck() throws SQLException {
214         logDebug("closedCheck()");
215         if (closed || getConnection().isClosed()) {
216             throw new java.sql.SQLException JavaDoc("attempt to access a closed connection.");
217         }
218     }
219
220     /**
221      * Validates this connection. Check to see that it
222      * is not closed and has been properly allocated.
223      *
224      * @exception java.sql.SQLException
225      * If it is not valid.
226      */

227     public void validate() throws SQLException {
228         logDebug("validate()");
229         allocatedCheck();
230         closedCheck();
231     }
232
233     /**
234      * Closes down all query-specific resources.
235      *
236      * @exception java.sql.SQLException If a database error occurs.
237      */

238     public synchronized void reset() throws SQLException {
239         // Try to cleanup everything, but save the first error.
240
SQLException saveExcept = null;
241
242         if (reset) {
243             return;
244         }
245         logDebug("reset");
246         try {
247             connection.clearWarnings();
248         } catch (SQLException except) {
249             if (saveExcept == null) {
250                 saveExcept = except;
251             }
252         }
253         try {
254             connection.setAutoCommit(false);
255         } catch (SQLException except) {
256             if (saveExcept == null) {
257                 saveExcept = except;
258             }
259         }
260         reset = true;
261         //
262
// Throw any exceptions that were generated.
263
//
264
if (saveExcept != null) {
265             throw saveExcept;
266         }
267     }
268
269     /**
270      * Get a prepared statement given an SQL string. If the statement is
271      * cached, return that statement, otherwise prepare and save in the
272      * cache.
273      *
274      * @param sql The SQL statement to prepared.
275      * @return The prepared statement, which is associated only with this
276      * connection and must not be used once the connection is released.
277      * @exception java.sql.SQLException If a SQL error occured compiling the
278      * statement.
279      */

280     public synchronized PreparedStatement prepareStatement(String JavaDoc sql)
281         throws SQLException {
282             return _prepareStatement(sql, -100, -100, false);
283     }
284
285     private synchronized PreparedStatement _prepareStatement(String JavaDoc sql, int iResultSetType, int iResultSetConcurrency, boolean tuned)
286         throws SQLException {
287         PreparedStatement preparedStmt = null;
288         String JavaDoc mapKey = sql+"=+=+"+iResultSetType+"=+=+"+iResultSetConcurrency+"=+=+";
289         if (tuned){
290              mapKey=mapKey+"tuned";
291         }
292         logDebug("Prepare statement: " + sql);
293         validate();
294         boolean selectQuery = sql.trim().toLowerCase().startsWith("select");
295         if(maxPreparedStmts>0 && !selectQuery){
296             preparedStmt = (PreparedStatement) preparedStmtCache.get(mapKey);
297             if ((preparedStmt != null) && (!preparedStmt.getConnection().isClosed())) {
298                 preparedStmt.clearParameters();
299             } else {
300                 if (preparedStmtCache.size() >= maxPreparedStmts) {
301                     String JavaDoc key = (String JavaDoc) preparedStmtCache.keys().nextElement();
302                     ((PreparedStatement) preparedStmtCache.remove(key)).close();
303                 }
304                 preparedStmt = getNewPrepStatemet(sql, iResultSetType, iResultSetConcurrency, tuned);
305                 preparedStmtCache.put(mapKey, preparedStmt);
306             }
307         }else{
308             preparedStmt = getNewPrepStatemet(sql, iResultSetType, iResultSetConcurrency, tuned);
309         }
310         return preparedStmt;
311     }
312
313     
314
315     /**
316      * @param sql The SQL statement to prepared.
317      * @param iResultSetType a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE.
318      * @param iResultSetConcurrency a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE.
319      * @param tuned Showing is PrepareStatment user tuned or use default setings
320      * @return New PreparedStatement
321      * @throws SQLException
322      */

323     private PreparedStatement getNewPrepStatemet(String JavaDoc sql, int iResultSetType, int iResultSetConcurrency, boolean tuned) throws SQLException {
324         PreparedStatement preparedStmt;
325         if(!tuned){
326             if(getResultSetType()==StandardLogicalDatabase.DEFAULT_RESULT_SET_TYPE ||
327                getResultSetConcurrency()==StandardLogicalDatabase.DEFAULT_RESULT_SET_CONCURRENCY){
328                 preparedStmt = connection.prepareStatement(sql);
329             }
330             else {
331                 preparedStmt = connection.prepareStatement(sql,getResultSetType(),getResultSetConcurrency());
332             }
333         }else{
334             preparedStmt = connection.prepareStatement(sql,iResultSetType,iResultSetConcurrency);
335         }
336         return preparedStmt;
337     }
338
339     /**
340      * Get a prepared statement given an SQL string. If the statement is
341      * cached, return that statement, otherwise prepare and save in the
342      * cache.
343      *
344      * @param sql The SQL statement to prepared.
345      * @param iResultSetType a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE.
346      * @param iResultSetConcurrency a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE.
347      * @return The prepared statement, which is associated only with this
348      * connection and must not be used once the connection is released.
349      * @exception java.sql.SQLException If a SQL error occured compiling the
350      * statement.
351      */

352     public synchronized PreparedStatement prepareStatement(String JavaDoc sql, int iResultSetType, int iResultSetConcurrency)
353         throws SQLException {
354         return _prepareStatement(sql, iResultSetType, iResultSetConcurrency, true);
355     }
356
357
358     protected int getResultSetType(){
359
360         int resultSetType;
361         try {
362             resultSetType =((StandardLogicalDatabase) DODS
363                                 .getDatabaseManager()
364                                 .findLogicalDatabase(getDatabaseName()))
365                 .getResultSetType();
366         } catch (DatabaseManagerException e) {
367             DODS.getLogChannel().write(Logger.DEBUG,"Error unknown logical database. Using default value for 'resultSetType' parameter");
368             resultSetType = StandardLogicalDatabase.DEFAULT_RESULT_SET_TYPE;
369         }
370         return resultSetType;
371     }
372
373     protected int getResultSetConcurrency(){
374
375         int resultSetConcurrency;
376         try {
377             resultSetConcurrency =((StandardLogicalDatabase) DODS
378                                        .getDatabaseManager()
379                                        .findLogicalDatabase(getDatabaseName()))
380                 .getResultSetConcurrency();
381         } catch (DatabaseManagerException e) {
382             DODS.getLogChannel().write(Logger.DEBUG,"Error unknown logical database. Using default value for 'resultSetConcurrency' parameter");
383             resultSetConcurrency = StandardLogicalDatabase.DEFAULT_RESULT_SET_CONCURRENCY;
384         }
385         return resultSetConcurrency;
386     }
387
388
389     /**
390      * Creates a CallableStatement object for calling database
391      * stored procedures. Refer to jdk api refernece.
392      *
393      * @param sql The SQL statement to be called.
394      * @return a new CallableStatement object containing the
395      * pre-compiled SQL statement.
396      * @exception java.sql.SQLException If a database access error occurs
397      * statement.
398      */

399     public synchronized CallableStatement prepareCall(String JavaDoc sql) throws SQLException {
400         return connection.prepareCall(sql);
401     }
402
403     /**
404      * Execute a prepared query statement. Once the query has completed,
405      * <CODE>reset()</CODE> should be called.
406      *
407      * @param preparedStmt The statement to execute.
408      * @param msg for logging/debug purposes
409      * @return Query result set, do not call close, use reset(),
410      * @exception java.sql.SQLException If a SQL error occured executing the
411      * statement.
412      */

413     public synchronized ResultSet executeQuery(PreparedStatement preparedStmt, String JavaDoc msg)
414         throws SQLException {
415         logDebug("Execute prepared statement: " + msg, preparedStmt);
416         validate();
417         return preparedStmt.executeQuery();
418     }
419
420     /**
421      * Execute a SQL query statement. This is a wrapper that adds logging.
422      * Once the query has completed, <CODE>reset()</CODE> should be called.
423      *
424      * @param sql The SQL query statement
425      * @return Query result set, do not call close, use reset(),
426      * @exception java.sql.SQLException If a SQL error occured executing the
427      * statement.
428      */

429     public synchronized ResultSet executeQuery(String JavaDoc sql) throws SQLException {
430         logDebug(sql);
431         validate();
432         return currentStmt.executeQuery(sql);
433     }
434
435     /**
436      * Execute a SQL update statement. This is a wrapper that adds logging.
437      * Once the update has completed, <CODE>reset()</CODE> should be called.
438      *
439      * @param sql
440      * The SQL query statement
441      * @return
442      * Either the row count for UPDATE, INSERT, DELETE or 0 for
443      * SQL statements that return nothing.
444      * @exception java.sql.SQLException
445      * If a SQL error occured executing the update.
446      */

447     public synchronized int executeUpdate(String JavaDoc sql) throws SQLException {
448         logDebug(sql);
449         validate();
450         return currentStmt.executeUpdate(sql);
451     }
452
453     /**
454      * Execute a prepared update statement. Once the update has completed,
455      * <CODE>reset()</CODE> should be called.
456      *
457      * @param preparedStmt The statement to execute.
458      * @param msg for logging/debug purposes
459      * @return Either the row count for UPDATE, INSERT, DELETE or 0 for
460      * SQL statements that return nothing.
461      * @exception java.sql.SQLException If a SQL error occured executing the
462      * statement.
463      */

464     public int executeUpdate(PreparedStatement preparedStmt, String JavaDoc msg) throws SQLException {
465         logDebug("Execute prepared statement: " + msg, preparedStmt);
466         validate();
467         return preparedStmt.executeUpdate();
468     }
469
470     /**
471      * Execute a SQL statement that does not return a resultset. This is a
472      * wrapper that adds logging. Once the query has completed,
473      * <CODE>reset()</CODE> should be called.
474      *
475      * @param sql The SQL query statement
476      * @return True if the next result is a ResultSet; false if it is
477      * an update count or there are no more results.
478      * @exception java.sql.SQLException If a SQL error occured executing the
479      * statement.
480      */

481     public synchronized boolean execute(String JavaDoc sql) throws SQLException {
482         logDebug("execute: " + sql);
483         validate();
484         return currentStmt.execute(sql);
485     }
486
487     /**
488      * Check for warnings in a result set.
489      *
490      * @param resultSet The result set to check for warnings.
491      * @exception java.sql.SQLException If a SQL error occured compiling the
492      * statement.
493      */

494     public void warningCheck(ResultSet resultSet) throws SQLException {
495         logDebug("warningCheck()");
496         SQLWarning warning = resultSet.getWarnings();
497
498         if (warning != null) {
499             throw warning;
500         }
501     }
502
503     /**
504      * Return this connection to its allocator. This object should not be
505      * used after calling this function.
506      */

507     public synchronized void release() {
508         if (allocated) {
509         logDebug("release");
510             allocated = false;
511             if (dropConnection) {
512                 drop();
513             }
514             if (!dropped){
515                 connectionAllocator.release(this);
516             }
517         }
518     }
519
520     /**
521      * Drop this connection from the connection allocator.
522      */

523     protected synchronized void drop() {
524         if (!dropped) {
525             close();
526             logDebug("drop");
527             connectionAllocator.drop(this);
528             dropped = true;
529             logDebug("DBConnection[" + id + "]: " + url
530                          + "Connection has been dropped from the connection allocator.");
531         }
532     }
533
534     /**
535      * Check if a connection is valid after an SQL exception
536      * is thrown. If it is not usable, then the connection is
537      * dropped from the connection allocator and closed. The connection
538      * is then no longer usable.
539      *
540      * @param sqlExcept
541      * The SQL exception that occured.
542      * @return true if the exception does not affect this
543      * connection object. False otherwise - in which case
544      * this connection object is no longer usable.
545      */

546     public synchronized boolean handleException(SQLException sqlExcept) {
547         String JavaDoc sqlState = sqlExcept.getSQLState();
548
549         logDebug("handleException: " + sqlExcept.getMessage());
550         //
551
// TODO
552
// Need to query complete set of fatal exceptions,
553
// or complete set of non-fatal exceptions.
554
// Until then we assume all are fatal.
555
// Note: that code '11111111' is an internal exception
556
// and does not require the connection pool to be
557
// reset. This is a temporary fix. (paul)
558
// Note: There may be a bug in the pool closure logic
559
// if connections in the pool repeatidly throw exceptions
560
// that close the pool while the pool was already in the
561
// process of being closed. (paul)
562
//
563
if (sqlExcept.getErrorCode() != 11111111) {
564             if (!dropConnection) {
565                 logDebug("DBConnection[" + id + "]: " + url
566                              + "\nScheduled to be dropped from connection allocator."
567                              + "\nUnable to handle exception: \""
568                              + sqlExcept.toString() + " \nErrorCode : "
569                              + sqlExcept.getErrorCode() + " \nSQLState : "
570                              + sqlExcept.getSQLState() + "\"\n");
571                 //
572
// We need to drop this connection. N.B. We only
573
// set a flag that we want the connection dropped.
574
// We don't want the connection dropped yet (which
575
// implies closed()) because we may be in the
576
// middle of a transaction which we may want to
577
// rollback.
578
//
579
dropConnection = true;
580             }
581             return false;
582         } else {
583             return true;
584         }
585     }
586
587     /**
588      * Get the generation number specified when the connection was created.
589      *
590      * @return The generation number.
591      */

592     public int getGeneration() {
593         return generation;
594     }
595
596     /**
597      * Close this connection. Use by the connection allocator when this
598      * object is no longer used. Errors are ignored.
599      */

600     public synchronized void close() {
601         if (!closed) {
602             logDebug("close");
603
604             /*
605              * If we are closing the connection, then
606              * the prepared statements should automatically
607              * be closed. Of course, the doc isn't clear.
608              * So we attempt to close the statements.
609              * If any fail, then we ignore the rest.
610              * The reason we do this is that if the original
611              * connection is broken, then the closing of
612              * each statement needs to time out. This
613              * is very time consuming.....
614              */

615             boolean closeStmts = true;
616             //
617
// Close the prepared statements.
618
//
619
/**/
620             Enumeration JavaDoc e = preparedStmtCache.keys();
621
622             while (e.hasMoreElements() && closeStmts) {
623                 String JavaDoc key = (String JavaDoc) e.nextElement();
624
625                 try {
626                     ((PreparedStatement) preparedStmtCache.remove(key)).close();
627                 } catch (SQLException except) {
628                     // Ignore errors, we maybe handling one.
629
closeStmts = false;
630                     logDebug("DBConnection[" + id + "]: " + url
631                                  + "\nUnable to close statements. Continuing....\n");
632                 }
633             }
634             /**/
635             if (closeStmts) {
636                 try {
637                     if (currentStmt != null) {
638                         currentStmt.close();
639                     }
640                 } catch (Exception JavaDoc except) {
641                     // Ignore errors, we maybe handling one.
642
closeStmts = false;
643                 }
644                 currentStmt=null;
645             }
646             try {
647                 if(!connection.isClosed()){
648                     connection.close();
649                 }
650             } catch (Exception JavaDoc except) {// Ignore errors, we maybe handling one.
651
}
652             logDebug("DBConnection[" + id + "]: " + url
653                          + "\nConnection has been closed.\n");
654         }
655         closed = true;
656         connection = null;
657     }
658
659     /**
660      * Autocommit on/off.
661      *
662      * @param on - False to disable auto commit mode. True to enable.
663      * @exception java.sql.SQLException If a database access error occurs.
664      */

665     public void setAutoCommit(boolean on) throws SQLException {
666         validate();
667         if(Common.isChangeAutocommitEnabled(getDatabaseName())){
668             logDebug("set autocommit: " + on);
669             connection.setAutoCommit(on);
670         }else{
671             logDebug("set autocommit is disabled, can't change to value :" + on);
672         }
673     }
674
675     /**
676      * Commit a transaction.
677      *
678      * @exception java.sql.SQLException If a database access error occurs.
679      */

680     public void commit() throws SQLException {
681         validate();
682         logDebug("commit");
683         connection.commit();
684     }
685
686     /**
687      * Rollback a transaction. Should only be used when
688      * <A HREF=#setAutoCommit>auto-commit</A> mode
689      * has been disabled.
690      *
691      * @exception java.sql.SQLException If a database access error occurs.
692      */

693     public void rollback() throws SQLException {
694         validate();
695         logDebug("rollback");
696         connection.rollback();
697     }
698
699     /**
700      * Debug logging.
701      *
702      * @param str
703      * The data to log.
704      */

705     protected void logDebug(String JavaDoc str) {
706         if (logging) {
707             DODS.getLogChannel().write(Logger.DEBUG,
708                                        "\nDBConnection[" + id + "]:" + str + "\n");
709         }
710     }
711
712     /**
713      * Debug logging.
714      *
715      * @param str
716      * The data to log.
717      * @param stmt
718      * The statement to log.
719      */

720     protected void logDebug(String JavaDoc str, Statement stmt) {
721         if (logging) {
722             DODS.getLogChannel().write(Logger.DEBUG,
723                                        "\nDBConnection[" + id + "]:" + str + "\n" + "SQL: "
724                                            + stmt.toString());
725         }
726     }
727
728     /**
729      * Increment the count of the number of requests against
730      * this connection.
731      */

732     public void incrRequestCount() {
733         ((ExtendedConnectionAllocator) connectionAllocator).IncrementRequesteCount();
734     }
735
736     /**
737      * Get the database URL.
738      * @return The database URL.
739      */

740     public String JavaDoc getUrl() {
741         return url;
742     }
743
744     /**
745      * Get the database user name. Normally user for error messages.
746      * @return The database user name.
747      */

748     public String JavaDoc getUser() {
749         return user;
750     }
751
752     /**
753      * Get the underlying <code>Connection</code> object.
754      * Use with extreme caution.
755      * @return the connection object
756      */

757     public Connection getConnection() {
758         return connection;
759     }
760
761     /**
762      * @return true if this connection is marked to be dropped out
763      * of the connection pool and closed.
764      */

765     public boolean isMarkedForDrop() {
766         return dropConnection;
767     }
768
769     /**
770      * @return database name of current connection
771      *
772      */

773     public String JavaDoc getDatabaseName() {
774         return connectionAllocator.getDatabaseName();
775     }
776     /**
777      * @return connectionUsageCounter
778      */

779     public int getConnectionUsageCounter() {
780         return connectionUsageCounter;
781     }
782
783     /**
784      * @param i new value for connectionUsageCounter
785      */

786     public void setConnectionUsageCounter(int i) {
787         connectionUsageCounter = i;
788     }
789     /**
790      * @return dropped
791      */

792     public boolean isDroped() {
793         return dropped;
794     }
795     /**
796      * @return dropped
797      */

798     public boolean isClosed() {
799         return closed;
800     }
801
802     /* (non-Javadoc)
803      * @see com.lutris.appserver.server.sql.ExtendedDBConnection#setConnectionEnterPoolTime(int)
804      */

805     public void setConnectionEnterPoolTime(long i) {
806         connectionEnterPoolTime=i;
807
808     }
809
810     /* (non-Javadoc)
811      * @see com.lutris.appserver.server.sql.ExtendedDBConnection#getConnectionEnterPoolTime()
812      */

813     public long getConnectionEnterPoolTime() {
814         return connectionEnterPoolTime;
815     }
816
817     /**
818      * @return Returns the maxPreparedStmts.
819      */

820     public int getMaxPreparedStmts() {
821         return maxPreparedStmts;
822     }
823     
824     public long curtime=0;
825 }
826
Popular Tags