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.RepairDao; import com.qfix.vms.model.Driver; import com.qfix.vms.model.PaymentMonth; import com.qfix.vms.model.Repair; 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.Criterion; import org.hibernate.criterion.Order; import org.hibernate.criterion.Projections; import org.hibernate.criterion.Restrictions; import org.hibernate.transform.Transformers; import org.springframework.stereotype.Repository; /** * * @author Ruwani Jayarathna */ @Repository("repairDao") public class RepairDaoImpl extends AbstractDao<Serializable, Repair> implements RepairDao { @SuppressWarnings("unchecked") MonthlyPaymentsDaoImpl monthlyPaymentsDaoImpl; @Override public void saveRepair(Repair repair) { /* Session session = sessionFactory.openSession(); Transaction tx = null; tx = session.beginTransaction(); Criteria cr = session.createCriteria(Repair.class); // To get total salary. cr.setProjection(Projections.sum("repairCost")); List totalSalary = cr.list(); repair.setRepairCost((double) totalSalary.get(0)); */ persist(repair); } @Override public List<Repair> findAllRepairs() { Criteria criteria = createEntityCriteria(); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); List<Repair> repairs = (List<Repair>) criteria.list(); return repairs; } @Override public List<Repair> findRepairs(Date frome, Date to) { Session session = sessionFactory.openSession(); Transaction tx = null; tx = session.beginTransaction(); Criteria cr = session.createCriteria(Repair.class); cr.add(Restrictions.between("date", frome, to)); List repairs = cr.list(); return repairs; } @Override public int getsum(Date from, Date to) { Session session = sessionFactory.openSession(); Transaction tx = null; tx = session.beginTransaction(); Criteria cr = session.createCriteria(Repair.class); cr.add(Restrictions.between("date", from, to)); cr.setProjection(Projections.sum("repairCost")); int repairs = cr.hashCode(); return repairs; } @Override public List<Repair> vehicleReport(Date from, Date to) { Session session = sessionFactory.openSession(); Transaction tx = null; tx = session.beginTransaction(); Criteria cr = session.createCriteria(Repair.class); cr.add(Restrictions.between("date", from, to)); List repairs = cr.list(); return repairs; } }