@Override protected void jumpToItem(int itemLastIndex) throws Exception { synchronized (lock) { page = (itemLastIndex - 1) / pageSize; current = (itemLastIndex - 1) % pageSize; results = doPageRead(); page++; } }
/** * {@link Map} of property names/{@link org.springframework.data.domain.Sort.Direction} values to * sort the input by. * * @param sorts map of properties and direction to sort each. */ public void setSort(Map<String, Sort.Direction> sorts) { this.sort = convertToSort(sorts); }
/** * Provides ordering of the results so that order is maintained between paged queries * * @param sorts the fields to sort by and the directions */ public void setSort(Map<String, Sort.Direction> sorts) { this.sort = convertToSort(sorts); }
private Neo4jItemReader<String> buildSessionBasedReader() throws Exception { Neo4jItemReader<String> reader = new Neo4jItemReader<>(); reader.setSessionFactory(this.sessionFactory); reader.setTargetType(String.class); reader.setStartStatement("n=node(*)"); reader.setReturnStatement("*"); reader.setOrderByStatement("n.age"); reader.setPageSize(50); reader.afterPropertiesSet(); return reader; }
/** * Validates and builds a {@link MongoItemWriter}. * * @return a {@link MongoItemWriter} */ public MongoItemWriter<T> build() { Assert.notNull(this.template, "template is required."); MongoItemWriter<T> writer = new MongoItemWriter<>(); writer.setTemplate(this.template); writer.setDelete(this.delete); writer.setCollection(this.collection); return writer; }
/** * Validates and builds a {@link GemfireItemWriter}. * * @return a {@link GemfireItemWriter} */ public GemfireItemWriter<K, V> build() { Assert.notNull(this.template, "template is required."); Assert.notNull(this.itemKeyMapper, "itemKeyMapper is required."); GemfireItemWriter<K, V> writer = new GemfireItemWriter<>(); writer.setTemplate(this.template); writer.setItemKeyMapper(this.itemKeyMapper); writer.setDelete(this.delete); return writer; } }
/** * Validates and builds a {@link org.springframework.batch.item.data.Neo4jItemWriter}. * * @return a {@link Neo4jItemWriter} */ public Neo4jItemWriter<T> build() { Assert.notNull(sessionFactory, "sessionFactory is required."); Neo4jItemWriter<T> writer = new Neo4jItemWriter<>(); writer.setDelete(this.delete); writer.setSessionFactory(this.sessionFactory); return writer; } }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); writer = new MongoItemWriter<>(); writer.setTemplate(template); writer.afterPropertiesSet(); }
/** * If a transaction is active, buffer items to be written just before commit. * Otherwise write items using the provided template. * * @see org.springframework.batch.item.ItemWriter#write(List) */ @Override public void write(List<? extends T> items) throws Exception { if(!transactionActive()) { doWrite(items); return; } List<T> bufferedItems = getCurrentBuffer(); bufferedItems.addAll(items); }
/** * Write all items to the data store. * * @see org.springframework.batch.item.ItemWriter#write(java.util.List) */ @Override public void write(List<? extends T> items) throws Exception { if(!CollectionUtils.isEmpty(items)) { doWrite(items); } }
@Override protected void jumpToItem(int itemLastIndex) throws Exception { synchronized (lock) { page = itemLastIndex / pageSize; int current = itemLastIndex % pageSize; Iterator<T> initialPage = doPageRead(); for(; current >= 0; current--) { initialPage.next(); } } } }
/** * Write all items to the data store via a Spring Data repository. * * @see org.springframework.batch.item.ItemWriter#write(java.util.List) */ @Override public void write(List<? extends T> items) throws Exception { if(!CollectionUtils.isEmpty(items)) { doWrite(items); } }
public MongoItemReader() { super(); setName(ClassUtils.getShortName(MongoItemReader.class)); }
public RepositoryItemReader() { setName(ClassUtils.getShortName(RepositoryItemReader.class)); }
@Override public void beforeCommit(boolean readOnly) { List<T> items = (List<T>) TransactionSynchronizationManager.getResource(bufferKey); if(!CollectionUtils.isEmpty(items)) { if(!readOnly) { doWrite(items); } } }
@Test public void testWriteNoTransactionNoItems() throws Exception { writer.write(null); verifyZeroInteractions(template); }
@Test public void testAfterPropertiesSet() throws Exception { writer = new MongoItemWriter<>(); try { writer.afterPropertiesSet(); fail("Expected exception was not thrown"); } catch (IllegalStateException ignore) { } writer.setTemplate(template); writer.afterPropertiesSet(); }