Search in sources :

Example 11 with JdbcPagingItemReader

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;
}
Also used : HarvestedRecordUniqueId(cz.mzk.recordmanager.server.model.HarvestedRecord.HarvestedRecordUniqueId) 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)

Example 12 with JdbcPagingItemReader

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;
}
Also used : SqlPagingQueryProviderFactoryBean(org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean) ArrayList(java.util.ArrayList) List(java.util.List) JdbcPagingItemReader(org.springframework.batch.item.database.JdbcPagingItemReader)

Example 13 with JdbcPagingItemReader

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;
}
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 14 with JdbcPagingItemReader

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;
}
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 15 with JdbcPagingItemReader

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;
}
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

JdbcPagingItemReader (org.springframework.batch.item.database.JdbcPagingItemReader)18 SqlPagingQueryProviderFactoryBean (org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean)18 StepScope (org.springframework.batch.core.configuration.annotation.StepScope)17 Bean (org.springframework.context.annotation.Bean)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 Timestamp (java.sql.Timestamp)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 ArrayList (java.util.ArrayList)1 List (java.util.List)1