package com.gitrekt.resort.model.services;

import com.gitrekt.resort.hibernate.HibernateUtil;
import com.gitrekt.resort.model.entities.Guest;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityNotFoundException;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceException;
import javax.persistence.Query;

public class GuestService {

    @PersistenceContext
    private final EntityManager entityManager;

    public GuestService() {
        this.entityManager = HibernateUtil.getEntityManager();
    }

    @Override
    public void finalize() throws Throwable {
        super.finalize();
        this.entityManager.close();
    }

    public List<Guest> getCurrentlyCheckedInGuests() {
        return null;
    }

    public Guest getGuestById(Long id) throws EntityNotFoundException {
        try {
            Guest guest = entityManager.getReference(Guest.class,id);
            return  guest;
        } catch (EntityNotFoundException e) {
            System.out.println("entity not found");
            return null;
        }
    }

    public Guest getGuestByEmailAddress(String emailAddress) 
        throws EntityNotFoundException {
        String query = "FROM Guest WHERE emailAddress = :emailAddress";
        Query q = entityManager.createQuery(query);
        q.setParameter("emailAddress", emailAddress);
        return (Guest) q.getSingleResult();
    }

    public void createNewGuest(Guest guest) {
        try {
            entityManager.getTransaction().begin();
            entityManager.persist(guest);
            entityManager.getTransaction().commit();
        } catch (PersistenceException e) {
            entityManager.getTransaction().rollback();
            // TODO: Log rollback or notify user somewhere, possibly in e.
            throw e;
        }
    }

    public void updateGuest(Guest guest) {
        // TODO
    }
}

@@ -761,35 +761,203 @@
 ) %7B%0A        
-return null
+String query = %22FROM Guest WHERE isCheckedIn = :param%22;%0A        Query q = entityManager.createQuery(query);%0A        q.setParameter(%22param%22, true);%0A        return q.getResultList()
 ;%0A    %7D%0A%0A   
@@ -1025,34 +1025,16 @@
 ption %7B%0A
-        try %7B%0A    
         
@@ -1095,28 +1095,24 @@
 d);%0A        
-    
 return  gues
@@ -1118,141 +1118,8 @@
 st;%0A
-        %7D catch (EntityNotFoundException e) %7B%0A            System.out.println(%22entity not found%22);%0A            return null;%0A        %7D%0A
     

Fix merge conflict