package dataaccess;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
public class ArtifactMessage {
private long m_artifact_message_id;
private long m_artifact_id;
private long m_submitted_by;
private String m_from_email;
private Date m_adddate;
private String m_body;
private final static DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
public ArtifactMessage(long group_artifact_id, long artifact_id, long submitted_by, String from_email, Date adddate, String body)
{
m_artifact_message_id = group_artifact_id;
m_artifact_id = artifact_id;
m_submitted_by = submitted_by;
m_from_email = from_email;
m_adddate = adddate;
m_body = body;
}
public static LinkedList<ArtifactMessage> getArtifactMessages(long artifact_id, Date begin, Date end)
{
MysqlDataSource l_ds = DBAccess.ReturnDataSource();
Connection l_con = null;
Statement l_stat = null;
LinkedList<ArtifactMessage> l_artifacts = new LinkedList<ArtifactMessage>();
try
{
l_con = l_ds.getConnection();
l_stat = l_con.createStatement();
ResultSet s = l_stat.executeQuery("select id, artifact_id, submitted_by, from_unixtime(adddate) as adddate, body from artifact_message where artifact_id = " + artifact_id
+ " and from_unixtime(adddate) > '"+ df.format(begin) + "' and from_unixtime(adddate) < '" + df.format(end) + "'");
while (s.next())
{
ArtifactMessage tmp = new ArtifactMessage(s.getLong("id"), s.getLong("artifact_id"), s.getLong("submitted_by"),s.getDate("adddate"));
l_artifacts.add(tmp);
}
}
catch (Exception e)
{
return null;
}
finally
{
try {
l_stat.close();
l_con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return l_artifacts;
}
public ArtifactMessage(long group_artifact_id, long artifact_id, long submitted_by, String from_email, Date adddate)
{
m_artifact_message_id = group_artifact_id;
m_artifact_id = artifact_id;
m_submitted_by = submitted_by;
m_from_email = from_email;
m_adddate = adddate;
}
public ArtifactMessage(long group_artifact_id, long artifact_id, long submitted_by, Date adddate)
{
m_artifact_message_id = group_artifact_id;
m_artifact_id = artifact_id;
m_submitted_by = submitted_by;
m_adddate = adddate;
}
public static LinkedList<ArtifactMessage> getArtifactMessages(long artifact_id)
{
MysqlDataSource l_ds = DBAccess.ReturnDataSource();
Connection l_con = null;
Statement l_stat = null;
LinkedList<ArtifactMessage> l_artifact_ids = new LinkedList<ArtifactMessage>();
try
{
l_con = l_ds.getConnection();
l_stat = l_con.createStatement();
ResultSet s = l_stat.executeQuery("select id, artifact_id, submitted_by, from_unixtime(adddate) as adddate, body from artifact_message where artifact_id = " + artifact_id);
while (s.next())
{
ArtifactMessage tmp = new ArtifactMessage(s.getLong("id"), s.getLong("artifact_id"), s.getLong("submitted_by"),s.getDate("adddate"));
l_artifact_ids.add(tmp);
}
}
catch (Exception e)
{
return null;
}
finally
{
try {
l_stat.close();
l_con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return l_artifact_ids;
}
public long getM_artifact_message_id() {
return m_artifact_message_id;
}
public void setM_artifact_message_id(long mArtifactMessageId) {
m_artifact_message_id = mArtifactMessageId;
}
public long getM_artifact_id() {
return m_artifact_id;
}
public void setM_artifact_id(long mArtifactId) {
m_artifact_id = mArtifactId;
}
public long getM_submitted_by() {
return m_submitted_by;
}
public void setM_submitted_by(long mSubmittedBy) {
m_submitted_by = mSubmittedBy;
}
public String getM_from_email() {
return m_from_email;
}
public void setM_from_email(String mFromEmail) {
m_from_email = mFromEmail;
}
public Date getM_adddate() {
return m_adddate;
}
public void setM_adddate(Date mAdddate) {
m_adddate = mAdddate;
}
public String getM_body() {
return m_body;
}
public void setM_body(String mBody) {
m_body = mBody;
}
}