@Override protected void pointToEmptyInput(ItemReader<Foo> tested) throws Exception { JpaPagingItemReader<Foo> reader = (JpaPagingItemReader<Foo>) tested; reader.close(); reader.setQueryString("select f from Foo f where f.id = -1"); reader.afterPropertiesSet(); reader.open(new ExecutionContext()); }
@Override protected AbstractPagingItemReader<Foo> getItemReader() throws Exception { String jpqlQuery = "select f from Foo f where f.value >= :limit"; JpaPagingItemReader<Foo> reader = new JpaPagingItemReader<>(); reader.setQueryString(jpqlQuery); reader.setParameterValues(Collections.<String, Object>singletonMap("limit", 2)); reader.setEntityManagerFactory(entityManagerFactory); reader.setPageSize(3); reader.afterPropertiesSet(); reader.setSaveState(true); return reader; }
@Override protected ItemReader<Foo> getItemReader() throws Exception { String jpqlQuery = "select f from Foo f"; JpaPagingItemReader<Foo> reader = new JpaPagingItemReader<>(); reader.setQueryString(jpqlQuery); reader.setEntityManagerFactory(entityManagerFactory); reader.setPageSize(3); reader.afterPropertiesSet(); reader.setSaveState(true); return reader; }
private JpaPagingItemReader<Foo> getItemReader() throws Exception { String jpqlQuery = "select f from Foo f"; JpaPagingItemReader<Foo> reader = new JpaPagingItemReader<>(); reader.setQueryString(jpqlQuery); reader.setEntityManagerFactory(entityManagerFactory); reader.setPageSize(PAGE_SIZE); reader.afterPropertiesSet(); reader.setSaveState(false); reader.open(new ExecutionContext()); return reader; }
private JpaPagingItemReader<Foo> getItemReader() throws Exception { String jpqlQuery = "select f from Foo f"; JpaPagingItemReader<Foo> reader = new JpaPagingItemReader<>(); reader.setQueryString(jpqlQuery); reader.setEntityManagerFactory(entityManagerFactory); reader.setPageSize(3); reader.afterPropertiesSet(); reader.setSaveState(false); reader.open(new ExecutionContext()); return reader; }
@Override protected AbstractPagingItemReader<Foo> getItemReader() throws Exception { String sqlQuery = "select * from T_FOOS where value >= :limit"; JpaPagingItemReader<Foo> reader = new JpaPagingItemReader<>(); //creating a native query provider as it would be created in configuration JpaNativeQueryProvider<Foo> queryProvider= new JpaNativeQueryProvider<>(); queryProvider.setSqlQuery(sqlQuery); queryProvider.setEntityClass(Foo.class); queryProvider.afterPropertiesSet(); reader.setParameterValues(Collections.<String, Object>singletonMap("limit", 2)); reader.setEntityManagerFactory(entityManagerFactory); reader.setPageSize(3); reader.setQueryProvider(queryProvider); reader.afterPropertiesSet(); reader.setSaveState(true); return reader; } }
@Override protected ItemReader<Foo> createItemReader() throws Exception { LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean(); factoryBean.setDataSource(dataSource); factoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); factoryBean.setPersistenceUnitName("bar"); factoryBean.afterPropertiesSet(); EntityManagerFactory entityManagerFactory = factoryBean.getObject(); String jpqlQuery = "select f from Foo f where name like :name"; JpaPagingItemReader<Foo> inputSource = new JpaPagingItemReader<>(); inputSource.setQueryString(jpqlQuery); inputSource.setParameterValues(Collections.singletonMap("name", "bar%")); inputSource.setEntityManagerFactory(entityManagerFactory); inputSource.setPageSize(3); inputSource.afterPropertiesSet(); inputSource.setSaveState(true); return inputSource; }
@Test public void testConfigurationNoSaveState() throws Exception { Map<String, Object> parameters = new HashMap<>(); parameters.put("value", 2); JpaPagingItemReader<Foo> reader = new JpaPagingItemReaderBuilder<Foo>() .name("fooReader") .entityManagerFactory(this.entityManagerFactory) .queryString("select f from Foo f where f.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 testConfigurationQueryProvider() throws Exception { JpaNativeQueryProvider<Foo> provider = new JpaNativeQueryProvider<>(); provider.setEntityClass(Foo.class); provider.setSqlQuery("select * from T_FOOS"); provider.afterPropertiesSet(); JpaPagingItemReader<Foo> reader = new JpaPagingItemReaderBuilder<Foo>() .name("fooReader") .entityManagerFactory(this.entityManagerFactory) .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 { JpaPagingItemReader<Foo> reader = new JpaPagingItemReaderBuilder<Foo>() .name("fooReader") .entityManagerFactory(this.entityManagerFactory) .currentItemCount(2) .maxItemCount(4) .pageSize(5) .transacted(false) .queryString("select f from Foo f ") .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()); assertEquals(5, ReflectionTestUtils.getField(reader, "pageSize")); assertFalse((Boolean) ReflectionTestUtils.getField(reader, "transacted")); }
@Override public void afterPropertiesSet() throws Exception { String query = "select i from InteractionImpl i join i.annotations as annot " + "where annot.cvTopic.shortLabel = 'curated-complex' " + "order by i.ac"; setQueryString(query); super.afterPropertiesSet(); } }
@Override public void afterPropertiesSet() throws Exception { String query = "select i from InteractorImpl i where i.objClass <> 'uk.ac.ebi.intact.model.InteractionImpl'"; if (isInteracting()) { query = query + " and size(i.activeInstances) > 0 order by i.ac"; } else { query += " order by i.ac"; } setQueryString(query); super.afterPropertiesSet(); }
@Override public void afterPropertiesSet() throws Exception { String query = "select i from InteractionImpl i " + "where i.ac not in " + "(select distinct i2.ac from InteractionImpl i2 join i2.annotations as a1 " + "where a1.cvTopic.shortLabel = 'curated-complex')"; if (isExcludeNegative()) { query = query + " and i.ac not in " + "(select distinct i3.ac from InteractionImpl i3 join i3.annotations as annot where annot.cvTopic.shortLabel = 'negative') " + "order by i.ac"; } else { query += " order by i.ac"; } setQueryString(query); super.afterPropertiesSet(); }
@Override public void afterPropertiesSet() throws Exception { String query = "select p from Publication p "; if (isExcludeIntactPaper()) { query = query + "where p.shortLabel <> '14681455' "; } if(isOrderedByCreated()){ query += " order by p.created, p.ac"; } else { query += " order by p.ac"; } setQueryString(query); super.afterPropertiesSet(); }
@Override public void afterPropertiesSet() throws Exception { String query = "select e from Experiment e "; if (isExcludeInferredByCurators()) { query = query + " where e.cvInteraction.shortLabel <> 'inferred by curator' " + "order by e.ac"; } else if (isOnlyInferredByCurators()) { query = query + " where e.cvInteraction.shortLabel = 'inferred by curator' " + "order by e.ac"; } else { query += " order by e.ac"; } setQueryString(query); super.afterPropertiesSet(); }