Skip to content

Commit

Permalink
SAK-18864
Browse files Browse the repository at this point in the history
Abstracted the EventManager such that the old implementation can still be used if one prefers. Then created a Hibernate-backed version.
Added a pager to the events log, then filtering to filter on date, type, or job name.
Added other types of events and a message property to events in anticipation of adding the ability to log from jobs to the log



git-svn-id: https://source.sakaiproject.org/svn/jobscheduler/branches/SAK-18864@82099 66ffb92e-73f9-0310-93c1-f5514f145a0a
  • Loading branch information
Duffy Gillman committed Sep 3, 2010
1 parent 616cd8d commit dc194bb
Show file tree
Hide file tree
Showing 14 changed files with 614 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface TriggerEventManager

public List<TriggerEvent> getTriggerEvents ();

public List<TriggerEvent> getTriggerEvents (Date after, Date before, String jobName, String triggerName, TriggerEvent.TRIGGER_EVENT_TYPE[] types);
public List<TriggerEvent> getTriggerEvents (Date after, Date before, List<String> jobs, String triggerName, TriggerEvent.TRIGGER_EVENT_TYPE[] types);

public void purgeEvents (Date before);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public List<TriggerEvent> getTriggerEvents()
return Collections.unmodifiableList(events);
}

public List<TriggerEvent> getTriggerEvents(Date after, Date before, String jobName, String triggerName,
public List<TriggerEvent> getTriggerEvents(Date after, Date before, List<String> jobs, String triggerName,
TriggerEvent.TRIGGER_EVENT_TYPE[] types)
{
LinkedList<TriggerEvent>
Expand All @@ -53,7 +53,7 @@ public List<TriggerEvent> getTriggerEvents(Date after, Date before, String jobNa
continue;
if (before != null && event.getTime().compareTo(before) == 1)
continue;
if (jobName != null && !jobName.equals(event.getJobName()))
if (jobs != null && !jobs.contains(event.getJobName()))
continue;
if (triggerName != null && !triggerName.equals(event.getTriggerName()))
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public List<TriggerEvent> getTriggerEvents()
return criteria.list();
}

public List<TriggerEvent> getTriggerEvents(Date after, Date before, String jobName, String triggerName, TriggerEvent.TRIGGER_EVENT_TYPE[] types)
public List<TriggerEvent> getTriggerEvents(Date after, Date before, List<String> jobs, String triggerName, TriggerEvent.TRIGGER_EVENT_TYPE[] types)
{
final Session
session = this.getSession();
Expand All @@ -64,23 +64,23 @@ public List<TriggerEvent> getTriggerEvents(Date after, Date before, String jobNa

if (after != null)
{
criteria.add(Restrictions.gt("time", after));
criteria.add(Restrictions.or(Restrictions.gt("time", after), Restrictions.eq("time", after)));
}
if (before != null)
{
criteria.add(Restrictions.lt("time", before));
criteria.add(Restrictions.or(Restrictions.lt("time", before), Restrictions.eq("time", before)));
}
if (jobName != null)
if (jobs != null && !jobs.isEmpty())
{
criteria.add(Restrictions.eq("job", jobName));
criteria.add(Restrictions.in("jobName", jobs));
}
if (triggerName != null)
{
criteria.add(Restrictions.eq("trigger", triggerName));
criteria.add(Restrictions.eq("triggerName", triggerName));
}
if (types != null)
{
criteria.add(Restrictions.in("type", types));
criteria.add(Restrictions.in("eventType", types));
}

return criteria.list();
Expand Down
44 changes: 44 additions & 0 deletions jobscheduler/scheduler-events-model/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.sakaiproject.scheduler</groupId>
<artifactId>scheduler</artifactId>
<version>2.8-SNAPSHOT</version>
</parent>

<name>Sakai Job Scheduler Events Model</name>
<groupId>org.sakaiproject.scheduler</groupId>
<artifactId>scheduler-events-model</artifactId>
<organization>
<name>The Sakai Foundation</name>
<url>http://sakaiproject.org/</url>
</organization>
<inceptionYear>2003</inceptionYear>
<packaging>jar</packaging>

<properties>
<deploy.target>shared</deploy.target>
</properties>

<dependencies>
<dependency>
<groupId>org.sakaiproject.scheduler</groupId>
<artifactId>scheduler-api</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>${basedir}/src/hibernate</directory>
</resource>
</resources>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>

<class name="org.sakaiproject.scheduler.events.hibernate.TriggerEventHibernateImpl"
table="scheduler_trigger_events" lazy="false">

<id name="id" length="36" type="java.lang.String" column="uuid">
<generator class="uuid.hex"/>
</id>

<property name="eventType" column="type"
type="org.sakaiproject.scheduler.events.hibernate.TriggerEventEnumUserType" not-null="true"/>
<property name="jobName" column="jobName" type="string" not-null="true"/>
<property name="triggerName" column="triggerName" type="string"/>
<property name="time" column="time"/>
<property name="message" column="message" type="text"/>
</class>

<query name="purgeEventsBefore">
delete from TriggerEventHibernateImpl as evt
where evt.time &lt; ?
</query>

</hibernate-mapping>
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package org.sakaiproject.scheduler.events.hibernate;

import org.hibernate.HibernateException;
import org.hibernate.usertype.UserType;

import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;

/**
* This custom user type template was created from instructions found on the JBoss site at:
* http://community.jboss.org/wiki/UserTypeforpersistinganEnumwithaVARCHARcolumn
*
* User: duffy
* Date: Aug 26, 2010
* Time: 4:48:50 PM
* To change this template use File | Settings | File Templates.
*/
public class EnumUserType<E extends Enum<E>> implements UserType
{
private Class<E>
myClass = null;

private static final int[]
SQL_TYPES = {Types.VARCHAR};

protected EnumUserType (Class<E> c)
{
myClass = c;
}

public int[] sqlTypes()
{
return SQL_TYPES;
}

public Class returnedClass()
{
return myClass;
}

public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner)
throws HibernateException, SQLException
{
String
name = resultSet.getString(names[0]);
E
result = null;

if (!resultSet.wasNull())
{
result = Enum.valueOf(myClass, name);
}

return result;
}

public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index)
throws HibernateException, SQLException
{
if (null == value)
{
preparedStatement.setNull(index, Types.VARCHAR);
}
else
{
preparedStatement.setString(index, ((Enum)value).name());
}
}

public Object deepCopy(Object value)
throws HibernateException
{
return value;
}

public boolean isMutable()
{
return false;
}

public Object assemble(Serializable cached, Object owner)
throws HibernateException
{
return cached;
}

public Serializable disassemble(Object value)
throws HibernateException
{
return (Serializable)value;
}

public Object replace(Object original, Object target, Object owner)
throws HibernateException
{
return original;
}

public int hashCode(Object x)
throws HibernateException
{
return x.hashCode();
}

public boolean equals(Object x, Object y)
throws HibernateException
{
if (x == y)
return true;
if (null == x || null == y)
return false;

return x.equals(y);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.sakaiproject.scheduler.events.hibernate;

import org.sakaiproject.api.app.scheduler.events.TriggerEvent;

/**
* This custom user type was created based on the EnumUserType class modelled at:
* http://community.jboss.org/wiki/UserTypeforpersistinganEnumwithaVARCHARcolumn
*
* Created by IntelliJ IDEA.
* User: duffy
* Date: Aug 26, 2010
* Time: 5:01:30 PM
* To change this template use File | Settings | File Templates.
*/
public class TriggerEventEnumUserType extends EnumUserType<TriggerEvent.TRIGGER_EVENT_TYPE>
{
public TriggerEventEnumUserType()
{
super(TriggerEvent.TRIGGER_EVENT_TYPE.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package org.sakaiproject.scheduler.events.hibernate;

import org.sakaiproject.api.app.scheduler.events.TriggerEvent;

import java.util.Date;

/**
* Created by IntelliJ IDEA.
* User: duffy
* Date: Aug 26, 2010
* Time: 5:04:12 PM
* To change this template use File | Settings | File Templates.
*/
public class TriggerEventHibernateImpl
implements TriggerEvent
{
private TRIGGER_EVENT_TYPE
type;
private String
id,
jobName,
triggerName;
private Date
time;
private String
message;

public TriggerEventHibernateImpl()
{}

public void setId(String i)
{
id = i;
}

public String getId()
{
return id;
}

public void setEventType (TRIGGER_EVENT_TYPE t)
{
type = t;
}

public TRIGGER_EVENT_TYPE getEventType()
{
return type;
}

public void setJobName(String name)
{
jobName = name;
}

public String getJobName()
{
return jobName;
}

public void setTriggerName(String name)
{
triggerName = name;
}

public String getTriggerName()
{
return triggerName;
}

public void setTime(Date t)
{
time = t;
}

public Date getTime()
{
return time;
}

public void setMessage(String m)
{
message = m;
}

public String getMessage()
{
return message;
}

public int hashCode ()
{
return id.hashCode();
}

public boolean equals (Object o)
{
if (!TriggerEventHibernateImpl.class.isAssignableFrom (o.getClass()))
return false;

final TriggerEventHibernateImpl
that = (TriggerEventHibernateImpl)o;

if (this == that)
return true;

if (that == null)
return false;

return (id.equals(that.id));
}
}
Loading

0 comments on commit dc194bb

Please sign in to comment.