com.mchange.v2.c3p0.C3P0ProxyConnection Java Examples

The following examples show how to use com.mchange.v2.c3p0.C3P0ProxyConnection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MysqlConnectionTester.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public int activeCheckConnection(Connection con) {
    try {
        if (this.pingMethod != null) {
            if (con instanceof JdbcConnection) {
                // We've been passed an instance of a MySQL connection -- no need for reflection
                ((JdbcConnection) con).ping();
            } else {
                // Assume the connection is a C3P0 proxy
                C3P0ProxyConnection castCon = (C3P0ProxyConnection) con;
                castCon.rawConnectionOperation(this.pingMethod, C3P0ProxyConnection.RAW_CONNECTION, NO_ARGS_ARRAY);
            }
        } else {
            Statement pingStatement = null;

            try {
                pingStatement = con.createStatement();
                pingStatement.executeQuery("SELECT 1").close();
            } finally {
                if (pingStatement != null) {
                    pingStatement.close();
                }
            }
        }

        return CONNECTION_IS_OKAY;
    } catch (Exception ex) {
        return CONNECTION_IS_INVALID;
    }
}
 
Example #2
Source File: MysqlConnectionTester.java    From r-course with MIT License 5 votes vote down vote up
public int activeCheckConnection(Connection con) {
    try {
        if (this.pingMethod != null) {
            if (con instanceof com.mysql.jdbc.Connection) {
                // We've been passed an instance of a MySQL connection -- no need for reflection
                ((com.mysql.jdbc.Connection) con).ping();
            } else {
                // Assume the connection is a C3P0 proxy
                C3P0ProxyConnection castCon = (C3P0ProxyConnection) con;
                castCon.rawConnectionOperation(this.pingMethod, C3P0ProxyConnection.RAW_CONNECTION, NO_ARGS_ARRAY);
            }
        } else {
            Statement pingStatement = null;

            try {
                pingStatement = con.createStatement();
                pingStatement.executeQuery("SELECT 1").close();
            } finally {
                if (pingStatement != null) {
                    pingStatement.close();
                }
            }
        }

        return CONNECTION_IS_OKAY;
    } catch (Exception ex) {
        return CONNECTION_IS_INVALID;
    }
}
 
Example #3
Source File: MysqlConnectionTester.java    From Komondor with GNU General Public License v3.0 5 votes vote down vote up
public int activeCheckConnection(Connection con) {
    try {
        if (this.pingMethod != null) {
            if (con instanceof com.mysql.jdbc.Connection) {
                // We've been passed an instance of a MySQL connection -- no need for reflection
                ((com.mysql.jdbc.Connection) con).ping();
            } else {
                // Assume the connection is a C3P0 proxy
                C3P0ProxyConnection castCon = (C3P0ProxyConnection) con;
                castCon.rawConnectionOperation(this.pingMethod, C3P0ProxyConnection.RAW_CONNECTION, NO_ARGS_ARRAY);
            }
        } else {
            Statement pingStatement = null;

            try {
                pingStatement = con.createStatement();
                pingStatement.executeQuery("SELECT 1").close();
            } finally {
                if (pingStatement != null) {
                    pingStatement.close();
                }
            }
        }

        return CONNECTION_IS_OKAY;
    } catch (Exception ex) {
        return CONNECTION_IS_INVALID;
    }
}
 
Example #4
Source File: MysqlConnectionTester.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int activeCheckConnection(Connection con) {
    try {
        if (this.pingMethod != null) {
            if (con instanceof JdbcConnection) {
                // We've been passed an instance of a MySQL connection -- no need for reflection
                ((JdbcConnection) con).ping();
            } else {
                // Assume the connection is a C3P0 proxy
                C3P0ProxyConnection castCon = (C3P0ProxyConnection) con;
                castCon.rawConnectionOperation(this.pingMethod, C3P0ProxyConnection.RAW_CONNECTION, NO_ARGS_ARRAY);
            }
        } else {
            Statement pingStatement = null;

            try {
                pingStatement = con.createStatement();
                pingStatement.executeQuery("SELECT 1").close();
            } finally {
                if (pingStatement != null) {
                    pingStatement.close();
                }
            }
        }

        return CONNECTION_IS_OKAY;
    } catch (Exception ex) {
        return CONNECTION_IS_INVALID;
    }
}