Search in sources :

Example 1 with UpdatableResultSet

use of com.mysql.cj.jdbc.result.UpdatableResultSet in project JavaSegundasQuintas by ecteruel.

the class ResultSetRegressionTest method testBug70704.

/**
 * Tests fix for Bug#70704 - Deadlock using UpdatableResultSet.
 *
 * Doesn't actually test the buggy behavior since it is not verifiable since the fix for Bug#59462 (revision 385a151). However, the patch for this fix is
 * needed because the synchronization in UpdatableResultSet was dated.
 * This test makes sure there is no regression.
 *
 * WARNING! If this test fails there is no guarantee that the JVM will remain stable and won't affect any other tests. It is imperative that this test
 * passes to ensure other tests results.
 *
 * @throws Exception
 */
@Test
public void testBug70704() throws Exception {
    for (int i = 0; i < 100; i++) {
        final Statement testStmt = this.conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
        final ResultSet testRs = testStmt.executeQuery("SELECT 1");
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        executorService.submit(new Callable<Void>() {

            public Void call() throws Exception {
                testStmt.close();
                return null;
            }
        });
        executorService.submit(new Callable<Void>() {

            public Void call() throws Exception {
                testRs.close();
                return null;
            }
        });
        executorService.shutdown();
        if (!executorService.awaitTermination(2, TimeUnit.SECONDS)) {
            ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
            long[] threadIds = threadMXBean.findMonitorDeadlockedThreads();
            if (threadIds != null) {
                System.err.println("Deadlock detected!");
                ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadIds, Integer.MAX_VALUE);
                for (ThreadInfo ti : threadInfos) {
                    System.err.println();
                    System.err.println(ti);
                    System.err.println("Stack trace:");
                    for (StackTraceElement ste : ti.getStackTrace()) {
                        System.err.println("   " + ste);
                    }
                }
                fail("Unexpected deadlock detected. Consult system output for more details. WARNING: this failure may lead to JVM instability.");
            }
        }
    }
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) ThreadInfo(java.lang.management.ThreadInfo) PreparedStatement(java.sql.PreparedStatement) CallableStatement(java.sql.CallableStatement) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) UpdatableResultSet(com.mysql.cj.jdbc.result.UpdatableResultSet) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) CJCommunicationsException(com.mysql.cj.exceptions.CJCommunicationsException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SQLException(java.sql.SQLException) SQLDataException(java.sql.SQLDataException) CommunicationsException(com.mysql.cj.jdbc.exceptions.CommunicationsException) Test(org.junit.jupiter.api.Test)

Example 2 with UpdatableResultSet

use of com.mysql.cj.jdbc.result.UpdatableResultSet in project ABC by RuiPinto96274.

the class ConnectionImpl method initializeResultsMetadataFromCache.

@Override
public void initializeResultsMetadataFromCache(String sql, CachedResultSetMetaData cachedMetaData, ResultSetInternalMethods resultSet) throws SQLException {
    if (cachedMetaData == null) {
        // read from results
        cachedMetaData = new CachedResultSetMetaDataImpl();
        // assume that users will use named-based lookups
        resultSet.getColumnDefinition().buildIndexMapping();
        resultSet.initializeWithMetadata();
        if (resultSet instanceof UpdatableResultSet) {
            ((UpdatableResultSet) resultSet).checkUpdatability();
        }
        resultSet.populateCachedMetaData(cachedMetaData);
        this.resultSetMetadataCache.put(sql, cachedMetaData);
    } else {
        resultSet.getColumnDefinition().initializeFrom(cachedMetaData);
        resultSet.initializeWithMetadata();
        if (resultSet instanceof UpdatableResultSet) {
            ((UpdatableResultSet) resultSet).checkUpdatability();
        }
    }
}
Also used : UpdatableResultSet(com.mysql.cj.jdbc.result.UpdatableResultSet) CachedResultSetMetaDataImpl(com.mysql.cj.jdbc.result.CachedResultSetMetaDataImpl)

Example 3 with UpdatableResultSet

use of com.mysql.cj.jdbc.result.UpdatableResultSet in project JavaSegundasQuintas by ecteruel.

the class ConnectionImpl method initializeResultsMetadataFromCache.

@Override
public void initializeResultsMetadataFromCache(String sql, CachedResultSetMetaData cachedMetaData, ResultSetInternalMethods resultSet) throws SQLException {
    if (cachedMetaData == null) {
        // read from results
        cachedMetaData = new CachedResultSetMetaDataImpl();
        // assume that users will use named-based lookups
        resultSet.getColumnDefinition().buildIndexMapping();
        resultSet.initializeWithMetadata();
        if (resultSet instanceof UpdatableResultSet) {
            ((UpdatableResultSet) resultSet).checkUpdatability();
        }
        resultSet.populateCachedMetaData(cachedMetaData);
        this.resultSetMetadataCache.put(sql, cachedMetaData);
    } else {
        resultSet.getColumnDefinition().initializeFrom(cachedMetaData);
        resultSet.initializeWithMetadata();
        if (resultSet instanceof UpdatableResultSet) {
            ((UpdatableResultSet) resultSet).checkUpdatability();
        }
    }
}
Also used : UpdatableResultSet(com.mysql.cj.jdbc.result.UpdatableResultSet) CachedResultSetMetaDataImpl(com.mysql.cj.jdbc.result.CachedResultSetMetaDataImpl)

Example 4 with UpdatableResultSet

use of com.mysql.cj.jdbc.result.UpdatableResultSet in project aws-mysql-jdbc by awslabs.

the class ConnectionImpl method initializeResultsMetadataFromCache.

@Override
public void initializeResultsMetadataFromCache(String sql, CachedResultSetMetaData cachedMetaData, ResultSetInternalMethods resultSet) throws SQLException {
    if (cachedMetaData == null) {
        // read from results
        cachedMetaData = new CachedResultSetMetaDataImpl();
        // assume that users will use named-based lookups
        resultSet.getColumnDefinition().buildIndexMapping();
        resultSet.initializeWithMetadata();
        if (resultSet instanceof UpdatableResultSet) {
            ((UpdatableResultSet) resultSet).checkUpdatability();
        }
        resultSet.populateCachedMetaData(cachedMetaData);
        this.resultSetMetadataCache.put(sql, cachedMetaData);
    } else {
        resultSet.getColumnDefinition().initializeFrom(cachedMetaData);
        resultSet.initializeWithMetadata();
        if (resultSet instanceof UpdatableResultSet) {
            ((UpdatableResultSet) resultSet).checkUpdatability();
        }
    }
}
Also used : UpdatableResultSet(com.mysql.cj.jdbc.result.UpdatableResultSet) CachedResultSetMetaDataImpl(com.mysql.cj.jdbc.result.CachedResultSetMetaDataImpl)

Example 5 with UpdatableResultSet

use of com.mysql.cj.jdbc.result.UpdatableResultSet in project aws-mysql-jdbc by awslabs.

the class ResultSetRegressionTest method testBug70704.

/**
 * Tests fix for Bug#70704 - Deadlock using UpdatableResultSet.
 *
 * Doesn't actually test the buggy behavior since it is not verifiable since the fix for Bug#59462 (revision 385a151). However, the patch for this fix is
 * needed because the synchronization in UpdatableResultSet was dated.
 * This test makes sure there is no regression.
 *
 * WARNING! If this test fails there is no guarantee that the JVM will remain stable and won't affect any other tests. It is imperative that this test
 * passes to ensure other tests results.
 *
 * @throws Exception
 */
@Test
public void testBug70704() throws Exception {
    for (int i = 0; i < 100; i++) {
        final Statement testStmt = this.conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
        final ResultSet testRs = testStmt.executeQuery("SELECT 1");
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        executorService.submit(new Callable<Void>() {

            public Void call() throws Exception {
                testStmt.close();
                return null;
            }
        });
        executorService.submit(new Callable<Void>() {

            public Void call() throws Exception {
                testRs.close();
                return null;
            }
        });
        executorService.shutdown();
        if (!executorService.awaitTermination(2, TimeUnit.SECONDS)) {
            ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
            long[] threadIds = threadMXBean.findMonitorDeadlockedThreads();
            if (threadIds != null) {
                System.err.println("Deadlock detected!");
                ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadIds, Integer.MAX_VALUE);
                for (ThreadInfo ti : threadInfos) {
                    System.err.println();
                    System.err.println(ti);
                    System.err.println("Stack trace:");
                    for (StackTraceElement ste : ti.getStackTrace()) {
                        System.err.println("   " + ste);
                    }
                }
                fail("Unexpected deadlock detected. Consult system output for more details. WARNING: this failure may lead to JVM instability.");
            }
        }
    }
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) ThreadInfo(java.lang.management.ThreadInfo) PreparedStatement(java.sql.PreparedStatement) CallableStatement(java.sql.CallableStatement) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) UpdatableResultSet(com.mysql.cj.jdbc.result.UpdatableResultSet) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) CJCommunicationsException(com.mysql.cj.exceptions.CJCommunicationsException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SQLException(java.sql.SQLException) SQLDataException(java.sql.SQLDataException) CommunicationsException(com.mysql.cj.jdbc.exceptions.CommunicationsException) Test(org.junit.jupiter.api.Test)

Aggregations

UpdatableResultSet (com.mysql.cj.jdbc.result.UpdatableResultSet)6 CJCommunicationsException (com.mysql.cj.exceptions.CJCommunicationsException)3 ServerPreparedStatement (com.mysql.cj.jdbc.ServerPreparedStatement)3 CommunicationsException (com.mysql.cj.jdbc.exceptions.CommunicationsException)3 CachedResultSetMetaDataImpl (com.mysql.cj.jdbc.result.CachedResultSetMetaDataImpl)3 ThreadInfo (java.lang.management.ThreadInfo)3 ThreadMXBean (java.lang.management.ThreadMXBean)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 CallableStatement (java.sql.CallableStatement)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SQLDataException (java.sql.SQLDataException)3 SQLException (java.sql.SQLException)3 Statement (java.sql.Statement)3 ExecutorService (java.util.concurrent.ExecutorService)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 Test (org.junit.jupiter.api.Test)3