Search in sources :

Example 86 with NamedParameterJdbcTemplate

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;
}
Also used : NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) SQLException(java.sql.SQLException) HashMap(java.util.HashMap) MainNames(org.nextprot.api.core.domain.MainNames) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 87 with NamedParameterJdbcTemplate

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;
}
Also used : NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) SQLException(java.sql.SQLException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) SqlParameterSource(org.springframework.jdbc.core.namedparam.SqlParameterSource) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) NucleotidePositionRange(org.nextprot.api.commons.utils.NucleotidePositionRange) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List)

Example 88 with NamedParameterJdbcTemplate

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;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) SqlParameterSource(org.springframework.jdbc.core.namedparam.SqlParameterSource) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) HashMap(java.util.HashMap) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)

Example 89 with NamedParameterJdbcTemplate

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;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) SqlParameterSource(org.springframework.jdbc.core.namedparam.SqlParameterSource) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) HashMap(java.util.HashMap) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)

Example 90 with NamedParameterJdbcTemplate

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));
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) SqlParameterSource(org.springframework.jdbc.core.namedparam.SqlParameterSource) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) PublicationCvJournal(org.nextprot.api.core.domain.PublicationCvJournal)

Aggregations

NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)119 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)66 SqlParameterSource (org.springframework.jdbc.core.namedparam.SqlParameterSource)42 HashMap (java.util.HashMap)30 ResultSet (java.sql.ResultSet)16 SQLException (java.sql.SQLException)16 DbXref (org.nextprot.api.core.domain.DbXref)8 NextProtException (org.nextprot.api.commons.exception.NextProtException)7 PublicationDbXref (org.nextprot.api.core.domain.PublicationDbXref)7 ArrayList (java.util.ArrayList)5 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)5 List (java.util.List)4 Map (java.util.Map)4 CvTerm (org.nextprot.api.core.domain.CvTerm)4 GargoyleException (com.kyj.fx.voeditor.visual.exceptions.GargoyleException)3 NotSupportException (com.kyj.fx.voeditor.visual.exceptions.NotSupportException)3 DataSource (javax.sql.DataSource)3 UserProteinList (org.nextprot.api.user.domain.UserProteinList)3 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)2 Date (java.util.Date)2