use of org.springframework.batch.item.database.JdbcPagingItemReader in project RecordManager2 by moravianlibrary.
the class KrameriusFulltextJobConfig method reader.
/* reads document uuids for given config (may be limited by update date)
* returns ItemReader for HarvestedRecord(s)
*/
@Bean(name = "krameriusFulltextJob:reader")
@StepScope
public ItemReader<HarvestedRecord> reader(@Value("#{jobParameters[" + Constants.JOB_PARAM_CONF_ID + "]}") Long configId, @Value("#{stepExecutionContext[" + Constants.JOB_PARAM_FROM_DATE + "] " + "?:jobParameters[ " + Constants.JOB_PARAM_FROM_DATE + "]}") Date from, @Value("#{stepExecutionContext[" + Constants.JOB_PARAM_UNTIL_DATE + "]" + "?:jobParameters[" + Constants.JOB_PARAM_UNTIL_DATE + "]}") Date to) throws Exception {
Timestamp fromStamp = null;
Timestamp toStamp = null;
JdbcPagingItemReader<HarvestedRecord> reader = new JdbcPagingItemReader<HarvestedRecord>();
SqlPagingQueryProviderFactoryBean pqpf = new SqlPagingQueryProviderFactoryBean();
pqpf.setDataSource(dataSource);
pqpf.setSelectClause("SELECT *");
pqpf.setFromClause("FROM harvested_record");
String whereClause = "WHERE import_conf_id = :configId";
if (from != null) {
fromStamp = new Timestamp(from.getTime());
whereClause += " AND updated >= :from";
}
if (to != null) {
toStamp = new Timestamp(to.getTime());
whereClause += " AND updated <= :to";
}
if (configId != null) {
pqpf.setWhereClause(whereClause);
}
pqpf.setSortKeys(ImmutableMap.of("import_conf_id", Order.ASCENDING, "record_id", Order.ASCENDING));
reader.setRowMapper(harvestedRecordRowMapper);
reader.setPageSize(PAGE_SIZE);
reader.setQueryProvider(pqpf.getObject());
reader.setDataSource(dataSource);
if (configId != null) {
Map<String, Object> parameterValues = new HashMap<String, Object>();
parameterValues.put("configId", configId);
parameterValues.put("from", fromStamp);
parameterValues.put("to", toStamp);
reader.setParameterValues(parameterValues);
}
reader.afterPropertiesSet();
return reader;
}
use of org.springframework.batch.item.database.JdbcPagingItemReader in project RecordManager2 by moravianlibrary.
the class InspirationImportJobConfig method inspirationDeleteReader.
@Bean(name = Constants.JOB_ID_DELETE_INSPIRATION + ":deleteInspirationReader")
@StepScope
public ItemReader<Long> inspirationDeleteReader(@Value("#{jobParameters[" + Constants.JOB_PARAM_DELETE_INSPIRATION + "]}") String name) throws Exception {
JdbcPagingItemReader<Long> reader = new JdbcPagingItemReader<Long>();
SqlPagingQueryProviderFactoryBean pqpf = new SqlPagingQueryProviderFactoryBean();
pqpf.setDataSource(dataSource);
pqpf.setSelectClause("SELECT id");
pqpf.setFromClause("FROM inspiration");
pqpf.setWhereClause("WHERE name = :name");
pqpf.setSortKey("id");
Map<String, Object> parameterValues = new HashMap<String, Object>();
parameterValues.put("name", name);
reader.setParameterValues(parameterValues);
reader.setRowMapper(new InspirationIdRowMapper());
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 FilterCaslinRecordsBySiglaJobConfig method caslinRecordsReader.
@Bean(name = Constants.JOB_ID_FILTER_CASLIN + ":caslinRecordsReader")
@StepScope
public synchronized ItemReader<HarvestedRecordUniqueId> caslinRecordsReader() 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 deleted is null");
pqpf.setSortKey("record_id");
Map<String, Object> parameterValues = new HashMap<String, Object>();
parameterValues.put("conf_id", Constants.IMPORT_CONF_ID_CASLIN);
reader.setParameterValues(parameterValues);
reader.setRowMapper(new HarvestedRecordIdRowMapper());
reader.setPageSize(20);
reader.setQueryProvider(pqpf.getObject());
reader.setDataSource(dataSource);
reader.afterPropertiesSet();
return reader;
}
Aggregations