Search in sources :

Example 1 with LongValueRowMapper

use of cz.mzk.recordmanager.server.jdbc.LongValueRowMapper in project RecordManager2 by moravianlibrary.

the class UniqueRecordsDedupTasklet method execute.

@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
    ExecutionContext ctx = chunkContext.getStepContext().getStepExecution().getExecutionContext();
    long harvestedRecordId = ctx.getLong("harvestedRecordId", 0L);
    Long nextHarvestedRecordId = DataAccessUtils.singleResult(jdbcTemplate.query(command, new Object[] { harvestedRecordId }, new LongValueRowMapper()));
    if (nextHarvestedRecordId != null) {
        ctx.putLong("harvestedRecordId", nextHarvestedRecordId);
    }
    logger.debug("nextHarvestedRecordId: {}", nextHarvestedRecordId);
    return (nextHarvestedRecordId == null) ? RepeatStatus.FINISHED : RepeatStatus.CONTINUABLE;
}
Also used : LongValueRowMapper(cz.mzk.recordmanager.server.jdbc.LongValueRowMapper) ExecutionContext(org.springframework.batch.item.ExecutionContext)

Example 2 with LongValueRowMapper

use of cz.mzk.recordmanager.server.jdbc.LongValueRowMapper in project RecordManager2 by moravianlibrary.

the class MiscellaneousJobsConfig method generateSkatKeysReader.

@Bean(name = Constants.JOB_ID_GENERATE_SKAT_DEDUP_KEYS + ":generateSkatKeysReader")
@StepScope
public ItemReader<Long> generateSkatKeysReader(@Value("#{jobParameters[" + Constants.JOB_PARAM_FROM_DATE + "]}") Date fromDate, @Value("#{jobParameters[" + Constants.JOB_PARAM_UNTIL_DATE + "]}") Date toDate) throws Exception {
    Date from = fromDate == null ? new Date(0) : fromDate;
    Date to = toDate == null ? new Date() : toDate;
    JdbcPagingItemReader<Long> reader = new JdbcPagingItemReader<>();
    SqlPagingQueryProviderFactoryBean pqpf = new SqlPagingQueryProviderFactoryBean();
    pqpf.setDataSource(dataSource);
    pqpf.setSelectClause("SELECT id");
    pqpf.setFromClause("FROM harvested_record");
    pqpf.setWhereClause("WHERE import_conf_id = :conf_id AND updated > :updated_from AND updated < :updated_to");
    pqpf.setSortKey("id");
    Map<String, Object> parameterValues = new HashMap<String, Object>();
    parameterValues.put("conf_id", Constants.IMPORT_CONF_ID_CASLIN);
    parameterValues.put("updated_from", from);
    parameterValues.put("updated_to", to);
    reader.setParameterValues(parameterValues);
    reader.setRowMapper(new LongValueRowMapper());
    reader.setPageSize(100);
    reader.setQueryProvider(pqpf.getObject());
    reader.setDataSource(dataSource);
    reader.afterPropertiesSet();
    return reader;
}
Also used : LongValueRowMapper(cz.mzk.recordmanager.server.jdbc.LongValueRowMapper) SqlPagingQueryProviderFactoryBean(org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean) HashMap(java.util.HashMap) JdbcPagingItemReader(org.springframework.batch.item.database.JdbcPagingItemReader) 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)

Example 3 with LongValueRowMapper

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

Example 4 with LongValueRowMapper

use of cz.mzk.recordmanager.server.jdbc.LongValueRowMapper 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;
}
Also used : LongValueRowMapper(cz.mzk.recordmanager.server.jdbc.LongValueRowMapper) SqlPagingQueryProviderFactoryBean(org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean) HashMap(java.util.HashMap) JdbcPagingItemReader(org.springframework.batch.item.database.JdbcPagingItemReader) 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

LongValueRowMapper (cz.mzk.recordmanager.server.jdbc.LongValueRowMapper)4 StepScope (org.springframework.batch.core.configuration.annotation.StepScope)3 JdbcPagingItemReader (org.springframework.batch.item.database.JdbcPagingItemReader)3 SqlPagingQueryProviderFactoryBean (org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean)3 Bean (org.springframework.context.annotation.Bean)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2 ExecutionContext (org.springframework.batch.item.ExecutionContext)1