forked from sakaiproject/sakai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
14 changed files
with
614 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
28 changes: 28 additions & 0 deletions
28
...c/hibernate/org/sakaiproject/scheduler/events/hibernate/TriggerEventHibernateImpl.hbm.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 < ? | ||
</query> | ||
|
||
</hibernate-mapping> |
118 changes: 118 additions & 0 deletions
118
...duler-events-model/src/java/org/sakaiproject/scheduler/events/hibernate/EnumUserType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...-model/src/java/org/sakaiproject/scheduler/events/hibernate/TriggerEventEnumUserType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
...model/src/java/org/sakaiproject/scheduler/events/hibernate/TriggerEventHibernateImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
Oops, something went wrong.