KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mchange > v2 > c3p0 > AbstractConnectionTester


1 /*
2  * Distributed as part of c3p0 v.0.9.1
3  *
4  * Copyright (C) 2005 Machinery For Change, Inc.
5  *
6  * Author: Steve Waldman <swaldman@mchange.com>
7  *
8  * This library is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License version 2.1, as
10  * published by the Free Software Foundation.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this software; see the file LICENSE. If not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */

22
23
24 package com.mchange.v2.c3p0;
25
26 import java.sql.Connection JavaDoc;
27
28 /**
29  * <p>Having expanded the once-simple ConnectionTester interface to support both
30  * user-specified queries and return of root cause Exceptions (via an out-param),
31  * this interface has grown unnecessarily complex.</p>
32  *
33  * <p>If you wish to implement a custom Connection tester, here is the simple
34  * way to do it</p>
35  *
36  * <ol>
37  * <li>Extend {@link com.mchange.v2.c3p0.AbstractConnectionTester}</li>
38  * <li>Override only the two abstract methods</li>
39  * <ul>
40  * <li><tt>public int activeCheckConnection(Connection c, String preferredTestQuery, Throwable[] rootCauseOutParamHolder)</tt></li>
41  * <li><tt>public int statusOnException(Connection c, Throwable t, String preferredTestQuery, Throwable[] rootCauseOutParamHolder)</tt></li>
42  * </ul>
43  * <li>Take care to ensure that your methods are defined to allow <tt>preferredTestQuery</tt> and
44  * <tt>rootCauseOutParamHolder</tt> to be <tt>null</tt>.</li>
45  * </ol>
46  *
47  * <p>Parameter <tt>rootCauseOutParamHolder</tt> is an optional parameter, which if supplied, will be a Throwable array whose size
48  * it at least one. If a Connection test fails because of some Exception, the Connection tester may set this Exception as the
49  * zero-th element of the array to provide information about why and how the test failed.</p>
50  */

51 public abstract class AbstractConnectionTester implements UnifiedConnectionTester
52 {
53     /**
54      * Override, but remember that <tt>preferredTestQuery</tt> and <tt>rootCauseOutParamHolder</tt>
55      * can be null.
56      */

57     public abstract int activeCheckConnection(Connection JavaDoc c, String JavaDoc preferredTestQuery, Throwable JavaDoc[] rootCauseOutParamHolder);
58
59     /**
60      * Override, but remember that <tt>preferredTestQuery</tt> and <tt>rootCauseOutParamHolder</tt>
61      * can be null.
62      */

63     public abstract int statusOnException(Connection JavaDoc c, Throwable JavaDoc t, String JavaDoc preferredTestQuery, Throwable JavaDoc[] rootCauseOutParamHolder);
64
65     //usually just leave the rest of these as-is
66
public int activeCheckConnection(Connection JavaDoc c)
67     { return activeCheckConnection( c, null, null); }
68
69     public int activeCheckConnection(Connection JavaDoc c, Throwable JavaDoc[] rootCauseOutParamHolder)
70     { return activeCheckConnection( c, null, rootCauseOutParamHolder); }
71
72     public int activeCheckConnection(Connection JavaDoc c, String JavaDoc preferredTestQuery)
73     { return activeCheckConnection( c, preferredTestQuery, null); }
74
75     public int statusOnException(Connection JavaDoc c, Throwable JavaDoc t)
76     { return statusOnException( c, t, null, null); }
77
78     public int statusOnException(Connection JavaDoc c, Throwable JavaDoc t, Throwable JavaDoc[] rootCauseOutParamHolder)
79     { return statusOnException( c, t, null, rootCauseOutParamHolder); }
80
81     public int statusOnException(Connection JavaDoc c, Throwable JavaDoc t, String JavaDoc preferredTestQuery)
82     { return statusOnException( c, t, preferredTestQuery, null); }
83 }
84
Popular Tags