Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.qfix.vms.dao.impl; import com.qfix.vms.dao.AbstractDao; import com.qfix.vms.dao.SurvicingDao; import com.qfix.vms.model.Survicing; import java.io.Serializable; import java.security.NoSuchAlgorithmException; import java.sql.Date; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Hibernate; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.criterion.Order; import org.hibernate.criterion.Restrictions; import org.springframework.stereotype.Repository; /** * * @author Tishan Madhawa */ @Repository("survicingDao") public class SurvicingDaoImpl extends AbstractDao<Serializable, Survicing> implements SurvicingDao { @SuppressWarnings("unchecked") @Override public void saveSurvicing(Survicing survicing) { persist(survicing); } @Override public List<Survicing> findAllSurvicings() { Criteria criteria = createEntityCriteria(); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); List<Survicing> survicings = (List<Survicing>) criteria.list(); return survicings; } @Override public List<Survicing> findSurvicings(Date from, Date to) { Session session = sessionFactory.openSession(); Transaction tx = null; tx = session.beginTransaction(); Criteria cr = session.createCriteria(Survicing.class); cr.add(Restrictions.between("date", from, to)); List survicings = cr.list(); return survicings; } @Override public List<Survicing> vehicleReport(Date from, Date to) { Session session = sessionFactory.openSession(); Transaction tx = null; tx = session.beginTransaction(); Criteria cr = session.createCriteria(Survicing.class); cr.add(Restrictions.between("date", from, to)); List survicings = cr.list(); return survicings; } }