use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project nextprot-api by calipho-sib.
the class MainNamesDAOImpl method getMainNamesMap.
@Override
public Map<String, MainNames> getMainNamesMap() {
List<Map<String, Object>> rows = new NamedParameterJdbcTemplate(dsLocator.getDataSource()).query(sqlDictionary.getSQLQuery("isoform-names"), new RowMapper<Map<String, Object>>() {
@Override
public Map<String, Object> mapRow(ResultSet resultSet, int row) throws SQLException {
Map<String, Object> rec = new HashMap<>();
// isoform accession
String isoformAc = resultSet.getString("unique_name");
rec.put("isoform_ac", isoformAc);
// derive entry accession from isoform accession
String masterAc = isoformAc.substring(0, isoformAc.indexOf("-"));
rec.put("master_ac", masterAc);
// entry (display) name
rec.put("master_name", resultSet.getString("master_name"));
// handle isoform name
String isoName = resultSet.getString("isoform_name");
try {
// if it is a number, prefix it with "Iso "
Integer.parseInt(isoName);
isoName = "Iso " + isoName;
} catch (NumberFormatException e) {
}
rec.put("isoform_name", isoName);
// handle gene list
String genes = resultSet.getString("gene_name");
String[] geneArray = genes.split(";");
List<String> geneList = new ArrayList<>();
for (String g : geneArray) geneList.add(g.trim());
rec.put("geneList", geneList);
return rec;
}
});
// now turn the list into a map
Map<String, MainNames> result = new HashMap<>();
for (Map<String, Object> rec : rows) {
String masterAc = (String) rec.get("master_ac");
// add a map entry for the master if not already done from a previous row
if (!result.containsKey(masterAc)) {
MainNames names = new MainNames();
names.setAccession(masterAc);
names.setName((String) rec.get("master_name"));
names.setGeneNameList((List<String>) rec.get("geneList"));
result.put(masterAc, names);
}
// add a map entry for the isoform
MainNames names = new MainNames();
String isoAc = (String) rec.get("isoform_ac");
names.setAccession(isoAc);
names.setName((String) rec.get("isoform_name"));
names.setGeneNameList((List<String>) rec.get("geneList"));
result.put(isoAc, names);
}
return result;
}
use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project nextprot-api by calipho-sib.
the class MasterIsoformMappingDaoImpl method findMasterIsoformMapping.
@Override
public Map<String, List<NucleotidePositionRange>> findMasterIsoformMapping(String ac) {
SqlParameterSource namedParams = new MapSqlParameterSource("entryName", ac);
List<IsoMasterNuRangePos> isoNuRanges = new NamedParameterJdbcTemplate(dsLocator.getDataSource()).query(sqlDictionary.getSQLQuery("master-isoform-mapping-by-entry-name"), namedParams, new RowMapper<IsoMasterNuRangePos>() {
@Override
public IsoMasterNuRangePos mapRow(ResultSet resultSet, int row) throws SQLException {
IsoMasterNuRangePos rec = new IsoMasterNuRangePos();
rec.iso = resultSet.getString("isoform_ac");
rec.nuPosRange = new NucleotidePositionRange(resultSet.getInt("first_pos"), resultSet.getInt("last_pos"));
return rec;
}
});
Map<String, List<NucleotidePositionRange>> mapIsoNuRanges = new HashMap<String, List<NucleotidePositionRange>>();
for (IsoMasterNuRangePos rec : isoNuRanges) {
if (!mapIsoNuRanges.containsKey(rec.iso))
mapIsoNuRanges.put(rec.iso, new ArrayList<NucleotidePositionRange>());
mapIsoNuRanges.get(rec.iso).add(new NucleotidePositionRange(rec.nuPosRange.getLower(), rec.nuPosRange.getUpper()));
}
return mapIsoNuRanges;
}
use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project nextprot-api by calipho-sib.
the class MdataDaoImpl method findEvidenceIdMdataIdMapForPTMsByEntryName.
@Override
public Map<Long, Long> findEvidenceIdMdataIdMapForPTMsByEntryName(String ac) {
SqlParameterSource namedParameters = new MapSqlParameterSource("entry_name", ac);
Map<Long, Long> map = new HashMap<>();
EvidenceMdataMapRowMapper mapper = new EvidenceMdataMapRowMapper(map);
new NamedParameterJdbcTemplate(dsLocator.getDataSource()).query(sqlDictionary.getSQLQuery("ptm-evidence-with-mdata-by-unique-name"), namedParameters, mapper);
return map;
}
use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project nextprot-api by calipho-sib.
the class MdataDaoImpl method findEvidenceIdMdataIdMapForPeptideMappingsByEntryName.
@Override
public Map<Long, Long> findEvidenceIdMdataIdMapForPeptideMappingsByEntryName(String ac) {
SqlParameterSource namedParameters = new MapSqlParameterSource("entry_name", ac);
Map<Long, Long> map = new HashMap<>();
EvidenceMdataMapRowMapper mapper = new EvidenceMdataMapRowMapper(map, IdentifierOffset.PEPTIDE_MAPPING_ANNOTATION_EVIDENCE_OFFSET);
new NamedParameterJdbcTemplate(dsLocator.getDataSource()).query(sqlDictionary.getSQLQuery("peptide-evidence-with-mdata-by-unique-name"), namedParameters, mapper);
return map;
}
use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project nextprot-api by calipho-sib.
the class PublicationDaoImpl method findPublicationById.
@Override
public Publication findPublicationById(long publicationId) {
SqlParameterSource namedParameters = new MapSqlParameterSource("resourceId", publicationId);
// get the journal found for publication id
List<PublicationCvJournal> journals = journalDao.findCvJournalsByPublicationIds(Collections.singletonList(publicationId));
return new NamedParameterJdbcTemplate(dsLocator.getDataSource()).queryForObject(sqlDictionary.getSQLQuery("publication-by-resourceid"), namedParameters, new PublicationRowMapper(journals));
}
Aggregations