6 Ocak 2020 Pazartesi

SpringBatch RepositoryItemReader Sınıfı

Giriş
Şu satırı dahil ederiz
import org.springframework.batch.item.data.RepositoryItemReader;
Bu sınıfı RepositoryItemReaderBuilder ile de yaratmak mümkün.

JdbcPagingItemReader sınıfı ile kardeştir. Kendi JpaRepository sınıfımızı kullanarak veritabanını okur. Açıklaması şöyle.
These readers will read a page once , keep it in memory , and process single - single items till chunk size is reached & then commit happens. DB read wouldn't happen till one page is finished. Generally, for optimal performance , chunk size needs to be few times smaller than page size e.g. reader page size - 1000 & chunk size = 100 so 1000 items would be read once and committed in chunks of 100 - 100 items.
setPageSize metodu
Örnek ver

setSort metodu
Örnek
Şöyle yaparız
@Bean(name = "readerNewsReportByRealStatus")
public RepositoryItemReader<NewsReport> readerNewsReportByRealStatus(){
  RepositoryItemReader<NewsReport> reader = new RepositoryItemReader<>();
  reader.setRepository(newsReportRepository);
  reader.setMethodName("findByReal");
  List<Object> queryMethodArguments = new ArrayList<>();
  queryMethodArguments.add("1");
  reader.setArguments(queryMethodArguments);
  Map<String, Sort.Direction> sorts = new LinkedHashMap<>();
  sorts.put("id", Sort.Direction.ASC);
  reader.setSort(sorts);
  return reader;
}



Hiç yorum yok:

Yorum Gönder