com.mysql.jdbc.ConnectionImpl Java Examples

The following examples show how to use com.mysql.jdbc.ConnectionImpl. 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: BaseTestCase.java    From r-course with MIT License 5 votes vote down vote up
protected void dropSchemaObject(Statement st, String objectType, String objectName) throws SQLException {
    if (st != null) {
        if (!objectType.equalsIgnoreCase("USER") || ((ConnectionImpl) st.getConnection()).versionMeetsMinimum(5, 7, 8)) {
            st.executeUpdate("DROP " + objectType + " IF EXISTS " + objectName);
        } else {
            st.executeUpdate("DROP " + objectType + " " + objectName);
        }
        st.executeUpdate("flush privileges");
    }
}
 
Example #2
Source File: ErrorReportingExceptionInterceptor.java    From r-course with MIT License 5 votes vote down vote up
public SQLException interceptException(SQLException sqlEx, Connection conn) {
    MySQLConnection mysqlConn = (MySQLConnection) conn;

    // don't intercept exceptions during initialization, before the proxy has a chance to setProxy() on the physical connection
    if (ConnectionImpl.class.isAssignableFrom(mysqlConn.getMultiHostSafeProxy().getClass())) {
        return null;
    }

    FabricMySQLConnectionProxy fabricProxy = (FabricMySQLConnectionProxy) mysqlConn.getMultiHostSafeProxy();
    try {
        return fabricProxy.interceptException(sqlEx, conn, this.fabricHaGroup, this.hostname, this.port);
    } catch (FabricCommunicationException ex) {
        return SQLError.createSQLException("Failed to report error to Fabric.", SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE, ex, null);
    }
}
 
Example #3
Source File: BaseTestCase.java    From Komondor with GNU General Public License v3.0 5 votes vote down vote up
protected void dropSchemaObject(Statement st, String objectType, String objectName) throws SQLException {
    if (st != null) {
        if (!objectType.equalsIgnoreCase("USER") || ((ConnectionImpl) st.getConnection()).versionMeetsMinimum(5, 7, 8)) {
            st.executeUpdate("DROP " + objectType + " IF EXISTS " + objectName);
        } else {
            st.executeUpdate("DROP " + objectType + " " + objectName);
        }
        st.executeUpdate("flush privileges");
    }
}
 
Example #4
Source File: ErrorReportingExceptionInterceptor.java    From Komondor with GNU General Public License v3.0 5 votes vote down vote up
public SQLException interceptException(SQLException sqlEx, Connection conn) {
    MySQLConnection mysqlConn = (MySQLConnection) conn;

    // don't intercept exceptions during initialization, before the proxy has a chance to setProxy() on the physical connection
    if (ConnectionImpl.class.isAssignableFrom(mysqlConn.getMultiHostSafeProxy().getClass())) {
        return null;
    }

    FabricMySQLConnectionProxy fabricProxy = (FabricMySQLConnectionProxy) mysqlConn.getMultiHostSafeProxy();
    try {
        return fabricProxy.interceptException(sqlEx, conn, this.fabricHaGroup, this.hostname, this.port);
    } catch (FabricCommunicationException ex) {
        return SQLError.createSQLException("Failed to report error to Fabric.", SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE, ex, null);
    }
}
 
Example #5
Source File: MysqlUtils.java    From clearpool with GNU General Public License v3.0 5 votes vote down vote up
public static XAConnection mysqlXAConnection(Connection con) throws SQLException {
  ConnectionImpl mysqlConn = (ConnectionImpl) con;
  if (mysqlConn.getPinGlobalTxToPhysicalConnection()) {
    if (!Util.isJdbc4()) {
      return new SuspendableXAConnection(mysqlConn);
    }
    return new JDBC4SuspendableXAConnection(mysqlConn);
  }
  return new MysqlXAConnection(mysqlConn, false);
}
 
Example #6
Source File: RetrievalPerfTest.java    From r-course with MIT License 4 votes vote down vote up
/**
 * Tests retrieval from the query cache
 * 
 * @throws Exception
 *             if an error occurs
 */
public void testRetrievalCached() throws Exception {
    if (!((ConnectionImpl) this.conn).isQueryCacheEnabled()) {
        return;
    }
    this.stmt.executeUpdate("SET QUERY_CACHE_TYPE = DEMAND");

    double fullBegin = System.currentTimeMillis();
    double averageQueryTimeMs = 0;
    double averageTraversalTimeMs = 0;

    for (int i = 0; i < NUM_TESTS; i++) {
        long queryBegin = System.currentTimeMillis();
        this.rs = this.stmt.executeQuery("SELECT SQL_CACHE * FROM retrievalPerfTestHeap");

        long queryEnd = System.currentTimeMillis();
        averageQueryTimeMs += ((double) (queryEnd - queryBegin) / NUM_TESTS);

        long traverseBegin = System.currentTimeMillis();

        while (this.rs.next()) {
            this.rs.getInt(1);
            this.rs.getString(2);
        }

        long traverseEnd = System.currentTimeMillis();
        averageTraversalTimeMs += ((double) (traverseEnd - traverseBegin) / NUM_TESTS);
    }

    double fullEnd = System.currentTimeMillis();
    double fullTime = (fullEnd - fullBegin) / 1000;
    double queriesPerSec = NUM_TESTS / fullTime;
    double rowsPerSec = (NUM_ROWS * NUM_TESTS) / fullTime;
    System.out.println("\nQuery Cache From Heap Retrieval\n");
    System.out.println("Full test took: " + fullTime + " seconds.");
    System.out.println("Queries/second: " + queriesPerSec);
    System.out.println("Rows/second: " + rowsPerSec);
    System.out.println("Avg. Query Exec Time: " + averageQueryTimeMs + " ms");
    System.out.println("Avg. Traversal Time: " + averageTraversalTimeMs + " ms");

    // We're doing something wrong if we can't beat 45 seconds :(
    assertTrue(fullTime < 45);
}
 
Example #7
Source File: RetrievalPerfTest.java    From Komondor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Tests retrieval from the query cache
 * 
 * @throws Exception
 *             if an error occurs
 */
public void testRetrievalCached() throws Exception {
    if (!((ConnectionImpl) this.conn).isQueryCacheEnabled()) {
        return;
    }
    this.stmt.executeUpdate("SET QUERY_CACHE_TYPE = DEMAND");

    double fullBegin = System.currentTimeMillis();
    double averageQueryTimeMs = 0;
    double averageTraversalTimeMs = 0;

    for (int i = 0; i < NUM_TESTS; i++) {
        long queryBegin = System.currentTimeMillis();
        this.rs = this.stmt.executeQuery("SELECT SQL_CACHE * FROM retrievalPerfTestHeap");

        long queryEnd = System.currentTimeMillis();
        averageQueryTimeMs += ((double) (queryEnd - queryBegin) / NUM_TESTS);

        long traverseBegin = System.currentTimeMillis();

        while (this.rs.next()) {
            this.rs.getInt(1);
            this.rs.getString(2);
        }

        long traverseEnd = System.currentTimeMillis();
        averageTraversalTimeMs += ((double) (traverseEnd - traverseBegin) / NUM_TESTS);
    }

    double fullEnd = System.currentTimeMillis();
    double fullTime = (fullEnd - fullBegin) / 1000;
    double queriesPerSec = NUM_TESTS / fullTime;
    double rowsPerSec = (NUM_ROWS * NUM_TESTS) / fullTime;
    System.out.println("\nQuery Cache From Heap Retrieval\n");
    System.out.println("Full test took: " + fullTime + " seconds.");
    System.out.println("Queries/second: " + queriesPerSec);
    System.out.println("Rows/second: " + rowsPerSec);
    System.out.println("Avg. Query Exec Time: " + averageQueryTimeMs + " ms");
    System.out.println("Avg. Traversal Time: " + averageTraversalTimeMs + " ms");

    // We're doing something wrong if we can't beat 45 seconds :(
    assertTrue(fullTime < 45);
}