@Override public void storeRiskData(RiskData riskData) { RiskDataEntity riskDataEntity = new RiskDataEntity(); riskDataEntity.setId(riskData.getId()); riskDataEntity.setTarget(riskData.getTarget()); riskDataEntity.setType(riskData.getType()); riskDataEntity.setDate(new Date()); riskDataEntity.setValue(riskData.getValue()); hibernateStore(riskDataEntity); }
@Override public List<RiskData> getRiskData(String target, String id, int offset, int limit) { org.hibernate.Session hibernateSession = hibernateSessionProvider.getSession(); hibernateSession.beginTransaction(); try { Query query = hibernateSession.createQuery( "FROM RiskDataEntity AS RDE WHERE RDE.id = :id AND RDE.target = :target ORDER BY RDE.date DESC"); query.setParameter("id", id); query.setParameter("target", target); query.setFirstResult(offset); query.setMaxResults(limit); List<RiskDataEntity> riskDataEntities = query.list(); List<RiskData> result = new ArrayList<RiskData>(); for (RiskDataEntity riskDataEntity : riskDataEntities) { RiskData riskData = RiskDataFactory.createRiskData( riskDataEntity.getId(), riskDataEntity.getTarget(), riskDataEntity.getDate(), riskDataEntity.getType(), riskDataEntity.getValue()); result.add(riskData); } return result; } catch (Exception e) { logger.error("Unable to get risk data", e); hibernateSession.getTransaction().rollback(); } finally { hibernateSession.getTransaction().commit(); } return Collections.EMPTY_LIST; }