Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Attachment.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Attachment.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Attachment.java 17 Jun 2005 04:04:25 -0000 1.1 @@ -0,0 +1,55 @@ +package org.lamsfoundation.lams.tool.forum.persistence; + +/** + * @author conradb + * + * A Wrapper class for uploaded files. An Attachment cannot exist independently + * and must belong to a Forum. + * + * + * @hibernate.joined-subclass table="ATTACHMENT" + * @hibernate.joined-subclass-key column="id" + * + * @hibernate.query name="allAttachments" query="from Attachment attachment" + * @hibernate.query name="getAttachmentbyType" query="from Attachment attachment where attachment.type = ?" + */ +public class Attachment extends GenericEntity { + protected byte[] data; + protected boolean type; + protected String contentType; + public final static boolean TYPE_ONLINE = true; + public final static boolean TYPE_OFFLINE = false; + + + /** + * @hibernate.property column="DATA" + * type="binary" + */ + public byte[] getData() { + return data; + } + + public void setData(byte[] data) { + this.data = data; + } + + /** + * @hibernate.property column="TYPE" + */ + public boolean getType() { + return type; + } + + public void setType(boolean type) { + this.type = type; + } + + public String getContentType() { + return contentType; + } + + public void setContentType(String contentType) { + this.contentType = contentType; + } + +} Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/AttachmentDao.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/AttachmentDao.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/AttachmentDao.java 17 Jun 2005 04:04:25 -0000 1.1 @@ -0,0 +1,15 @@ +package org.lamsfoundation.lams.tool.forum.persistence; + +/** + * Created by IntelliJ IDEA. + * User: conradb + * Date: 7/06/2005 + * Time: 12:23:49 + * To change this template use File | Settings | File Templates. + */ +public class AttachmentDao extends GenericEntityDao { + + public Class getPersistentClass() { + return Attachment.class; + } +} Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Forum.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Forum.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Forum.java 17 Jun 2005 04:04:25 -0000 1.1 @@ -0,0 +1,167 @@ +package org.lamsfoundation.lams.tool.forum.persistence; + +import java.util.Set; + +/** + * Forum + * @author conradb + * + * @hibernate.joined-subclass table="FORUM" + * @hibernate.joined-subclass-key column="id" + * + * @hibernate.query name="allForums" query="from Forum forum" + */ +public class Forum extends GenericEntity { + protected String title; + protected boolean lockWhenFinished; + protected boolean forceOffline; + protected boolean allowAnnomity; + protected String instructions; + protected String onlineInstructions; + protected String offlineInstructions; + protected Set attachments; + + /** + * @return Returns the title. + * + * @hibernate.property + * column="TITLE" + * + */ + public String getTitle() { + return title; + } + + /** + * @param title The title to set. + */ + public void setTitle(String title) { + this.title = title; + } + + /** + * @return Returns the allowAnnomity. + * + * @hibernate.property + * column="ALLOWANNOMITY" + * + */ + public boolean getAllowAnnomity() { + return allowAnnomity; + } + + /** + * @param allowAnnomity The allowAnnomity to set. + * + */ + public void setAllowAnnomity(boolean allowAnnomity) { + this.allowAnnomity = allowAnnomity; + } + + /** + * @return Returns the forceOffline. + * + * @hibernate.property + * column="FORCEOFFLINE" + * + */ + public boolean getForceOffLine() { + return forceOffline; + } + + /** + * @param forceOffline The forceOffLine to set. + * + * + */ + public void setForceOffLine(boolean forceOffline) { + this.forceOffline = forceOffline; + } + + /** + * @return Returns the lockWhenFinish. + * + * @hibernate.property + * column="LOCKWHENFINISHED" + * + */ + public boolean getLockWhenFinished() { + return lockWhenFinished; + } + + /** + * @param lockWhenFinished Set to true to lock the forum for finished users. + */ + public void setLockWhenFinished(boolean lockWhenFinished) { + this.lockWhenFinished = lockWhenFinished; + } + + /** + * @return Returns the instructions set by the teacher. + * + * @hibernate.property + * column="INSTRUCTIONS" + * type="text" + */ + public String getInstructions() { + return instructions; + } + + public void setInstructions(String instructions) { + this.instructions = instructions; + } + + /** + * @return Returns the onlineInstructions set by the teacher. + * + * @hibernate.property + * column="ONLINEINSTRUCTIONS" + * type="text" + */ + public String getOnlineInstructions() { + return onlineInstructions; + } + + public void setOnlineInstructions(String onlineInstructions) { + this.onlineInstructions = onlineInstructions; + } + + /** + * @return Returns the onlineInstructions set by the teacher. + * + * @hibernate.property + * column="OFFLINEINSTRUCTIONS" + * type="text" + */ + public String getOfflineInstructions() { + return offlineInstructions; + } + + public void setOfflineInstructions(String offlineInstructions) { + this.offlineInstructions = offlineInstructions; + } + + /** + * @return a set of Attachments to this Message. + * + * @hibernate.set table="ATTACHMENT" + * inverse="false" + * lazy="false" + * cascade="none" + * @hibernate.collection-key column="FORUM" + * @hibernate.collection-one-to-many + * class="org.lamsfoundation.lams.tool.forum.persistence.Attachment" + * + */ + public Set getAttachments() { + return attachments; + } + + /* + * @param attachments The attachments to set. + */ + public void setAttachments(Set attachments) { + this.attachments = attachments; + } + +} Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/ForumDao.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/ForumDao.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/ForumDao.java 17 Jun 2005 04:04:25 -0000 1.1 @@ -0,0 +1,15 @@ +package org.lamsfoundation.lams.tool.forum.persistence; + +/** + * ForumDao + * @author conradb + * + * + */ +public class ForumDao extends GenericEntityDao { + + public Class getPersistentClass() { + return Forum.class; + } + +} Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/ForumException.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/ForumException.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/ForumException.java 17 Jun 2005 04:04:25 -0000 1.1 @@ -0,0 +1,19 @@ +package org.lamsfoundation.lams.tool.forum.persistence; + +/** + * Created by IntelliJ IDEA. + * User: conradb + * Date: 14/06/2005 + * Time: 12:33:12 + * To change this template use File | Settings | File Templates. + */ +public class ForumException extends RuntimeException { + + public ForumException(String message) { + super(message); + } + + public ForumException(String message, Throwable cause) { + super(message, cause); + } +} Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/GenericEntity.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Attic/GenericEntity.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/GenericEntity.java 17 Jun 2005 04:04:25 -0000 1.1 @@ -0,0 +1,171 @@ +package org.lamsfoundation.lams.tool.forum.persistence; + +import java.util.Date; + +/** + * GenericEntity + * @author conradb + * + * + * @hibernate.class table="GENERICENTITY" + * + * @hibernate.query name="all" query="from GenericEntity genericEntity" + */ +public class GenericEntity { + protected Long id; + protected Date created; + protected Date updated; + protected Long createdBy; + protected Long modifiedBy; + + public GenericEntity() { + + } + + /** + * Gets the GenericEntity's id + * + * @return the id + * @hibernate.id column="ID" generator-class="native" + */ + public Long getId() { + return id; + } + + /** + * Sets the project id + * + * @param id + */ + public void setId(Long id) { + this.id = id; + } + + /** + * Returns the object's creation date + * + * @return date + * @hibernate.property column="CREATED" + */ + public Date getCreated() { + return created; + } + + /** + * Sets the object's creation date + * + * @param created + */ + public void setCreated(Date created) { + this.created = created; + } + + /** + * Returns the object's date of last update + * + * @return date updated + * @hibernate.property column="UPDATED" + */ + public Date getUpdated() { + return updated; + } + + /** + * Sets the object's date of last update + * + * @param updated + */ + public void setUpdated(Date updated) { + this.updated = updated; + } + + /** + * @return Returns the userid of the user who created the Forum. + * + * @hibernate.property + * column="CREATEDBY" + * + */ + public Long getCreatedBy() { + return createdBy; + } + + /** + * @param createdBy The userid of the user who created this Forum. + */ + public void setCreatedBy(Long createdBy) { + this.createdBy = createdBy; + } + + /** + * Updates the modification data for this entity. + */ + public void updateModificationData() { + long now = System.currentTimeMillis(); + if (created == null) { + this.setCreated(new Date(now)); + } + this.setUpdated(new Date(now)); + } + + /** + * @return Returns the userid of the user who modified the posting. + * + * + * @hibernate.property + * column="MODIFIEDBY" + * + */ + public Long getModifiedBy() { + return modifiedBy; + } + + /** + * @param modifiedBy The userid of the user who modified the posting. + */ + public void setModifiedBy(Long modifiedBy) { + this.modifiedBy = modifiedBy; + } + + public boolean equals(Object o) { + if (this == o) + return true; + if (!(o instanceof GenericEntity)) + return false; + + final GenericEntity genericEntity = (GenericEntity) o; + + if (this.id != null ? !this.id.equals(genericEntity.id) + : genericEntity.id != null) + return false; + + if (this.createdBy != null ? !this.createdBy.equals(genericEntity.createdBy) + : genericEntity.createdBy != null) + return false; + + if (this.modifiedBy != null ? !this.modifiedBy.equals(genericEntity.modifiedBy) + : genericEntity.modifiedBy != null) + return false; + + if (this.created != null ? !new Date(this.created.getTime()/1000).equals(new Date(genericEntity.created.getTime()/1000)) + : genericEntity.created != null) + return false; + + if (this.updated != null ? !new Date(this.updated.getTime()/1000).equals(new Date(genericEntity.updated.getTime()/1000)) + : genericEntity.updated != null) + return false; + + return true; + } + + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 29 * result + (this.createdBy != null ? this.createdBy.hashCode() : 0); + result = 29 * result + (this.modifiedBy != null ? this.modifiedBy.hashCode() : 0); + result = 29 * result + (this.created != null ? new Date(this.created.getTime()/1000).hashCode() : 0); + result = 29 * result + (this.updated != null ? new Date(this.updated.getTime()/1000).hashCode() : 0); + return result; + } + +} Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/GenericEntityDao.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Attic/GenericEntityDao.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/GenericEntityDao.java 17 Jun 2005 04:04:25 -0000 1.1 @@ -0,0 +1,91 @@ +package org.lamsfoundation.lams.tool.forum.persistence; + +import org.springframework.orm.hibernate.HibernateCallback; +import org.springframework.orm.hibernate.support.HibernateDaoSupport; +import net.sf.hibernate.HibernateException; +import net.sf.hibernate.Session; + +import java.util.List; +import java.util.Date; + +/** + * @author conradb + * + * + */ + +public class GenericEntityDao extends HibernateDaoSupport { + + /** + * Retrieve the GenericEntity with a particular id. The GenericEntity must be of + * the same class as the DAO's getPersistentClass() method returns. + * + * @param id the id of the GenericEntity to look up + * @return the corresponding GenericEntity, or null if the object does not exist with the + * appropriate class and id. + */ + public GenericEntity getById(final Long id) { + GenericEntity entity = (GenericEntity) this.getHibernateTemplate().execute(new HibernateCallback() { + public Object doInHibernate(Session session) throws HibernateException { + return session.get(getPersistentClass(), id); + } + }); + return entity; + } + + /** + * Save the GenericEntity if it doesn't exist or update an existing entity with the same id. + * + * @param genericEntity + */ + public void saveOrUpdate(GenericEntity genericEntity) { + genericEntity.updateModificationData(); + this.getHibernateTemplate().saveOrUpdate(genericEntity); + } + + /** + * Delete the GenericEntity with this id + * @param genericEntity + */ + public void delete(GenericEntity genericEntity) { + this.getHibernateTemplate().delete(genericEntity); + } + + /** + * Find a list of GenericEntity objects, fetched by a given named query in the Entity object hierarchy. + * @param name the query name + * @return a list of GenericEntity objects. + */ + public List findByNamedQuery(String name) { + return this.getHibernateTemplate().findByNamedQuery(name); + } + + /** + * Find a list of GenericEntity objects, fetched by a given named query in the Entity object hierarchy. + * @param name the query name + * @param value the query parameter at position 0 + * @return a list of GenericEntity objects. + */ + public List findByNamedQuery(String name, Object value) { + return this.getHibernateTemplate().findByNamedQuery(name, value); + } + + /** + * Find a list of GenericEntity objects, fetched by a given named query in the Entity object hierarchy. + * @param name the query name + * @param values an array of query parameters passed into the query at the position of their array index. + * @return a list of GenericEntity objects. + */ + public List findByNamedQuery(String name, Object[] values) { + return this.getHibernateTemplate().findByNamedQuery(name, values); + } + + /** + * Implement this to return the actual class mapped to hibernate. + * + * @return + */ + public Class getPersistentClass() { + return GenericEntity.class; + } +} Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Message.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Message.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Message.java 17 Jun 2005 04:04:25 -0000 1.1 @@ -0,0 +1,142 @@ +package org.lamsfoundation.lams.tool.forum.persistence; + +import java.util.Set; +import java.util.Date; + +/** + * @author conradb + * + * @hibernate.joined-subclass table="MESSAGE" + * @hibernate.joined-subclass-key column="id" + * + * @hibernate.query name="allMessages" query="from Message message" + * @hibernate.query name="allAuthoredMessagesByForum" query="from Message message where message.forum = ? AND message.isAuthored = true" + * @hibernate.query name="allMessagesByForum" query="from Message message where message.forum = ?" + */ +public class Message extends GenericEntity { + protected String subject; + protected String body; + protected boolean isAuthored; + protected boolean isAnnonymous; + protected Set replies; + protected Forum forum; + + /** + * @return Returns the subject of the Message. + * + * @hibernate.property + * column="SUBJECT" + * + */ + public String getSubject() { + return subject; + } + + /** + * @param subject The subject of the Message to be set. + */ + public void setSubject(String subject) { + this.subject = subject; + } + + /** + * @return Returns the body of the Message. + * + * @hibernate.property + * column="BODY" + * + */ + public String getBody() { + return body; + } + + /** + * @param body The body of the Message to set. + */ + public void setBody(String body) { + this.body = body; + } + + /** + * @return Returns true if the Message was an Authored Message. + * + * @hibernate.property + * column="ISAUTHORED" + * + */ + public boolean getIsAuthored() { + return isAuthored; + } + + /** + * @param isAuthored Set isAuthored to true if Message was authored + * otherwise set to false. + */ + public void setIsAuthored(boolean isAuthored) { + this.isAuthored = isAuthored; + } + + /** + * @return Returns whether the Message should be shown as an + * Annonymous message. + * + * @hibernate.property + * column="ISANNONYMOUS" + * + */ + public boolean getIsAnnonymous() { + return isAnnonymous; + } + + /** + * @param isAnnonymous Indicates that the Message is to be shown + * as an Annonymous message when set to true. + */ + public void setIsAnnonymous(boolean isAnnonymous) { + this.isAnnonymous = isAnnonymous; + } + + /** + * @return a set of relpies to this Message. + * + * @hibernate.set table="MESSAGE" + * inverse="false" + * lazy="false" + * cascade="all" + * @hibernate.collection-key column="PARENT" + * @hibernate.collection-one-to-many + * class="org.lamsfoundation.lams.tool.forum.persistence.Message" + * + */ + public Set getReplies() { + return replies; + } + + /** + * @param replies The reply Messages that is associated with this Message. + */ + public void setReplies(Set replies) { + this.replies = replies; + } + + /** + * Gets the forum + * + * @hibernate.many-to-one + * class="org.lamsfoundation.lams.tool.forum.persistence.Forum" + * column="FORUM" + * + */ + public Forum getForum() { + return forum; + } + + + /** + * @param forum The forum that this Message belongs to + */ + public void setForum(Forum forum) { + this.forum = forum; + } + +} Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/MessageDao.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/MessageDao.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/MessageDao.java 17 Jun 2005 04:04:25 -0000 1.1 @@ -0,0 +1,21 @@ +/* + * Created on Jun 1, 2005 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package org.lamsfoundation.lams.tool.forum.persistence; + +/** + * @author conradb + * + * TODO To change the template for this generated type comment go to + * Window - Preferences - Java - Code Style - Code Templates + */ +public class MessageDao extends GenericEntityDao { + + public Class getPersistentClass() { + return Message.class; + } + +}