Search in sources :

Example 16 with SimpleJdbcInsert

use of org.springframework.jdbc.core.simple.SimpleJdbcInsert in project goci by EBISPOT.

the class V2_0_1_002__Remove_duplicates_from_snp_region_table method migrate.

@Override
public void migrate(JdbcTemplate jdbcTemplate) throws Exception {
    final Map<Long, Long> snpIdToRegionId = new HashMap<>();
    // Go through list of exact duplicates in SNP_REGION table
    jdbcTemplate.query(SELECT_DUPLICATES, (resultSet, i) -> {
        Long snpId = resultSet.getLong(1);
        Long regionId = resultSet.getLong(2);
        // Store entry so we can recreate
        snpIdToRegionId.put(snpId, regionId);
        // Delete all entries
        jdbcTemplate.update(DELETE_FROM_SNP_REGION, snpId, regionId);
        return null;
    });
    // Insert statements
    SimpleJdbcInsert insertSnpRegion = new SimpleJdbcInsert(jdbcTemplate).withTableName("SNP_REGION").usingColumns("SNP_ID", "REGION_ID");
    for (Long snpId : snpIdToRegionId.keySet()) {
        Long regionId = snpIdToRegionId.get(snpId);
        Map<String, Object> snpRegionArgs = new HashMap<>();
        snpRegionArgs.put("SNP_ID", snpId);
        snpRegionArgs.put("REGION_ID", regionId);
        insertSnpRegion.execute(snpRegionArgs);
    }
}
Also used : HashMap(java.util.HashMap) SimpleJdbcInsert(org.springframework.jdbc.core.simple.SimpleJdbcInsert)

Example 17 with SimpleJdbcInsert

use of org.springframework.jdbc.core.simple.SimpleJdbcInsert in project goci by EBISPOT.

the class V2_0_1_014__Migrate_entrez_ids method migrate.

@Override
public void migrate(JdbcTemplate jdbcTemplate) throws Exception {
    // Query for gene IDs
    jdbcTemplate.query(SELECT_ENTREZ_GENE_IDS, (resultSet, i) -> {
        String geneId = resultSet.getString(1);
        // Insert into new table
        SimpleJdbcInsert insertEntrezId = new SimpleJdbcInsert(jdbcTemplate).withTableName("ENTREZ_GENE").usingColumns("ENTREZ_GENE_ID");
        Map<String, Object> insertArgs = new HashMap<>();
        insertArgs.put("ENTREZ_GENE_ID", geneId);
        insertEntrezId.execute(insertArgs);
        return null;
    });
}
Also used : HashMap(java.util.HashMap) SimpleJdbcInsert(org.springframework.jdbc.core.simple.SimpleJdbcInsert)

Aggregations

SimpleJdbcInsert (org.springframework.jdbc.core.simple.SimpleJdbcInsert)17 HashMap (java.util.HashMap)13 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)5 Set (java.util.Set)5 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)5 ResultSet (java.sql.ResultSet)4 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)4 List (java.util.List)3 TestCaseStep (org.sakuli.datamodel.TestCaseStep)1 DaoTestCaseStep (org.sakuli.services.forwarder.database.dao.DaoTestCaseStep)1