List of usage examples for org.springframework.jdbc.core RowMapper RowMapper
RowMapper
From source file:me.ronghai.sa.model.ModelMeta.java
public RowMapper<T> getRowMapper() { if (this.rowMapper == null) { this.rowMapper = new RowMapper<T>() { @Override//from w w w.j a v a 2 s . com public T mapRow(ResultSet rs, int rowNum) throws SQLException { T bean = null; try { bean = clazz.newInstance(); for (Map.Entry<String, Field> entry : columnFields.entrySet()) { String cname = entry.getKey().replaceAll("`", ""); Method setter = field2Setter.get(entry.getValue().getName()); Class<?> t = ReflectUtils.findPropertyType(entry.getValue(), setter); ReflectUtils.updateFieldValue(bean, entry.getValue(), setter, get(rs, cname, t)); } } catch (InvocationTargetException | IllegalArgumentException | InstantiationException | IllegalAccessException ex) { Logger.getLogger(CarrierDAOImpl.class.getName()).log(Level.SEVERE, null, ex); } return bean; } }; } return this.rowMapper; }
From source file:org.onesun.atomator.dao.SubscriptionDAOImpl.java
@SuppressWarnings("unchecked") @Override/*from w w w .j a va 2 s.c o m*/ public List<SubscriptionEntry> get(String whereClause, Object[] object) { /** * Implement the RowMapper callback interface */ try { String query = "SELECT * from " + SUBSCRIPTION_TABLE + whereClause; return Configuration.getJdbcTemplate().query(query, object, new RowMapper() { public Object mapRow(ResultSet resultSet, int rowNum) throws SQLException { return toSubscriptionEntry(resultSet); } }); } catch (EmptyResultDataAccessException e) { return null; } }
From source file:eionet.meta.dao.mysql.VocabularyFolderDAOImpl.java
@Override public List<VocabularyFolder> getReleasedVocabularyFolders(int folderId) { List<String> statuses = new ArrayList<String>(); statuses.add(RegStatus.RELEASED.toString()); statuses.add(RegStatus.PUBLIC_DRAFT.toString()); Map<String, Object> params = new HashMap<String, Object>(); params.put("folderId", folderId); params.put("statuses", statuses); StringBuilder sql = new StringBuilder(); sql.append(//from w w w .ja va 2 s . c om "select v.VOCABULARY_ID, v.IDENTIFIER, v.LABEL, v.REG_STATUS, v.WORKING_COPY, v.BASE_URI, v.VOCABULARY_TYPE, "); sql.append("v.WORKING_USER, v.DATE_MODIFIED, v.USER_MODIFIED, v.CHECKEDOUT_COPY_ID, v.CONTINUITY_ID, "); sql.append("v.CONCEPT_IDENTIFIER_NUMERIC, "); sql.append("f.ID, f.IDENTIFIER, f.LABEL, v.NOTATIONS_EQUAL_IDENTIFIERS "); sql.append("from VOCABULARY v "); sql.append("left join VOCABULARY_SET f on f.ID=v.FOLDER_ID "); sql.append("where v.WORKING_COPY=FALSE and v.FOLDER_ID=:folderId and v.REG_STATUS in (:statuses) "); sql.append("order by f.IDENTIFIER, v.IDENTIFIER "); List<VocabularyFolder> items = getNamedParameterJdbcTemplate().query(sql.toString(), params, new RowMapper<VocabularyFolder>() { @Override public VocabularyFolder mapRow(ResultSet rs, int rowNum) throws SQLException { VocabularyFolder vf = new VocabularyFolder(); vf.setId(rs.getInt("v.VOCABULARY_ID")); vf.setIdentifier(rs.getString("v.IDENTIFIER")); vf.setLabel(rs.getString("v.LABEL")); vf.setRegStatus(RegStatus.fromString(rs.getString("v.REG_STATUS"))); vf.setType(VocabularyType.valueOf(rs.getString("v.VOCABULARY_TYPE"))); vf.setWorkingCopy(rs.getBoolean("v.WORKING_COPY")); vf.setWorkingUser(rs.getString("v.WORKING_USER")); vf.setDateModified(rs.getTimestamp("v.DATE_MODIFIED")); vf.setUserModified(rs.getString("v.USER_MODIFIED")); vf.setCheckedOutCopyId(rs.getInt("v.CHECKEDOUT_COPY_ID")); vf.setContinuityId(rs.getString("v.CONTINUITY_ID")); vf.setNumericConceptIdentifiers(rs.getBoolean("v.CONCEPT_IDENTIFIER_NUMERIC")); vf.setNotationsEqualIdentifiers(rs.getBoolean("NOTATIONS_EQUAL_IDENTIFIERS")); vf.setBaseUri(rs.getString("v.BASE_URI")); vf.setFolderId(rs.getShort("f.ID")); vf.setFolderName(rs.getString("f.IDENTIFIER")); vf.setFolderLabel(rs.getString("f.LABEL")); return vf; } }); return items; }
From source file:eu.europa.ec.markt.dss.validation.crl.JdbcCacheCRLSource.java
@Override public X509CRL findCrl(X509Certificate certificate, X509Certificate issuerCertificate) throws IOException { OnlineCRLSource source = new OnlineCRLSource(); String crlUrl = source.getCrlUri(certificate); if (crlUrl != null) { try {/*w w w . ja va 2s.co m*/ MessageDigest digest = MessageDigest.getInstance(DigestAlgorithm.SHA1.getName()); String key = Hex.encodeHexString(digest.digest(crlUrl.getBytes())); List<CachedCRL> crls = getJdbcTemplate().query("SELECT * FROM CACHED_CRL WHERE ID = ?", new Object[] { key }, new RowMapper<CachedCRL>() { @Override public CachedCRL mapRow(ResultSet rs, int rowNum) throws SQLException { CachedCRL cached = new CachedCRL(); cached.setKey(rs.getString("ID")); cached.setCrl(rs.getBytes("DATA")); return cached; } }); if (crls.size() == 0) { LOG.info("CRL not in cache"); X509CRL originalCRL = cachedSource.findCrl(certificate, issuerCertificate); if (originalCRL != null) { getJdbcTemplate().update("INSERT INTO CACHED_CRL (ID, DATA) VALUES (?,?) ", key, originalCRL.getEncoded()); return originalCRL; } else { return null; } } CachedCRL crl = crls.get(0); CertificateFactory factory = CertificateFactory.getInstance("X509"); X509CRL x509crl = (X509CRL) factory.generateCRL(new ByteArrayInputStream(crl.getCrl())); if (x509crl.getNextUpdate().after(new Date())) { LOG.fine("CRL in cache"); return x509crl; } else { LOG.info("CRL expired"); X509CRL originalCRL = cachedSource.findCrl(certificate, issuerCertificate); getJdbcTemplate().update("UPDATE CACHED_CRL SET DATA = ? WHERE ID = ? ", originalCRL.getEncoded(), key); return originalCRL; } } catch (NoSuchAlgorithmException e) { LOG.info("Cannot instantiate digest for algorithm SHA1 !?"); } catch (CRLException e) { LOG.info("Cannot serialize CRL"); } catch (CertificateException e) { LOG.info("Cannot instanciate X509 Factory"); } } return null; }
From source file:shell.framework.organization.role.service.impl.TblSysRoleService4JdbcImpl.java
public TblSysRole findRoleByID(Serializable id) { String sql = "select * from TBL_SYS_ROLE role where role.ID = ?"; List<?> resultList = jdbcBaseDao.query(sql, new Object[] { id }, new RowMapper<Object>() { /* (non-Javadoc) * @see org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet, int) *//*from w w w . j a v a 2 s. c om*/ public Object mapRow(ResultSet rs, int rowNum) throws SQLException { TblSysRole sysRole = new TblSysRole(); Map<String, String> propertyMap = new HashMap<String, String>(); propertyMap.put("isValid", "IS_VALID"); propertyMap.put("isVirtual", "IS_VIRTUAL"); PopulateUtil.populate(sysRole, rs, propertyMap); return sysRole; } }); if (resultList == null || resultList.size() == 0) { throw new RuntimeException("NO DATA FROM DATABASE!"); } return (TblSysRole) resultList.get(0); }
From source file:com.sfs.whichdoctor.dao.SpecialtyDAOImpl.java
/** * Used to get an ArrayList of SpecialtyBeans for a specified GUID. * * @param guid the guid//from w w w. j av a 2 s. co m * @param fullResults the full results * @return the collection * @throws WhichDoctorDaoException the which doctor dao exception */ @SuppressWarnings("unchecked") public final Collection<SpecialtyBean> load(final int guid, final boolean fullResults) throws WhichDoctorDaoException { dataLogger.info("Specialties for GUID: " + guid + " requested"); final String loadSpecialties = getSQL().getValue("specialty/load") + " WHERE specialty.Active = true AND specialty.ReferenceGUID = ?" + " ORDER BY trainingprogram.Class, trainingprogram.Name, guid.CreatedDate"; Collection<SpecialtyBean> specialties = new ArrayList<SpecialtyBean>(); try { specialties = this.getJdbcTemplateReader().query(loadSpecialties, new Object[] { guid }, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return loadSpecialty(rs); } }); } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results found for this search: " + ie.getMessage()); } return specialties; }
From source file:com.denksoft.springstarter.util.security.PostgresqlJdbcAclService.java
public ObjectIdentity[] findChildren(ObjectIdentity parentIdentity) { Object[] args = { parentIdentity.getIdentifier(), parentIdentity.getJavaType().getName() }; List objects = jdbcTemplate.query(selectAclObjectWithParent, args, new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { String javaType = rs.getString("class"); String identifier = rs.getString("obj_id"); return new ObjectIdentityImpl(javaType, identifier); }//from ww w. java 2 s.co m }); return (ObjectIdentityImpl[]) objects.toArray(new ObjectIdentityImpl[] {}); }
From source file:CRM.repository.InteractionsDAO.java
public List<interactions> getInteractionsByPage(int start, int total) { String sql = "SELECT interactions.interaction_id, interactions.client_id, interactions.contact_date, interactions.first_name, interactions.last_name, interactions.notes, interactions.email, interactions.phone, clients.client_id " + "FROM Interactions AS interactions " + "INNER JOIN clients AS clients ON clients.client_id = interactions.client_id " + "ORDER BY interactions.contact_date " + "LIMIT " + (start - 1) + "," + total; return template.query(sql, new RowMapper<interactions>() { public interactions mapRow(ResultSet rs, int row) throws SQLException { interactions i = new interactions(); i.setInteraction_id(rs.getInt("interaction_id")); i.setFirst_name(rs.getString("first_name")); i.setLast_name(rs.getString("last_name")); //i.setStatus(rs.getString("status")); //i.setMethod_of_contact(rs.getString("method_of_contact")); i.setEmail(rs.getString("email")); i.setPhone(rs.getString("phone")); i.setNotes(rs.getString("notes")); i.setContact_date(rs.getString("contact_date")); i.setClient_id(rs.getInt("client_id")); clients clients = new clients(); clients.setClient_id(rs.getInt("client_id")); clients.setLast_name(rs.getString("last_name")); clients.setFirst_name(rs.getString("first_name")); i.setClients(clients);// w ww . jav a 2 s. c o m return i; } }); }
From source file:eu.trentorise.smartcampus.resourceprovider.jdbc.JdbcServices.java
@Override public User loadUserByUserId(String userId) { return queryForObject(selectUserSql, new RowMapper<User>() { @Override// w ww .jav a2s . c o m public User mapRow(ResultSet rs, int rowNum) throws SQLException { User user = new User(); user.setId("" + rs.getLong("id")); user.setName(rs.getString("name")); user.setSurname(rs.getString("surname")); user.setSocialId(rs.getString("social_id")); return user; } }, Long.parseLong(userId)); }
From source file:architecture.ee.web.community.timeline.dao.jdbc.JdbcTimelineDao.java
public List<Long> getTimelineIds(int objectType, long objectId) { return getExtendedJdbcTemplate().query(getBoundSql( "ARCHITECTURE_COMMUNITY.SELECT_TIMELINE_IDS_BY_OBJECT_TYPE_AND_OBJECT_ID_WITH_DATE_DESC").getSql(), new RowMapper<Long>() { public Long mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getLong(1); }/*from w w w . j a v a 2 s . c om*/ }, new SqlParameterValue(Types.NUMERIC, objectType), new SqlParameterValue(Types.NUMERIC, objectId)); }