List of usage examples for org.springframework.jdbc.core SingleColumnRowMapper SingleColumnRowMapper
public SingleColumnRowMapper()
From source file:com.stehno.sjdbcx.reflection.extractor.RowMapperExtractor.java
public RowMapper extract(final Method method) { final com.stehno.sjdbcx.annotation.RowMapper mapper = AnnotationUtils.getAnnotation(method, com.stehno.sjdbcx.annotation.RowMapper.class); if (mapper == null) { Class mappedType = method.getReturnType(); if (Collection.class.isAssignableFrom(mappedType)) { mappedType = (Class) ((ParameterizedType) method.getGenericReturnType()) .getActualTypeArguments()[0]; } else if (mappedType.isArray()) { throw new UnsupportedOperationException("Auto-mapping for array return types is not yet supported"); } else if (mappedType.isPrimitive()) { if (mappedType == int.class || mappedType == long.class) { return new SingleColumnRowMapper(); } else if (mappedType == boolean.class) { return new RowMapper<Boolean>() { @Override/*from ww w . j a va 2 s. c o m*/ public Boolean mapRow(final ResultSet resultSet, final int i) throws SQLException { return resultSet.getBoolean(1); } }; } } return new BeanPropertyRowMapper(mappedType); } else { final String extractKey = mapper.value(); if (StringUtils.isEmpty(extractKey)) { return resolve((Class<RowMapper>) mapper.type()); } else { return resolve(extractKey); } } }
From source file:org.ohmage.query.impl.ClassDocumentQueries.java
public List<String> getClassesAssociatedWithDocument(String documentId) throws DataAccessException { try {/*from ww w .j a va 2 s .co m*/ return getJdbcTemplate().query(SQL_GET_CLASSES_ASSOCIATED_WITH_DOCUMENT, new Object[] { documentId }, new SingleColumnRowMapper<String>()); } catch (org.springframework.dao.DataAccessException e) { throw new DataAccessException("Error executing SQL '" + SQL_GET_CLASSES_ASSOCIATED_WITH_DOCUMENT + "' with parameter: " + documentId, e); } }
From source file:org.ohmage.query.impl.CampaignDocumentQueries.java
@Override public List<String> getCampaignsAssociatedWithDocument(String documentId) throws DataAccessException { try {/*from w w w. ja v a 2 s. com*/ return getJdbcTemplate().query(SQL_GET_CAMPAIGNS_ASSOCIATED_WITH_DOCUMENT, new Object[] { documentId }, new SingleColumnRowMapper<String>()); } catch (org.springframework.dao.DataAccessException e) { throw new DataAccessException("Error executing SQL '" + SQL_GET_CAMPAIGNS_ASSOCIATED_WITH_DOCUMENT + "' with parameter: " + documentId, e); } }
From source file:com.sinosoft.one.data.jade.dataaccess.DataAccessImpl.java
/** * 2012-08-16/*w ww.j a v a 2 s. c om*/ */ public <T> Page<T> selectByPage(Pageable pageable, String sql, String countSql, Object[] args, RowMapper<?> rowMapper) { Session session = em.unwrap(Session.class); SingleColumnRowMapper<BigDecimal> scrm = new SingleColumnRowMapper<BigDecimal>(); List<BigDecimal> totals = select(countSql, args, scrm); RenderSqlWork psw = new RenderSqlWork(sql, pageable, null); session.doWork(psw); sql = psw.getSql(); List<T> content = select(sql, args, rowMapper); if (content == null) { content = new ArrayList<T>(); } Object o = totals.get(0); Number num = (Number) o; Page<T> page = new PageImpl<T>(content, pageable, num.longValue()); return page; }
From source file:org.ohmage.query.impl.CampaignClassQueries.java
@Override public List<String> getCampaignsAssociatedWithClass(String classId) throws DataAccessException { try {// ww w. jav a2 s .c o m return getJdbcTemplate().query(SQL_GET_CAMPAIGNS_ASSOCIATED_WITH_CLASS, new Object[] { classId }, new SingleColumnRowMapper<String>()); } catch (org.springframework.dao.DataAccessException e) { throw new DataAccessException("Error executing SQL '" + SQL_GET_CAMPAIGNS_ASSOCIATED_WITH_CLASS + "' with parameter: " + classId, e); } }
From source file:org.ohmage.query.impl.CampaignClassQueries.java
@Override public List<String> getClassesAssociatedWithCampaign(String campaignId) throws DataAccessException { try {/*from www . j a v a2s. co m*/ return getJdbcTemplate().query(SQL_GET_CLASSES_ASSOCIATED_WITH_CAMPAIGN, new Object[] { campaignId }, new SingleColumnRowMapper<String>()); } catch (org.springframework.dao.DataAccessException e) { throw new DataAccessException("Error executing SQL '" + SQL_GET_CLASSES_ASSOCIATED_WITH_CAMPAIGN + "' with parameter: " + campaignId, e); } }
From source file:org.ohmage.query.impl.UserClassDocumentQueries.java
/** * Gathers the unique identifiers for all of the documents associated with * a class./*from www .ja va2 s . c om*/ * * @param username The username of the requesting user. * * @param classId The class' unique identifier. * * @return A list of the documents associated with a class. The list may be * empty but never null. * * @throws DataAccessException Thrown if there is an error. */ public List<String> getVisibleDocumentsToUserInClass(String username, String classId) throws DataAccessException { try { return getJdbcTemplate().query(SQL_GET_DOCUMENTS_SPECIFIC_TO_CLASS_FOR_REQUESTING_USER, new Object[] { username, classId }, new SingleColumnRowMapper<String>()); } catch (org.springframework.dao.DataAccessException e) { throw new DataAccessException( "Error executing SQL '" + SQL_GET_DOCUMENTS_SPECIFIC_TO_CLASS_FOR_REQUESTING_USER + " with parameters: " + username + ", " + classId, e); } }
From source file:org.ohmage.query.impl.UserCampaignDocumentQueries.java
/** * Retrieves the list of document IDs for all of the documents associated * with a campaign./*from w w w .j a v a 2s .com*/ * * @param username The username of the requesting user. * * @param campaignId The campaign's unique identifier. * * @return A list of document IDs. * * @throws DataAccessException Thrown if there is an error. */ public List<String> getVisibleDocumentsToUserInCampaign(String username, String campaignId) throws DataAccessException { try { return getJdbcTemplate().query(SQL_GET_DOCUMENTS_SPECIFIC_TO_CAMPAIGN_FOR_REQUESTING_USER, new Object[] { username, campaignId }, new SingleColumnRowMapper<String>()); } catch (org.springframework.dao.DataAccessException e) { throw new DataAccessException( "Error executing SQL '" + SQL_GET_DOCUMENTS_SPECIFIC_TO_CAMPAIGN_FOR_REQUESTING_USER + " with parameters: " + username + ", " + campaignId, e); } }
From source file:org.ohmage.query.impl.CampaignImageQueries.java
public List<String> getCampaignIdsForImageId(UUID imageId) throws DataAccessException { try {//from w w w . j av a 2s.c om return getJdbcTemplate().query(SQL_GET_CAMPAIGN_IDS_FOR_IMAGE, new Object[] { imageId.toString() }, new SingleColumnRowMapper<String>()); } catch (org.springframework.dao.DataAccessException e) { throw new DataAccessException( "Error executing SQL '" + SQL_GET_CAMPAIGN_IDS_FOR_IMAGE + "' with parameter: " + imageId, e); } }
From source file:org.cateproject.features.FeatureStoreSpringJDBC.java
/** {@inheritDoc} */ @Override/*from ww w . ja v a2 s . c o m*/ public Feature read(String uid) { if (uid == null || uid.isEmpty()) { throw new IllegalArgumentException("Feature identifier (param#0) cannot be null nor empty"); } List<Feature> dbFlips = getJdbcTemplate().query(SQLQUERY_GET_FEATURE_BY_ID, MAPPER, uid); if (dbFlips.isEmpty()) { throw new FeatureNotFoundException(uid); } Feature fp = dbFlips.get(0); List<String> auths = getJdbcTemplate().query(SQL_GET_ROLES, new SingleColumnRowMapper<String>(), uid); fp.getPermissions().addAll(auths); return fp; }