Search in sources :

Example 1 with DedupRecordRowMapper

use of cz.mzk.recordmanager.server.jdbc.DedupRecordRowMapper 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;
}
Also used : DedupRecordRowMapper(cz.mzk.recordmanager.server.jdbc.DedupRecordRowMapper) SqlPagingQueryProviderFactoryBean(org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean) HashMap(java.util.HashMap) JdbcPagingItemReader(org.springframework.batch.item.database.JdbcPagingItemReader) DedupRecord(cz.mzk.recordmanager.server.model.DedupRecord) Date(java.util.Date) StepScope(org.springframework.batch.core.configuration.annotation.StepScope) SqlPagingQueryProviderFactoryBean(org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

DedupRecordRowMapper (cz.mzk.recordmanager.server.jdbc.DedupRecordRowMapper)1 DedupRecord (cz.mzk.recordmanager.server.model.DedupRecord)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 StepScope (org.springframework.batch.core.configuration.annotation.StepScope)1 JdbcPagingItemReader (org.springframework.batch.item.database.JdbcPagingItemReader)1 SqlPagingQueryProviderFactoryBean (org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean)1 Bean (org.springframework.context.annotation.Bean)1