List of usage examples for org.springframework.jdbc.core RowMapper RowMapper
RowMapper
From source file:com.jaxio.celerio.configuration.database.h2.H2Extension.java
@Override public void apply(Connection connection, Metadata metadata) { JdbcTemplate jdbcTemplate = getJdbcTemplate(connection); String schemaName = getSchemaName(metadata); List<Constraint> constraints = jdbcTemplate.query( "SELECT table_name, column_name, check_constraint FROM information_schema.columns WHERE table_schema = ? AND LENGTH(check_constraint) > 0", new Object[] { schemaName }, new RowMapper<Constraint>() { @Override/*from ww w.j a v a2 s . c o m*/ public Constraint mapRow(ResultSet rs, int rowNum) throws SQLException { Constraint constraint = new Constraint(); constraint.setTableName(rs.getString("table_name")); constraint.setColumnName(rs.getString("column_name")); constraint.setConstraint(rs.getString("check_constraint")); return constraint; } }); for (Constraint constraint : constraints) { addEnumValue(metadata, constraint.getTableName(), constraint.getColumnName(), constraint.getConstraint()); } }
From source file:org.xeneo.db.security.JdbcUserManager.java
private List<JdbcUser> loadUsersByUsername(String userURI) { return jdbcTemplate.query(GET_USER_BY_USERURI, new String[] { userURI }, new RowMapper<JdbcUser>() { public JdbcUser mapRow(ResultSet rs, int rowNum) throws SQLException { String password = rs.getString("Password"); String email = rs.getString("Email"); String firstName = rs.getString("FirstName"); String lastName = rs.getString("LastName"); String userURI = rs.getString("UserURI"); return new JdbcUser(userURI, firstName, lastName, email, password); }/* w w w . j a v a 2s . co m*/ }); }
From source file:ru.org.linux.gallery.ImageDao.java
/** * ? ./*from w ww . j a v a 2 s . c om*/ * * @return ?? GalleryDto */ public List<GalleryItem> getGalleryItems(int countItems) { final Section gallery = sectionService.getSection(Section.SECTION_GALLERY); String sql = "SELECT topics.id as msgid, " + " topics.stat1, topics.title, images.icon, images.original, userid, urlname, images.id as imageid " + "FROM topics " + " JOIN groups ON topics.groupid = groups.id " + " JOIN images ON topics.id = images.topic " + " WHERE topics.moderate AND section=" + Section.SECTION_GALLERY + " AND NOT topics.deleted AND commitdate is not null ORDER BY commitdate DESC LIMIT ?"; return jdbcTemplate.query(sql, new RowMapper<GalleryItem>() { @Override public GalleryItem mapRow(ResultSet rs, int rowNum) throws SQLException { GalleryItem item = new GalleryItem(); item.setMsgid(rs.getInt("msgid")); item.setStat(rs.getInt("stat1")); item.setTitle(rs.getString("title")); Image image = new Image(rs.getInt("imageid"), rs.getInt("msgid"), rs.getString("original"), rs.getString("icon")); item.setImage(image); item.setUserid(rs.getInt("userid")); item.setStat(rs.getInt("stat1")); item.setLink(gallery.getSectionLink() + rs.getString("urlname") + '/' + rs.getInt("msgid")); return item; } }, countItems); }
From source file:com.sfs.whichdoctor.dao.PhoneDAOImpl.java
/** * Used to get a Collection of PhoneBeans for a specified GUID. * * @param guid the guid//from www . ja v a 2 s .co m * @param allPhoneNumbers the all phone numbers * @return the collection * @throws WhichDoctorDaoException the which doctor dao exception */ @SuppressWarnings("unchecked") public final Collection<PhoneBean> load(final int guid, final boolean allPhoneNumbers) throws WhichDoctorDaoException { dataLogger.info("Phone numbers for GUID: " + guid + " requested"); // Do check whether required results are light // (only primary) or full (all phone numbers) String loadPhone = this.getSQL().getValue("phone/load") + " WHERE phone.Active = true AND phone.ReferenceGUID = ?"; if (!allPhoneNumbers) { loadPhone += " AND PrimaryPhone = true ORDER BY PrimaryPhone DESC"; } else { loadPhone += " ORDER BY PrimaryPhone DESC"; } Collection<PhoneBean> phoneNumbers = new ArrayList<PhoneBean>(); try { phoneNumbers = this.getJdbcTemplateReader().query(loadPhone, new Object[] { guid }, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return loadPhone(rs); } }); } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results found for this search: " + ie.getMessage()); } return phoneNumbers; }
From source file:db.migration.V023__UpdateOrganisationToimipisteKoodi.java
public void migrate(JdbcTemplate jdbcTemplate) throws Exception { LOG.info("migrate()..."); // Get all organisations List<Map> resultSet = jdbcTemplate.query("SELECT * FROM organisaatio o", new RowMapper<Map>() { @Override/*from ww w .jav a 2s . c o m*/ public Map mapRow(ResultSet rs, int rowNum) throws SQLException { Map r = new HashMap<String, Object>(); ResultSetMetaData metadata = rs.getMetaData(); for (int i = 1; i <= metadata.getColumnCount(); i++) { String cname = metadata.getColumnName(i); int ctype = metadata.getColumnType(i); switch (ctype) { case Types.VARCHAR: r.put(cname, rs.getString(cname)); break; default: break; } } LOG.debug(" read from db : org = {}", r); _organisations.put((String) r.get("oid"), r); return r; } }); // Generate and update initial values for toimipistekoodis for (Map org : resultSet) { if (isToimipiste(org, jdbcTemplate)) { String tpKoodi = calculateToimipisteKoodi(org, jdbcTemplate); updateToimipisteKoodi(org, tpKoodi, jdbcTemplate); } } LOG.info(" Processed {} organisations, updated {} Opetuspistes", _organisations.size(), _numUpdated); LOG.info("migrate()... done."); }
From source file:org.onesun.atomator.dao.HashEntryDAOImpl.java
@SuppressWarnings("unchecked") @Override/* w ww . j av a 2 s . co m*/ public Date get(String user, String hash) { /** * Implement the RowMapper callback interface */ try { String query = "SELECT time_stamp from " + HASH_ENTRY_TABLE + " WHERE hash=? AND user_id=?"; return (Date) Configuration.getJdbcTemplate().query(query, new Object[] { hash, user }, new RowMapper() { public Object mapRow(ResultSet resultSet, int rowNum) throws SQLException { return toDateObject(resultSet); } }); } catch (EmptyResultDataAccessException e) { return null; } }
From source file:bd.gov.forms.dao.ListDaoImpl.java
public List getListDataList() { return jdbcTemplate.query("SELECT * FROM list_data ", new Object[] {}, new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { ListData list = new ListData(); list.setId(rs.getInt("id")); list.setSysId(rs.getString("sys_id")); list.setName(rs.getString("name")); list.setDetail(rs.getString("detail")); return list; }/*from w w w .j ava2 s . c o m*/ }); }
From source file:com.sfs.whichdoctor.dao.IsbPayloadDAOImpl.java
/** * Used to get an IsbPayloadBean for the specified IsbMessageBean Id. * * @param isbMessageId the isb message id * * @return the isb payload bean// ww w . java2 s.c o m * * @throws WhichDoctorDaoException the which doctor dao exception */ public final IsbPayloadBean loadSiblingOf(final int isbMessageId) throws WhichDoctorDaoException { dataLogger.info("ISB payload with a parent id of : " + isbMessageId + " requested"); IsbPayloadBean isbPayload = null; try { isbPayload = (IsbPayloadBean) this.getIsbJdbcTemplate().queryForObject( this.getSQL().getValue("isbpayload/loadParent"), new Object[] { isbMessageId }, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return loadIsbPayloadBean(rs); } }); } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results found for search: " + ie.getMessage()); } return isbPayload; }
From source file:info.naiv.lab.java.tool.sqlite.exporter.component.DataAccess.java
/** * * @param sourceTempl/*from w w w . j a v a2 s . c o m*/ * @param destTempl * @param info * @param valueHandler */ public void copy(final JdbcTemplate sourceTempl, JdbcTemplate destTempl, TableInfo info, final ValueHandler valueHandler) { final Query sq = selectTables.merge(info); Query q = insertSql.merge(info); final List<Field> fields = info.getFields(); q.execute(destTempl, new PreparedStatementCallback<Void>() { @Override public Void doInPreparedStatement(final PreparedStatement ps) throws SQLException, DataAccessException { ps.getConnection().setAutoCommit(false); try { List<Integer> list = sq.query(sourceTempl, new RowMapper<Integer>() { @Override public Integer mapRow(ResultSet rs, int rowNum) throws SQLException { int col = 1; for (Field field : fields) { Object val = valueHandler.handleValue(field, rs); ps.setObject(col, val); } ps.addBatch(); if (rowNum % BATCH_SIZE == 0) { logger.info("execBatch: {}", rowNum); ps.executeBatch(); } return rowNum; } }); int total = list.size(); logger.info("total Batch: {}", total); if (total % BATCH_SIZE != 0) { ps.executeBatch(); } ps.getConnection().commit(); } catch (SQLException | RuntimeException e) { ps.getConnection().rollback(); throw e; } return null; } }); }
From source file:dao.CustomerDAO.java
public void getAddress(int SSN) { String q = "SELECT LastName,FirstName, Address, City, State, ZipCode, Telephone\n" + "FROM person\n" + "WHERE SSN = " + SSN; this.jdbcTemplate.queryForObject(q, new RowMapper<String>() { @Override/* w w w. j a va 2s . c o m*/ public String mapRow(ResultSet rs, int rowNum) throws SQLException { cust.setAddress(rs.getString("Address")); cust.setCity(rs.getString("City")); cust.setLastName(rs.getString("LastName")); cust.setFirstName(rs.getString("FirstName")); cust.setState(rs.getString("State")); cust.setZipcode(rs.getInt("ZipCode")); cust.setTelephone(rs.getString("Telephone")); return ""; } }); }