ReadOnlyModeAwareConnection extends DelegatingConnection { @Override public PreparedStatement prepareStatement(String sql) throws SQLException { PreparedStatement statement = super.prepareStatement(sql); return createProxy(statement, sql); } ReadOnlyModeAwareConnection(Connection connection, ReadOnlyModeStatus status); @Override Statement createStatement(); @Override PreparedStatement prepareStatement(String sql); @Override CallableStatement prepareCall(String sql); @Override Statement createStatement(int resultSetType, int resultSetConcurrency); @Override PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency); @Override CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency); @Override Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability); @Override PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability); @Override CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability); @Override PreparedStatement prepareStatement(String sql, int autoGeneratedKeys); @Override PreparedStatement prepareStatement(String sql, int[] columnIndexes); @Override PreparedStatement prepareStatement(String sql, String[] columnNames);  }
@Test public void testPreparedStatementsAreReadOnlyModeAware() throws SQLException { final ReadOnlyModeAwareConnection cnx = new ReadOnlyModeAwareConnection(mockedConnection, readOnlyModeStatus); final String sql = "select * from whatever"; assertIsReadOnlyModeAware(cnx.prepareStatement(sql)); assertIsReadOnlyModeAware(cnx.prepareStatement(sql, 0)); assertIsReadOnlyModeAware(cnx.prepareStatement(sql, 0, 0)); assertIsReadOnlyModeAware(cnx.prepareStatement(sql, 0, 0, 0)); assertIsReadOnlyModeAware(cnx.prepareStatement(sql, new int[0])); assertIsReadOnlyModeAware(cnx.prepareStatement(sql, new String[0])); }