Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.sakaiproject.component.app.scheduler.events.hibernate;
  
  import  org.hibernate.Criteria;
  import  org.hibernate.Query;
  import  org.hibernate.Session;
  import  org.hibernate.criterion.Order;
  import  org.hibernate.criterion.Projections;
  import  org.hibernate.criterion.Restrictions;
 import  org.springframework.orm.hibernate3.support.HibernateDaoSupport;
 
 import java.util.Date;
 import java.util.List;

Created by IntelliJ IDEA. User: duffy Date: Aug 26, 2010 Time: 5:24:51 PM To change this template use File | Settings | File Templates.
 
     extends HibernateDaoSupport
     implements TriggerEventManager
 {
 
     /* (non-Javadoc)
      * @see org.sakaiproject.api.app.scheduler.events.TriggerEventManager#createTriggerEvent(org.sakaiproject.api.app.scheduler.events.TriggerEvent.TRIGGER_EVENT_TYPE, java.lang.String, java.lang.String, java.util.Date, java.lang.String)
      */
     public TriggerEvent createTriggerEvent(TriggerEvent.TRIGGER_EVENT_TYPE typeString jobNameString triggerNameDate timeString message) {
         return createTriggerEvent(typejobNametriggerNametimemessagenull);
     }
 
     /* (non-Javadoc)
      * @see org.sakaiproject.api.app.scheduler.events.TriggerEventManager#createTriggerEvent(org.sakaiproject.api.app.scheduler.events.TriggerEvent.TRIGGER_EVENT_TYPE, java.lang.String, java.lang.String, java.util.Date, java.lang.String, java.lang.String)
      */
     public TriggerEvent createTriggerEvent(TriggerEvent.TRIGGER_EVENT_TYPE typeString jobNameString triggerName,
             Date timeString messageString serverId)
     {
         TriggerEventHibernateImpl event = new TriggerEventHibernateImpl();
 
         event.setEventType(type);
         event.setJobName(jobName);
         event.setTriggerName(triggerName);
         event.setTime(time);
         event.setMessage(message);
         event.setServerId(serverId);
 
         getHibernateTemplate().save(event);
 
         return event;
     }
 
     public List<TriggerEventgetTriggerEvents()
     {
         return getTriggerEvents(nullnullnullnullnull);
     }
 
     public List<TriggerEventgetTriggerEvents(int firstint size)
     {
         return getTriggerEvents(nullnullnullnullnullfirstsize);
     }
 
     public int getTriggerEventsSize()
     {
         return getTriggerEventsSize(nullnullnullnullnull);
     }
 
     public int getTriggerEventsSize(Date afterDate beforeList<StringjobsString triggerName,
             TriggerEvent.TRIGGER_EVENT_TYPE[] types)
     {
         final Criteria criteria = buildCriteria(afterbeforejobstriggerNametypes);
         criteria.setProjection(Projections.rowCount());
         return (Integercriteria.list().get(0);
     }
 
     public List<TriggerEventgetTriggerEvents(Date afterDate beforeList<StringjobsString triggerName,
             TriggerEvent.TRIGGER_EVENT_TYPE[] types)
     {
         return getTriggerEvents(afterbeforejobstriggerNametypesnullnull);
 
     }
     public List<TriggerEventgetTriggerEvents(Date afterDate beforeList<StringjobsString triggerName,
             TriggerEvent.TRIGGER_EVENT_TYPE[] typesint firstint size) {
         return getTriggerEvents(afterbeforejobstriggerNametypes, Integer.valueOf(first),  Integer.valueOf(size));
     }

    
Internal search for events. Applies the sort and optionally the limit/offset.
 
     protected List<TriggerEventgetTriggerEvents(Date afterDate beforeList<StringjobsString triggerName,
             TriggerEvent.TRIGGER_EVENT_TYPE[] typesInteger firstInteger size)
     {
         final Criteria criteria = buildCriteria(afterbeforejobstriggerNametypes);
         // We put the newest items first as generally that's what people are most interested in.
         criteria.addOrder(Order.desc("time"));
         if (first != null && size != null)
        {
            criteria.setFirstResult(first).setMaxResults(size);
        }
        return criteria.list();
    }

    
Creates a criteria with all restrictions applied.
    protected Criteria buildCriteria(Date afterDate beforeList<Stringjobs,
            String triggerNameTriggerEvent.TRIGGER_EVENT_TYPE[] types)
    {
        final Session session = this.getSession();
        final Criteria criteria = session.createCriteria(TriggerEventHibernateImpl.class);
        if (after != null)
        {
            criteria.add(Restrictions.ge("time"after));
        }
        if (before != null)
        {
            criteria.add(Restrictions.le("time"before));
        }
        if (jobs != null && !jobs.isEmpty())
        {
            criteria.add(Restrictions.in("jobName"jobs));
        }
        if (triggerName != null)
        {
            criteria.add(Restrictions.eq("triggerName"triggerName));
        }
        if (types != null)
        {
            criteria.add(Restrictions.in("eventType"types));
        }
        return criteria;
    }
    public void purgeEvents(Date before)
    {
        Query q = getSession().getNamedQuery("purgeEventsBefore");
        q.setTimestamp(0, before);
        q.executeUpdate();
    }
New to GrepCode? Check out our FAQ X