KickJava   Java API By Example, From Geeks To Geeks.

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


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: SimpleDBConnection.java,v 1.1 2005/05/26 08:08:10 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.1 $
44  */

45 public class SimpleDBConnection 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 SimpleDBConnection(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             // compliance with WEBDOCWF begin
511
// Excelsior's patch start
512
// The synchronized block is used to prevent dead lock that
513
// was found at 7/23/2002 by Excelsior
514
synchronized (connectionAllocator) {
515                 // Excelsior's patch end
516
connectionAllocator.release(this);
517                 allocated = false;
518                 if (dropConnection) {
519                     drop();
520                 }
521             }
522         }
523     }
524
525     /**
526      * Drop this connection from the connection allocator.
527      */

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

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

597     public int getGeneration() {
598         return generation;
599     }
600
601     /**
602      * Close this connection. Use by the connection allocator when this
603      * object is no longer used. Errors are ignored.
604      */

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

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

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

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

698     public void rollback() throws SQLException {
699         validate();
700         logDebug("rollback");
701         connection.rollback();
702     }
703
704     /**
705      * Debug logging.
706      *
707      * @param str
708      * The data to log.
709      */

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

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

737     public void incrRequestCount() {
738         ((ExtendedConnectionAllocator) connectionAllocator).IncrementRequesteCount();
739     }
740
741     /**
742      * Get the database URL.
743      * @return The database URL.
744      */

745     public String JavaDoc getUrl() {
746         return url;
747     }
748
749     /**
750      * Get the database user name. Normally user for error messages.
751      * @return The database user name.
752      */

753     public String JavaDoc getUser() {
754         return user;
755     }
756
757     /**
758      * Get the underlying <code>Connection</code> object.
759      * Use with extreme caution.
760      * @return the connection object
761      */

762     public Connection getConnection() {
763         return connection;
764     }
765
766     /**
767      * @return true if this connection is marked to be dropped out
768      * of the connection pool and closed.
769      */

770     public boolean isMarkedForDrop() {
771         return dropConnection;
772     }
773
774     /**
775      * @return database name of current connection
776      *
777      */

778     public String JavaDoc getDatabaseName() {
779         return connectionAllocator.getDatabaseName();
780     }
781     /**
782      * @return connectionUsageCounter
783      */

784     public int getConnectionUsageCounter() {
785         return connectionUsageCounter;
786     }
787
788     /**
789      * @param i new value for connectionUsageCounter
790      */

791     public void setConnectionUsageCounter(int i) {
792         connectionUsageCounter = i;
793     }
794     /**
795      * @return dropped
796      */

797     public boolean isDroped() {
798         return dropped;
799     }
800     /**
801      * @return dropped
802      */

803     public boolean isClosed() {
804         return closed;
805     }
806
807     /* (non-Javadoc)
808      * @see com.lutris.appserver.server.sql.ExtendedDBConnection#setConnectionEnterPoolTime(int)
809      */

810     public void setConnectionEnterPoolTime(long i) {
811         connectionEnterPoolTime=i;
812
813     }
814
815     /* (non-Javadoc)
816      * @see com.lutris.appserver.server.sql.ExtendedDBConnection#getConnectionEnterPoolTime()
817      */

818     public long getConnectionEnterPoolTime() {
819         return connectionEnterPoolTime;
820     }
821
822     /**
823      * @return Returns the maxPreparedStmts.
824      */

825     public int getMaxPreparedStmts() {
826         return maxPreparedStmts;
827     }
828 }
829
Popular Tags