@Test public void testConfigurationNoSaveState() throws Exception { Map<String, Object> parameters = new HashMap<>(); parameters.put("value", 2); HibernateCursorItemReader<Foo> reader = new HibernateCursorItemReaderBuilder<Foo>() .name("fooReader") .sessionFactory(this.sessionFactory) .queryString("from Foo foo where foo.id > :value") .parameterValues(parameters) .saveState(false) .build(); reader.afterPropertiesSet(); ExecutionContext executionContext = new ExecutionContext(); reader.open(executionContext); int i = 0; while(reader.read() != null) { i++; } reader.update(executionContext); reader.close(); assertEquals(3, i); assertEquals(0, executionContext.size()); }
@Test public void testConfigurationNativeQuery() throws Exception { HibernateCursorItemReader<Foo> reader = new HibernateCursorItemReaderBuilder<Foo>() .name("fooReader") .sessionFactory(this.sessionFactory) .nativeQuery("select * from T_FOOS") .entityClass(Foo.class) .build(); reader.afterPropertiesSet(); ExecutionContext executionContext = new ExecutionContext(); reader.open(executionContext); int i = 0; while(reader.read() != null) { i++; } reader.update(executionContext); reader.close(); assertEquals(5, i); }
@Test public void testConfigurationQueryProvider() throws Exception { HibernateNativeQueryProvider<Foo> provider = new HibernateNativeQueryProvider<>(); provider.setEntityClass(Foo.class); provider.setSqlQuery("select * from T_FOOS"); provider.afterPropertiesSet(); HibernateCursorItemReader<Foo> reader = new HibernateCursorItemReaderBuilder<Foo>() .name("fooReader") .sessionFactory(this.sessionFactory) .queryProvider(provider) .build(); reader.afterPropertiesSet(); ExecutionContext executionContext = new ExecutionContext(); reader.open(executionContext); int i = 0; while(reader.read() != null) { i++; } reader.update(executionContext); reader.close(); assertEquals(5, i); }
@Test public void testConfiguration() throws Exception { HibernateCursorItemReader<Foo> reader = new HibernateCursorItemReaderBuilder<Foo>() .name("fooReader") .sessionFactory(this.sessionFactory) .fetchSize(2) .currentItemCount(2) .maxItemCount(4) .queryName("allFoos") .useStatelessSession(true) .build(); reader.afterPropertiesSet(); ExecutionContext executionContext = new ExecutionContext(); reader.open(executionContext); Foo item1 = reader.read(); Foo item2 = reader.read(); assertNull(reader.read()); reader.update(executionContext); reader.close(); assertEquals(3, item1.getId()); assertEquals("bar3", item1.getName()); assertEquals(3, item1.getValue()); assertEquals(4, item2.getId()); assertEquals("bar4", item2.getName()); assertEquals(4, item2.getValue()); assertEquals(2, executionContext.size()); }