Search in sources :

Example 16 with StepScope

use of org.springframework.batch.core.configuration.annotation.StepScope 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 17 with StepScope

use of org.springframework.batch.core.configuration.annotation.StepScope 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)

Example 18 with StepScope

use of org.springframework.batch.core.configuration.annotation.StepScope 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)

Example 19 with StepScope

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

Example 20 with StepScope

use of org.springframework.batch.core.configuration.annotation.StepScope 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;
}
Also used : SqlPagingQueryProviderFactoryBean(org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean) HashMap(java.util.HashMap) 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)

Aggregations

StepScope (org.springframework.batch.core.configuration.annotation.StepScope)22 Bean (org.springframework.context.annotation.Bean)22 SqlPagingQueryProviderFactoryBean (org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean)18 JdbcPagingItemReader (org.springframework.batch.item.database.JdbcPagingItemReader)17 HashMap (java.util.HashMap)14 HarvestedRecordUniqueId (cz.mzk.recordmanager.server.model.HarvestedRecord.HarvestedRecordUniqueId)7 HarvestedRecordIdRowMapper (cz.mzk.recordmanager.server.export.HarvestedRecordIdRowMapper)5 HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)4 Date (java.util.Date)4 LongValueRowMapper (cz.mzk.recordmanager.server.jdbc.LongValueRowMapper)3 FileSystemResource (org.springframework.core.io.FileSystemResource)3 Timestamp (java.sql.Timestamp)2 Transaction (org.baeldung.batch.model.Transaction)2 JobRepositoryFactoryBean (org.springframework.batch.core.repository.support.JobRepositoryFactoryBean)2 FlatFileItemReader (org.springframework.batch.item.file.FlatFileItemReader)2 DelimitedLineTokenizer (org.springframework.batch.item.file.transform.DelimitedLineTokenizer)2 Cosmotron996RowMapper (cz.mzk.recordmanager.server.jdbc.Cosmotron996RowMapper)1 DedupRecordRowMapper (cz.mzk.recordmanager.server.jdbc.DedupRecordRowMapper)1 Cosmotron996 (cz.mzk.recordmanager.server.model.Cosmotron996)1 DedupRecord (cz.mzk.recordmanager.server.model.DedupRecord)1