package cn.updev.Events.Event;

import cn.updev.Database.HibernateSessionFactory;
import cn.updev.Events.Static.IEvent;
import org.hibernate.Session;

import java.util.List;

/**
 * Created by hypo on 15-9-30.
 */
public class EventDAO {

    private Session session;

    public EventDAO() {

        this.session = HibernateSessionFactory.currentSession();
    }

    public IEvent getEventById(Integer eventId){

        return null;
    }

    public List<IEvent> getEventByUserId(Integer userId){

        return null;
    }

    public List<IEvent> getEventByEventGroupId(Integer eventGroupId){

        return null;
    }

    public List<IEvent> getEventByUserGroupId(Integer userGroupId){

        return null;
    }

    protected void finalize(){
        HibernateSessionFactory.closeSession();
    }
}

@@ -138,17 +138,68 @@
 ate.
-Session;%0A
+Query;%0Aimport org.hibernate.Session;%0A%0Aimport java.util.Date;
 %0Aimp
@@ -441,23 +441,105 @@
 entById(
-Integer
+Long eventId)%7B%0A        Query query =session.createQuery(%22from Event e where e.eventId=%22 +
  eventId
@@ -539,17 +539,17 @@
 eventId)
-%7B
+;
 %0A%0A      
@@ -554,303 +554,1012 @@
     
-return null;%0A    %7D%0A%0A    public List%3CIEvent%3E getEventByUserId(Integer userId)%7B%0A%0A        return null;%0A    %7D%0A%0A    public List%3CIEvent%3E getEventByEventGroupId(Integer eventGroupId)%7B%0A%0A        return null;%0A    %7D%0A%0A    public List%3CIEvent%3E getEventByUserGroupId(Integer userGroupId)%7B%0A%0A        return null;
+if(query.list().size() == 0)%7B%0A            return null;%0A        %7D%0A        IEvent rnt = (IEvent) query.list().get(0);%0A        return rnt;%0A    %7D%0A%0A    public List%3CIEvent%3E getEventByUserId(Integer userId)%7B%0A%0A        Query query =session.createQuery(%22from Event e where e.doerId=%22 + userId);%0A%0A        return (List%3CIEvent%3E) query.list();%0A    %7D%0A%0A    public List%3CIEvent%3E getEventByEventGroupId(Integer eventGroupId)%7B%0A%0A        Query query =session.createQuery(%22from Event e where e.groupId=%22 + eventGroupId);%0A%0A        return (List%3CIEvent%3E) query.list();%0A    %7D%0A%0A    public List%3CIEvent%3E getEventByUserGroupId(Integer userGroupId)%7B%0A%0A        return null;%0A    %7D%0A%0A    public Boolean eventFinish(Long eventId)%7B%0A%0A        IEvent event = getEventById(eventId);%0A        if(event.isFinish())%7B%0A            event.setFinishTime(new Date());%0A%0A            session.update(event);%0A%0A            return true;%0A        %7Delse %7B%0A            event.setFinishTime(null);%0A%0A            session.update(event);%0A%0A            return false;%0A        %7D
 %0A   

update EventDAO