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.AnnualLicenseDao; import com.qfix.vms.model.AnnualLicense; 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 Ruwani Jayarathna */ @Repository("annualLicenseDao") public class AnnualLicenseDaoImpl extends AbstractDao<Serializable, AnnualLicense> implements AnnualLicenseDao { @SuppressWarnings("unchecked") @Override public void saveAnnualLicense(AnnualLicense annualLicense) { persist(annualLicense); } @Override public List<AnnualLicense> findAllAnnualLicenses() { Criteria criteria = createEntityCriteria(); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); List<AnnualLicense> annualLicenses = (List<AnnualLicense>) criteria.list(); return annualLicenses; } @Override public List<AnnualLicense> findAnnualLicenses(Date from, Date to) { Session session = sessionFactory.openSession(); Transaction tx = null; tx = session.beginTransaction(); Criteria cr = session.createCriteria(AnnualLicense.class); cr.add(Restrictions.between("date", from, to)); List annualLicenses = cr.list(); return annualLicenses; } @Override public List<AnnualLicense> vehicleReport(Date from, Date to) { Session session = sessionFactory.openSession(); Transaction tx = null; tx = session.beginTransaction(); Criteria cr = session.createCriteria(AnnualLicense.class); cr.add(Restrictions.between("date", from, to)); List annualLicenses = cr.list(); return annualLicenses; } }