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.overhead.markeugie.manager; import com.overhead.markeugie.entity.AttendanceLog; import com.overhead.markeugie.entity.Participants; import com.overhead.markeugie.services.AttendanceLogService; import com.overhead.markeugie.util.RegistrationHibernateUtil; import java.rmi.RemoteException; import java.rmi.server.UnicastRemoteObject; import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Session; import org.hibernate.criterion.Restrictions; /** * * @author markeugie */ public class AttendanceLogManager extends UnicastRemoteObject implements AttendanceLogService { public AttendanceLogManager() throws RemoteException { } private static AttendanceLogManager instance; public static AttendanceLogManager getInstance() throws RemoteException { if (instance == null) { instance = new AttendanceLogManager(); } return instance; } @Override public AttendanceLog getLogByParticipant(Participants participant, Date date) throws RemoteException { Session session = RegistrationHibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); Criteria criteria = session.createCriteria(AttendanceLog.class); criteria.add(Restrictions.eq("date", date)); criteria.add(Restrictions.eq("participant", participant)); criteria.setMaxResults(1); AttendanceLog participantLog = (AttendanceLog) criteria.uniqueResult(); session.getTransaction().commit(); session.close(); return participantLog; } @Override public AttendanceLog addLogByParticipant(AttendanceLog participantLog) throws RemoteException { Session session = RegistrationHibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); session.save(participantLog); session.getTransaction().commit(); session.close(); return participantLog; } @Override public AttendanceLog updateLogByParticipant(AttendanceLog participantLog) throws RemoteException { Session session = RegistrationHibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); session.update(participantLog); session.getTransaction().commit(); session.close(); return participantLog; } @Override public List<AttendanceLog> getLateLogByParticipant(Participants participant) throws RemoteException { Session session = RegistrationHibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); Criteria criteria = session.createCriteria(AttendanceLog.class); criteria.add(Restrictions.eq("participant", participant)); List<AttendanceLog> attendanceLogs = (List<AttendanceLog>) criteria.list(); session.getTransaction().commit(); session.close(); return attendanceLogs; } @Override public List<AttendanceLog> getAttendanceLogByStudent(String id) throws RemoteException { Session session = RegistrationHibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); Criteria criteria = session.createCriteria(AttendanceLog.class); criteria.add(Restrictions.eq("participant.id", id)); List<AttendanceLog> attendanceLogs = (List<AttendanceLog>) criteria.list(); session.getTransaction().commit(); session.close(); return attendanceLogs; } }