use of org.springframework.batch.item.database.JdbcPagingItemReader in project RecordManager2 by moravianlibrary.
the class ExportRecordsJobConfig method exportRecordsForClassifierReader.
@Bean(name = "exportRecordsForClassifierJob:exportRecordsForClassifierReader")
@StepScope
public ItemReader<HarvestedRecordUniqueId> exportRecordsForClassifierReader(@Value("#{jobParameters[" + Constants.JOB_PARAM_CONF_ID + "]}") Long configId) throws Exception {
JdbcPagingItemReader<HarvestedRecordUniqueId> reader = new JdbcPagingItemReader<HarvestedRecordUniqueId>();
SqlPagingQueryProviderFactoryBean pqpf = new SqlPagingQueryProviderFactoryBean();
pqpf.setDataSource(dataSource);
pqpf.setSelectClause("SELECT import_conf_id, record_id");
pqpf.setFromClause("FROM harvested_record");
pqpf.setWhereClause("WHERE import_conf_id = :conf_id AND dedup_record_id IN ( " + " SELECT dedup_record_id " + " FROM harvested_record " + " WHERE EXISTS( " + " SELECT 1 " + " FROM fulltext_kramerius " + " WHERE harvested_record.id = fulltext_kramerius.harvested_record_id " + " ))");
pqpf.setSortKey("record_id");
Map<String, Object> parameterValues = new HashMap<String, Object>();
parameterValues.put("conf_id", configId);
reader.setParameterValues(parameterValues);
reader.setRowMapper(new HarvestedRecordIdRowMapper());
reader.setPageSize(20);
reader.setQueryProvider(pqpf.getObject());
reader.setDataSource(dataSource);
reader.afterPropertiesSet();
return reader;
}
use of org.springframework.batch.item.database.JdbcPagingItemReader in project RecordManager2 by moravianlibrary.
the class DedupRecordsJobConfig method dedupSimpleKeysReader.
/**
* Generic components
*/
public ItemReader<List<Long>> dedupSimpleKeysReader(String tablename) throws Exception {
JdbcPagingItemReader<List<Long>> reader = new JdbcPagingItemReader<>();
SqlPagingQueryProviderFactoryBean pqpf = new SqlPagingQueryProviderFactoryBean();
pqpf.setDataSource(dataSource);
pqpf.setSelectClause("SELECT row_id,id_array");
pqpf.setFromClause("FROM " + tablename);
pqpf.setSortKey("row_id");
reader.setRowMapper(new ArrayLongMapper());
reader.setPageSize(100);
reader.setQueryProvider(pqpf.getObject());
reader.setDataSource(dataSource);
reader.afterPropertiesSet();
return reader;
}
use of org.springframework.batch.item.database.JdbcPagingItemReader in project RecordManager2 by moravianlibrary.
the class RegenerateDedupKeysJobConfig method reader.
@Bean(name = Constants.JOB_ID_REGEN_DEDUP_KEYS + ":regenarateDedupKeysReader")
@StepScope
public ItemReader<Long> reader() throws Exception {
JdbcPagingItemReader<Long> reader = new JdbcPagingItemReader<Long>();
SqlPagingQueryProviderFactoryBean pqpf = new SqlPagingQueryProviderFactoryBean();
pqpf.setDataSource(dataSource);
pqpf.setSelectClause("SELECT id");
pqpf.setFromClause("FROM harvested_record hr");
pqpf.setWhereClause("WHERE dedup_keys_hash is null");
pqpf.setSortKey("id");
reader.setRowMapper(new LongValueRowMapper());
reader.setPageSize(100);
reader.setQueryProvider(pqpf.getObject());
reader.setDataSource(dataSource);
reader.afterPropertiesSet();
return reader;
}
use of org.springframework.batch.item.database.JdbcPagingItemReader in project RecordManager2 by moravianlibrary.
the class IndexRecordsToSolrJobConfig method updatedRecordsReader.
@Bean(name = "indexRecordsToSolrJob:updatedRecordsReader")
@StepScope
public JdbcPagingItemReader<DedupRecord> updatedRecordsReader(@Value("#{jobParameters[" + Constants.JOB_PARAM_FROM_DATE + "]}") Date from, @Value("#{jobParameters[" + Constants.JOB_PARAM_UNTIL_DATE + "]}") Date to) throws Exception {
if (from != null && to == null) {
to = new Date();
}
SqlPagingQueryProviderFactoryBean pqpf = new SqlPagingQueryProviderFactoryBean();
pqpf.setDataSource(dataSource);
pqpf.setSelectClause("SELECT dedup_record_id");
pqpf.setFromClause("FROM dedup_record_last_update");
if (from != null && to != null) {
pqpf.setWhereClause("WHERE last_update BETWEEN :from AND :to");
}
pqpf.setSortKey("dedup_record_id");
JdbcPagingItemReader<DedupRecord> reader = new JdbcPagingItemReader<>();
reader.setRowMapper(new DedupRecordRowMapper("dedup_record_id"));
reader.setPageSize(PAGE_SIZE);
reader.setQueryProvider(pqpf.getObject());
reader.setDataSource(dataSource);
if (from != null && to != null) {
Map<String, Object> parameterValues = new HashMap<>();
parameterValues.put("from", from);
parameterValues.put("to", to);
reader.setParameterValues(parameterValues);
}
reader.setSaveState(true);
reader.afterPropertiesSet();
return reader;
}
use of org.springframework.batch.item.database.JdbcPagingItemReader in project RecordManager2 by moravianlibrary.
the class IndexRecordsToSolrJobConfig method orphanedRecordsReader.
@Bean(name = "indexRecordsToSolrJob:orphanedRecordsReader")
@StepScope
public JdbcPagingItemReader<Long> orphanedRecordsReader(@Value("#{jobParameters[" + Constants.JOB_PARAM_FROM_DATE + "]}") Date from, @Value("#{jobParameters[" + Constants.JOB_PARAM_UNTIL_DATE + "]}") Date to) throws Exception {
if (from != null && to == null) {
to = new Date();
}
SqlPagingQueryProviderFactoryBean pqpf = new SqlPagingQueryProviderFactoryBean();
pqpf.setDataSource(dataSource);
pqpf.setSelectClause("SELECT dedup_record_id");
pqpf.setFromClause("FROM dedup_record_orphaned");
if (from != null && to != null) {
pqpf.setWhereClause("WHERE orphaned BETWEEN :from AND :to");
}
pqpf.setSortKey("dedup_record_id");
JdbcPagingItemReader<Long> reader = new JdbcPagingItemReader<>();
reader.setRowMapper(new LongValueRowMapper());
reader.setPageSize(100000);
reader.setQueryProvider(pqpf.getObject());
reader.setDataSource(dataSource);
if (from != null && to != null) {
Map<String, Object> parameterValues = new HashMap<>();
parameterValues.put("from", from);
parameterValues.put("to", to);
reader.setParameterValues(parameterValues);
}
reader.setSaveState(true);
reader.afterPropertiesSet();
return reader;
}
Aggregations