@Test public void testUsesCurrentTransaction() throws Exception { DataSource ds = mock(DataSource.class); Connection con = mock(Connection.class); when(con.getAutoCommit()).thenReturn(false); PreparedStatement ps = mock(PreparedStatement.class); when(con.prepareStatement("select foo from bar", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT)).thenReturn(ps); when(ds.getConnection()).thenReturn(con); when(ds.getConnection()).thenReturn(con); con.commit(); PlatformTransactionManager tm = new DataSourceTransactionManager(ds); TransactionTemplate tt = new TransactionTemplate(tm); final JdbcCursorItemReader<String> reader = new JdbcCursorItemReader<>(); reader.setDataSource(new ExtendedConnectionDataSourceProxy(ds)); reader.setUseSharedExtendedConnection(true); reader.setSql("select foo from bar"); final ExecutionContext ec = new ExecutionContext(); tt.execute( new TransactionCallback<Void>() { @Override public Void doInTransaction(TransactionStatus status) { reader.open(ec); reader.close(); return null; } }); }
reader.setMaxRows(this.maxRows); reader.setQueryTimeout(this.queryTimeout); reader.setUseSharedExtendedConnection(this.useSharedExtendedConnection); reader.setVerifyCursorPosition(this.verifyCursorPosition);
reader.setMaxRows(this.maxRows); reader.setQueryTimeout(this.queryTimeout); reader.setUseSharedExtendedConnection(this.useSharedExtendedConnection); reader.setVerifyCursorPosition(this.verifyCursorPosition);