List of usage examples for org.springframework.jdbc.core RowMapperResultSetExtractor RowMapperResultSetExtractor
public RowMapperResultSetExtractor(RowMapper<T> rowMapper, int rowsExpected)
From source file:cc.tooyoung.common.db.JdbcTemplate.java
@SuppressWarnings("unchecked") public int update(final PreparedStatementCreator psc, final KeyHolder generatedKeyHolder) throws DataAccessException { Assert.notNull(generatedKeyHolder, "KeyHolder must not be null"); if (ApiLogger.isTraceEnabled()) { ApiLogger.trace("Executing SQL update and returning generated keys"); }/*from w w w. j av a 2s .c om*/ Integer result = (Integer) execute(psc, new PreparedStatementCallback() { public Object doInPreparedStatement(PreparedStatement ps) throws SQLException { int rows = ps.executeUpdate(); List generatedKeys = generatedKeyHolder.getKeyList(); generatedKeys.clear(); ResultSet keys = ps.getGeneratedKeys(); if (keys != null) { try { RowMapper rowMapper = getColumnMapRowMapper(); RowMapperResultSetExtractor rse = new RowMapperResultSetExtractor(rowMapper, 1); generatedKeys.addAll((List) rse.extractData(keys)); } finally { JdbcUtils.closeResultSet(keys); } } if (ApiLogger.isTraceEnabled()) { ApiLogger.trace( "SQL update affected " + rows + " rows and returned " + generatedKeys.size() + " keys"); } return new Integer(rows); } }, true); return result.intValue(); }
From source file:org.gbif.harvest.portal.synchronise.dao.jdbc.AgentDaoImpl.java
/** * @see org.gbif.portal.dao.AgentDAO#getByNameAndEmail(java.lang.String, java.lang.String) *//* w w w . j a va 2 s . c o m*/ @SuppressWarnings("unchecked") public Agent getByNameAndEmail(final String name, final String email) { List<Agent> results = (List<Agent>) getJdbcTemplate().query(AgentDaoImpl.QUERY_BY_NAME_AND_EMAIL_SQL, new Object[] { name, email }, new RowMapperResultSetExtractor(agentRowMapper, 1)); if (results.size() == 0) { return null; } else if (results.size() > 1) { //logger.warn("Found multiple Agents with name[" + name + "] and email[" + email + "]"); log.warn("agentDaoImpl.error.multiple", new String[] { name, email }); } return results.get(0); }
From source file:org.gbif.harvest.portal.synchronise.dao.jdbc.AgentDaoImpl.java
/** * @see org.gbif.portal.dao.AgentDAO#isAgentAssociatedWithResource(long, long, int) *//* www. j a v a 2 s . c o m*/ @SuppressWarnings("unchecked") public boolean isAgentAssociatedWithResource(long dataResourceId, long agentId, int agentType) { List<Integer> results = (List<Integer>) getJdbcTemplate().query(AgentDaoImpl.QUERY_FOR_RESOURCE_AGENT, new Object[] { dataResourceId, agentId, agentType }, new RowMapperResultSetExtractor(intRowMapper, 1)); if (results.size() > 0) { return true; } else { return false; } }
From source file:org.gbif.harvest.portal.synchronise.dao.jdbc.AgentDaoImpl.java
/** * @see org.gbif.portal.dao.AgentDAO#isAgentAssociatedWithProvider(long, long, int) *//*from www . j a v a 2s . c om*/ @SuppressWarnings("unchecked") public boolean isAgentAssociatedWithProvider(long dataProviderId, long agentId, int agentType) { List<Integer> results = (List<Integer>) getJdbcTemplate().query(AgentDaoImpl.QUERY_FOR_PROVIDER_AGENT, new Object[] { dataProviderId, agentId, agentType }, new RowMapperResultSetExtractor(intRowMapper, 1)); if (results.size() > 0) { return true; } else { return false; } }
From source file:org.gbif.harvest.portal.synchronise.dao.jdbc.RawOccurrenceRecordDaoImpl.java
/** * @see org.gbif.harvest.portal.synchronise.dao.RawOccurrenceRecordDao#getById(long) */// w w w . j a v a 2s.com @SuppressWarnings("unchecked") public RawOccurrenceRecord getById(final long id) { List<RawOccurrenceRecord> results = (List<RawOccurrenceRecord>) getJdbcTemplate().query( RawOccurrenceRecordDaoImpl.QUERY_ID_SQL, new Object[] { id }, new RowMapperResultSetExtractor(rawOccurrenceRecordRowMapper, 1)); if (results.size() == 0) { return null; } else if (results.size() > 1) { log.warn("Found multiple RawOccurrenceRecords with Id[" + id + "]"); } return results.get(0); }
From source file:org.gbif.harvest.portal.synchronise.dao.jdbc.RawOccurrenceRecordDaoImpl.java
/** * @see org.gbif.harvest.portal.synchronise.dao.RawOccurrenceRecordDao#getDataResourceIdsFor(long) *///from w ww.j ava2 s . c o m @SuppressWarnings("unchecked") public List<Long> getDataResourceIdsFor(long resourceAccessPointId) { List<Long> results = (List<Long>) getJdbcTemplate().query(RawOccurrenceRecordDaoImpl.QUERY_DATA_RESOURCE, new Object[] { resourceAccessPointId }, new RowMapperResultSetExtractor(longRowMapper, 3)); return results; }
From source file:org.gbif.harvest.portal.synchronise.dao.jdbc.RawOccurrenceRecordDaoImpl.java
/** * @see org.gbif.harvest.portal.synchronise.dao.RawOccurrenceRecordDao#getFullRawDistinctClassification(long) *///from ww w . ja v a2 s .com @SuppressWarnings("unchecked") public List<LinnaeanRankClassification> getFullRawDistinctClassification(long dataResourceId) { List<LinnaeanRankClassification> results = (List<LinnaeanRankClassification>) getJdbcTemplate().query( RawOccurrenceRecordDaoImpl.QUERY_RAW_TAXONOMY, new Object[] { dataResourceId }, new RowMapperResultSetExtractor(linnaeanRankClassificationRowMapper, 1000)); return results; }
From source file:org.gbif.harvest.portal.synchronise.dao.jdbc.RawOccurrenceRecordDaoImpl.java
/** * @see org.gbif.harvest.portal.synchronise.dao.RawOccurrenceRecordDao#getUniqueRecord(long, String, String, String, String) * java.lang.String)/*from ww w . ja va 2 s . co m*/ */ @SuppressWarnings("unchecked") public RawOccurrenceRecord getUniqueRecord(long dataResourceId, String institutionCode, String collectionCode, String catalogueNumber, String unitQualifier) { StringBuffer query = new StringBuffer(RawOccurrenceRecordDaoImpl.QUERY_UNIQUE_SQL); List<Object> params = new LinkedList<Object>(); params.add(new Long(dataResourceId)); params.add(institutionCode); params.add(collectionCode); params.add(catalogueNumber); if (StringUtils.isNotEmpty(unitQualifier)) { query.append(" and unit_qualifier=?"); params.add(unitQualifier); } List<RawOccurrenceRecord> results = (List<RawOccurrenceRecord>) getJdbcTemplate().query(query.toString(), params.toArray(), new RowMapperResultSetExtractor(rawOccurrenceRecordRowMapper, 1)); if (results.size() == 0) { return null; } else if (results.size() > 1) { log.warn("Found multiple RawOccurrenceRecords with dataResourceId[" + dataResourceId + "], institutionCode[" + institutionCode + "], collectionCode[" + collectionCode + "] and catalogueNumber[" + catalogueNumber + "] + and unitQualifier[" + unitQualifier + "]"); } return results.get(0); }
From source file:org.gbif.portal.dao.impl.jdbc.CommonNameDAOImpl.java
/** * @see org.gbif.portal.dao.CommonNameDAO#getUnique(java.lang.Long, java.lang.String, java.lang.String) *///w w w . j av a 2s. c om @SuppressWarnings("unchecked") public CommonName getUnique(String name, String language) { List<CommonName> results = null; if (StringUtils.isEmpty(language)) { results = (List<CommonName>) getJdbcTemplate().query( CommonNameDAOImpl.QUERY_BY_CONCEPT_NAME_NOLANGUAGE_SQL, new Object[] { name }, new RowMapperResultSetExtractor(commonNameRowMapper, 1)); } else { results = (List<CommonName>) getJdbcTemplate().query( CommonNameDAOImpl.QUERY_BY_CONCEPT_NAME_LANGUAGE_SQL, new Object[] { name, language }, new RowMapperResultSetExtractor(commonNameRowMapper, 1)); } if (results.size() == 0) { return null; } else if (results.size() > 1) { logger.warn("Found multiple CommonNames with name[" + name + "], language[" + language + "]"); } return results.get(0); }
From source file:org.gbif.portal.dao.impl.jdbc.CommonNameDAOImpl.java
/** * @see org.gbif.portal.dao.CommonNameDAO#getUnique(java.lang.String, java.lang.String, int) *//*from w w w .j ava2s .co m*/ @SuppressWarnings("unchecked") public CommonName getById(long id) { List<CommonName> results = (List<CommonName>) getJdbcTemplate().query(CommonNameDAOImpl.QUERY_BY_ID_SQL, new Object[] { id }, new RowMapperResultSetExtractor(commonNameRowMapper, 1)); if (results.size() == 0) { return null; } else if (results.size() > 1) { logger.warn("Found multiple CommonNames with id[" + id + "]"); } return results.get(0); }