protected void setQuery(HibernateCursorItemReader<Foo> reader) throws Exception { reader.setQueryString("from Foo"); }
@Override protected void setQuery(HibernateCursorItemReader<Foo> reader) { reader.setQueryString("from Foo where name like :name"); reader.setParameterValues(Collections.singletonMap("name", "bar%")); }
@Test @SuppressWarnings("unchecked") public void testStatefulClose(){ SessionFactory sessionFactory = mock(SessionFactory.class); Session session = mock(Session.class); Query<Foo> scrollableResults = mock(Query.class); HibernateCursorItemReader<Foo> itemReader = new HibernateCursorItemReader<>(); itemReader.setSessionFactory(sessionFactory); itemReader.setQueryString("testQuery"); itemReader.setUseStatelessSession(false); when(sessionFactory.openSession()).thenReturn(session); when(session.createQuery("testQuery")).thenReturn(scrollableResults); when(scrollableResults.setFetchSize(0)).thenReturn(scrollableResults); itemReader.open(new ExecutionContext()); itemReader.close(); }
reader.setQueryString(this.queryString);
@Override protected void pointToEmptyInput(ItemReader<Foo> tested) throws Exception { HibernateCursorItemReader<Foo> reader = (HibernateCursorItemReader<Foo>) tested; reader.close(); reader.setQueryString("from Foo foo where foo.id = -1"); reader.afterPropertiesSet(); reader.open(new ExecutionContext()); }
private void initializeItemReader(HibernateCursorItemReader<?> reader, String hsqlQuery) throws Exception { LocalSessionFactoryBean factoryBean = new LocalSessionFactoryBean(); factoryBean.setDataSource(dataSource); factoryBean.setMappingLocations(new Resource[] { new ClassPathResource( "Foo.hbm.xml", getClass()) }); factoryBean.afterPropertiesSet(); SessionFactory sessionFactory = factoryBean .getObject(); reader.setQueryString(hsqlQuery); reader.setSessionFactory(sessionFactory); reader.afterPropertiesSet(); reader.setSaveState(true); reader.open(new ExecutionContext()); }
@Override protected ItemReader<Foo> getItemReader() throws Exception { SessionFactory sessionFactory = createSessionFactory(); String hsqlQuery = "from Foo"; HibernateCursorItemReader<Foo> reader = new HibernateCursorItemReader<>(); reader.setQueryString(hsqlQuery); reader.setSessionFactory(sessionFactory); reader.setUseStatelessSession(true); reader.setFetchSize(10); reader.afterPropertiesSet(); reader.setSaveState(true); return reader; }
reader.setQueryString(this.queryString);