List of usage examples for org.springframework.jdbc.core RowMapper RowMapper
RowMapper
From source file:com.sfs.whichdoctor.analysis.RevenueAnalysisDAOImpl.java
/** * Batch analysis.//from w ww.j a va2s . com * * @param search the search * * @return the revenue analysis bean * * @throws WhichDoctorAnalysisDaoException the which doctor analysis dao * exception */ @SuppressWarnings("unchecked") public final RevenueAnalysisBean batchAnalysis(final RevenueAnalysisBean search) throws WhichDoctorAnalysisDaoException { /* Zero out values in revenue analysis bean */ search.setValue(0); search.setNetValue(0); /* Set ordering system of returned results */ String sqlORDER = " ORDER BY receipt.BatchReference, receipt.ReceiptNo"; StringBuffer sqlWHERE = new StringBuffer(); Collection<Object> parameters = new ArrayList<Object>(); if (search.getSQLWhereStatement() != null) { if (search.getSQLWhereStatement().compareTo("") != 0) { sqlWHERE.append(" AND "); sqlWHERE.append(search.getSQLWhereStatement()); } } if (search.getSearchParameters() != null) { parameters = search.getSearchParameters(); } /* BUILD SQL Statement */ final StringBuffer searchSQL = new StringBuffer(); searchSQL.append(this.getSQL().getValue("revenue")); searchSQL.append(sqlWHERE.toString()); searchSQL.append(" GROUP BY payment.PaymentId, receipt.BatchReference "); searchSQL.append(sqlORDER); dataLogger.info("SQL Query: " + searchSQL.toString()); Collection<RevenueBean> results = new ArrayList<RevenueBean>(); try { results = this.getJdbcTemplateReader().query(searchSQL.toString(), parameters.toArray(), new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return loadBatchRevenue(rs); } }); } catch (IncorrectResultSizeDataAccessException ie) { // No results found for this search dataLogger.debug("No results found for this search: " + ie.getMessage()); } final TreeMap<Object, ArrayList<RevenueBean>> batchMap = new TreeMap<Object, ArrayList<RevenueBean>>(); for (RevenueBean revenue : results) { ArrayList<RevenueBean> revenueList = new ArrayList<RevenueBean>(); if (batchMap.containsKey(revenue.getBatchReference())) { revenueList = batchMap.get(revenue.getBatchReference()); } revenueList.add(revenue); batchMap.put(revenue.getBatchReference(), revenueList); } final RevenueAnalysisBean summary = consolidateSummary(batchMap); search.setValue(summary.getValue()); search.setNetValue(summary.getNetValue()); search.setGSTValues(summary.getGSTValues()); search.setRevenue(summary.getRevenue()); return search; }
From source file:Implement.DAO.CommonDAOImpl.java
@Override public int getAccountIDByEmail(String email) { int providerID; String sql = "SELECT ProviderID AS id FROM Provider WHERE Email = ? " + "UNION " + "SELECT TripperID AS id FROM Tripper WHERE Email = ? "; try {// w ww . j a va 2 s. c o m providerID = jdbcTemplate.queryForObject(sql, new RowMapper<Integer>() { @Override public Integer mapRow(ResultSet rs, int i) throws SQLException { try { return rs.getInt("id"); } catch (Exception e) { return 0; } } }, email, email); } catch (EmptyResultDataAccessException e) { providerID = 0; } return providerID; }
From source file:nl.surfnet.coin.teams.service.impl.TeamExternalGroupDaoImpl.java
@Override public List<TeamExternalGroup> getByTeamIdentifier(String identifier) { Object[] args = { identifier }; try {/*from w w w . j av a 2s .com*/ String s = "SELECT teg.id AS teg_id, teg.grouper_team_id, eg.id AS eg_id, eg.identifier, eg.name, eg.description, eg.group_provider " + " FROM team_external_groups AS teg " + " INNER JOIN external_groups AS eg " + " ON teg.external_groups_id = eg.id " + " WHERE teg.grouper_team_id = ? "; return this.jdbcTemplate.query(s, args, new RowMapper<TeamExternalGroup>() { @Override public TeamExternalGroup mapRow(ResultSet rs, int rowNum) throws SQLException { return mapRowToTeamExternalGroup(rs); } }); } catch (EmptyResultDataAccessException er) { return null; } }
From source file:com.sfs.whichdoctor.dao.EmailDAOImpl.java
/** * Used to get an Collection of EmailBean objects for a * specified GUID number.//from w w w . ja v a2 s.c o m * * @param guid the guid * @param allAddresses the all addresses * @param emailClass the email class * @param emailType the email type * @return the collection * @throws WhichDoctorDaoException the which doctor dao exception */ @SuppressWarnings("unchecked") public final Collection<EmailBean> load(final int guid, final boolean allAddresses, final String emailClass, final String emailType) throws WhichDoctorDaoException { dataLogger.info("Email Addresses for GUID: " + guid + " requested"); // Do check whether required results are light (only primary) // or full(all email addresses) boolean specificAddress = false; String sql = getSQL().getValue("email/load") + " WHERE email.ReferenceGUID = ? AND email.Active = true"; Collection<Object> variables = new ArrayList<Object>(); /* The GUID value is the first variable */ variables.add(guid); if (emailClass != null) { if (emailClass.compareTo("") != 0 && emailClass.compareTo("Preferred") != 0) { sql += " AND emailtype.Class = ?"; variables.add(emailClass); specificAddress = true; } } if (emailType != null) { if (emailType.compareTo("") != 0 && emailType.compareTo("Preferred") != 0) { sql += " AND emailtype.Name = ?"; variables.add(emailType); specificAddress = true; } } sql += " ORDER BY PrimaryEmail DESC"; if (!allAddresses) { sql += " LIMIT 1"; } Collection<EmailBean> emailAddresses = new ArrayList<EmailBean>(); try { emailAddresses = this.getJdbcTemplateReader().query(sql, variables.toArray(), new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return loadEmail(rs); } }); } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results found for search: " + ie.getMessage()); } if (specificAddress && emailAddresses.size() == 0) { /** * Specific email type defined but no result found * Try getting a more generic email address */ if (emailType != null) { if (emailType.compareTo("") != 0) { emailAddresses = load(guid, allAddresses, emailClass, null); } } if (emailAddresses.size() == 0) { if (emailClass != null) { if (emailClass.compareTo("") != 0) { emailAddresses = load(guid, allAddresses, null, null); } } } } return emailAddresses; }
From source file:com.sfs.whichdoctor.dao.AddressVerificationDAOImpl.java
/** * Load the address verification bean based on the address guid. * * @param guid the guid//from w w w .jav a 2 s . c o m * @return the address verification bean * @throws WhichDoctorDaoException the which doctor dao exception */ @SuppressWarnings("unchecked") public final AddressVerificationBean load(final int addressVerificationId) throws WhichDoctorDaoException { AddressVerificationBean addressVerification = null; String loadGUID = this.getSQL().getValue("addressVerification/loadId"); try { addressVerification = (AddressVerificationBean) this.getJdbcTemplateReader().queryForObject(loadGUID, new Object[] { addressVerificationId }, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return loadAddressVerification(rs); } }); } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("Could not find an address verification record for " + " the AddressVerificationId " + addressVerificationId + ": " + ie.getMessage()); } return addressVerification; }
From source file:sample.contact.dao.impl.MenuDaoImpl.java
public Menu getById(Long id) { List<Menu> list = getJdbcTemplate().query( "select id, menu_name, menu_path from menus where id = ? order by id", new RowMapper<Menu>() { public Menu mapRow(ResultSet rs, int rowNum) throws SQLException { return mapMenu(rs); }/*from w w w . ja v a 2 s. co m*/ }, id); if (list.size() == 0) { return null; } else { return (Menu) list.get(0); } }
From source file:com.sfs.dao.FieldMapDAOImpl.java
/** * Load a FieldMapBean object based on the supplied fieldMapId value. * * @param fieldMapId the field map id// w ww. j a v a 2s.c o m * * @return the field map bean * * @throws SFSDaoException the SFS dao exception */ public final FieldMapBean load(final int fieldMapId) throws SFSDaoException { if (fieldMapId == 0) { throw new SFSDaoException("FieldMapId value cannot be 0"); } FieldMapBean fieldMap = null; try { fieldMap = (FieldMapBean) this.getJdbcTemplateReader().queryForObject( this.getSQL().getValue("fieldMap/loadId"), new Object[] { fieldMapId }, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return loadFieldMap(rs); } }); } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results found for this search: " + ie.getMessage()); } return fieldMap; }
From source file:com.sfs.dao.ObjectTypeDAOImpl.java
/** * Load an ObjectTypeBean for the supplied id. * * @param objectTypeId the object type id * * @return the object type bean/*from w ww .j a va 2s.co m*/ * * @throws SFSDaoException the SFS dao exception */ @SuppressWarnings("unchecked") public final ObjectTypeBean load(final int objectTypeId) throws SFSDaoException { if (objectTypeId == 0) { throw new SFSDaoException("ObjectTypeId value cannot be 0"); } ObjectTypeBean objectType = null; try { objectType = (ObjectTypeBean) this.getJdbcTemplateReader().queryForObject( this.getSQL().getValue("objectType/loadId"), new Object[] { objectTypeId }, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return loadObject(rs); } }); } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results found for this search: " + ie.getMessage()); } return objectType; }
From source file:in.sc.dao.ListGenerator.java
public List getListsDetails(int featureId, int cat_id) { StringBuilder sql = new StringBuilder(); List catList = null;//from w w w .j a v a2s . c om try { sql.append(" SELECT * FROM cat_lists WHERE 1=1 "); if (featureId > 0) { sql.append(" and cl_ID=" + featureId); } if (cat_id > 0) { sql.append(" and cat_ID=" + cat_id); } namedParameterJdbcTemplate = getTemplate(); catList = namedParameterJdbcTemplate.query(sql.toString(), new HashMap(), new RowMapper<ProductBean>() { @Override public ProductBean mapRow(ResultSet rs, int i) throws SQLException { ProductBean pBean = new ProductBean(); pBean.setUrl(rs.getString("list_url")); pBean.setProductName(rs.getString("list_name")); pBean.setPdesc(rs.getString("list_desc")); pBean.setCategoryid(rs.getInt("cat_id")); pBean.setProductId(rs.getInt("cl_id")); HashMap filterMap = new HashMap(); if (rs.getInt("cat_id") > 0) { filterMap.put(ProductHelper.category, rs.getInt("cat_id")); } if (rs.getInt("min_price") > 0) { filterMap.put(ProductHelper.minprice, rs.getInt("min_price")); } if (rs.getInt("max_price") > 0) { filterMap.put(maxprice, rs.getInt("max_price")); } if (rs.getString("brand_ids") != null) { filterMap.put(brand, rs.getString("brand_ids")); } if (rs.getString("whereclause") != null) { filterMap.put(ProductHelper.whereclause, rs.getString("whereclause")); } if (rs.getString("orderclause") != null) { filterMap.put(ProductHelper.orderclause, rs.getString("orderclause")); } pBean.setFilterMap(filterMap); return pBean; } }); } catch (Exception e) { e.printStackTrace(); } finally { } return catList; }
From source file:com.springsource.greenhouse.invite.JdbcInviteRepository.java
private Invite queryForInvite(String token) throws NoSuchInviteException { try {//w w w.java 2 s . c o m return jdbcTemplate.queryForObject(SELECT_INVITE, new RowMapper<Invite>() { public Invite mapRow(ResultSet rs, int rowNum) throws SQLException { Invitee invitee = new Invitee(rs.getString("firstName"), rs.getString("lastName"), rs.getString("email")); ProfileReference sentBy = ProfileReference.textOnly(rs.getLong("sentById"), rs.getString("sentByUsername"), rs.getString("sentByFirstName"), rs.getString("sentByLastName")); return new Invite(invitee, sentBy, rs.getBoolean("accepted")); } }, token, token); } catch (EmptyResultDataAccessException e) { throw new NoSuchInviteException(token); } }