ReadOnlyModeAwareDataSource extends DelegatingDataSource implements ReadOnlyModeCapable { @Override public Connection getConnection() throws SQLException { return new ReadOnlyModeAwareConnection(super.getConnection(), () -> readOnly.get()); } ReadOnlyModeAwareDataSource(DataSource targetDataSource); @Override Connection getConnection(); @Override Connection getConnection(String username, String password); @Override void switchReadOnlyMode(boolean enable); @Override int getReadOnlyModePriority();  }
@Test public void testConnectionsAreReadOnlyModeAware() throws SQLException { final ReadOnlyModeAwareDataSource dataSource = new ReadOnlyModeAwareDataSource(mockedDataSource); assertIsReadOnlyModeAware(dataSource.getConnection()); assertIsReadOnlyModeAware(dataSource.getConnection("x", "y")); }