Package dataaccess

Source Code of dataaccess.Artifact

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 Artifact {
  private long m_artifact_id;
  private long m_group_artifact_id;
  private long m_status_id;
  private long m_category_id;
  private long m_artifact_group_id;
  private long m_resolution_id;
  private long m_priority;
  private long m_submitted_by;
  private long m_assigned_to;
  private Date m_open_date;
  private Date m_close_date;
  private String m_summary;
  private String m_details;
  private long m_closed_by;
  private long m_is_private;
 
  private final static DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
 
  public Artifact(long artifact_id, boolean dummy)
  {
 
    MysqlDataSource l_ds = DBAccess.ReturnDataSource();
      Connection l_con = null;
      Statement l_stat = null;
     
      try
      {
        l_con = l_ds.getConnection();
      l_stat = l_con.createStatement()

       
      ResultSet s = l_stat.executeQuery("select artifact_id, group_artifact_id, status_id, category_id, artifact_group_id," +
          " resolution_id, priority, submitted_by, assigned_to, from_unixtime(open_date) as open_date, from_unixtime(close_date) as close_date, " +
          "summary, details, closed_by, is_private from artifact where artifact_id = " + artifact_id);

     
      while (s.next())
      {
        m_artifact_id = s.getLong("artifact_id");
        m_group_artifact_id = s.getLong("group_artifact_id");
        m_status_id = s.getLong("status_id");
        m_category_id = s.getLong("category_id");
        m_artifact_group_id = s.getLong("artifact_group_id");
        m_resolution_id = s.getLong("resolution_id");
        m_priority = s.getLong("priority");
        m_submitted_by = s.getLong("submitted_by");
        m_assigned_to = s.getLong("assigned_to");
        m_open_date = s.getDate("open_date");
        m_close_date = s.getDate("close_date");
        m_summary = s.getString("summary");
        m_details = s.getString("details");
        m_closed_by = s.getLong("closed_by");
        m_is_private = s.getLong("is_private");
      }
   
      }
      catch (Exception e)
      {
        m_artifact_id = 0;
        m_group_artifact_id = 0;
        m_status_id = 0;
        m_category_id =0;
      }
      finally
      {
        try {
        l_stat.close();
          l_con.close();
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      }
  }
 
  public Artifact()
  {
    super();
  }
 
  public Artifact(long group_artifact_id)
  {
    m_group_artifact_id = group_artifact_id;
  }
 
  public static LinkedList<Long> getArtifacts(long group_artifact_id, Date begin, Date end)
  {
    MysqlDataSource l_ds = DBAccess.ReturnDataSource();
      Connection l_con = null;
      Statement l_stat = null;
      LinkedList<Long> l_artifact_ids = new LinkedList<Long>();
     
      try
      {
        l_con = l_ds.getConnection();
      l_stat = l_con.createStatement()

       
      ResultSet s = l_stat.executeQuery("select artifact_id from artifact where group_artifact_id = " + group_artifact_id + " and from_unix_time(open_date) > '"
          + df.format(begin) + "' and from_unix_time(close_date) < '" + df.format(begin) + "'");
     
      while (s.next())
      {
        l_artifact_ids.add(s.getLong("artifact_id"));
      }
   
      }
      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 static LinkedList<Long> getArtifacts(long group_artifact_id)
  {
    MysqlDataSource l_ds = DBAccess.ReturnDataSource();
      Connection l_con = null;
      Statement l_stat = null;
      LinkedList<Long> l_artifact_ids = new LinkedList<Long>();
     
      try
      {
        l_con = l_ds.getConnection();
      l_stat = l_con.createStatement()

       
      ResultSet s = l_stat.executeQuery("select artifact_id from artifact where group_artifact_id = " + group_artifact_id);
     
      while (s.next())
      {
        l_artifact_ids.add(s.getLong("artifact_id"));
      }
   
      }
      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 static Artifact getArtifact(long artifact_id)
  {
    MysqlDataSource l_ds = DBAccess.ReturnDataSource();
      Connection l_con = null;
      Statement l_stat = null;
      Artifact l_artifact = null;
     
     
      try
      {
        l_con = l_ds.getConnection();
      l_stat = l_con.createStatement()

       
      ResultSet s = l_stat.executeQuery("select artifact_id, group_artifact_id, status_id, category_id, artifact_group_id," +
          " resolution_id, priority, submitted_by, assigned_to, from_unixtime(open_date) as open_date, from_unixtime(close_date) as close_date, " +
          "summary, details, closed_by, is_private from artifact where artifact_id = " + artifact_id);

     
      while (s.next())
      {
        l_artifact = new Artifact ();
        l_artifact.setM_artifact_id(s.getLong("artifact_id"));
        l_artifact.setM_group_artifact_id(s.getLong("group_artifact_id"));
        l_artifact.setM_status_id(s.getLong("status_id"));
        l_artifact.setM_category_id(s.getLong("category_id"));
        l_artifact.setM_artifact_group_id(s.getLong("artifact_group_id"));
        l_artifact.setM_resolution_id(s.getLong("resolution_id"));
        l_artifact.setM_priority(s.getLong("priority"));
        l_artifact.setM_submitted_by(s.getLong("submitted_by"));
        l_artifact.setM_assigned_to(s.getLong("assigned_to"));
        l_artifact.setM_open_date(s.getDate("open_date"));
        l_artifact.setM_close_date(s.getDate("close_date"));
        l_artifact.setM_summary(s.getString("summary"));
        l_artifact.setM_details(s.getString("details"));
        l_artifact.setM_closed_by(s.getLong("closed_by"));
        l_artifact.setM_is_private(s.getLong("is_private"));
      }
   
      }
      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;
  }

  public long getM_artifact_id() {
    return m_artifact_id;
  }

  public void setM_artifact_id(long mArtifactId) {
    m_artifact_id = mArtifactId;
  }

  public long getM_group_artifact_id() {
    return m_group_artifact_id;
  }

  public void setM_group_artifact_id(long mGroupArtifactId) {
    m_group_artifact_id = mGroupArtifactId;
  }

  public long getM_status_id() {
    return m_status_id;
  }

  public void setM_status_id(long mStatusId) {
    m_status_id = mStatusId;
  }

  public long getM_category_id() {
    return m_category_id;
  }

  public void setM_category_id(long mCategoryId) {
    m_category_id = mCategoryId;
  }

  public long getM_artifact_group_id() {
    return m_artifact_group_id;
  }

  public void setM_artifact_group_id(long mArtifactGroupId) {
    m_artifact_group_id = mArtifactGroupId;
  }

  public long getM_resolution_id() {
    return m_resolution_id;
  }

  public void setM_resolution_id(long mResolutionId) {
    m_resolution_id = mResolutionId;
  }

  public long getM_priority() {
    return m_priority;
  }

  public void setM_priority(long mPriority) {
    m_priority = mPriority;
  }

  public long getM_submitted_by() {
    return m_submitted_by;
  }

  public void setM_submitted_by(long mSubmittedBy) {
    m_submitted_by = mSubmittedBy;
  }

  public long getM_assigned_to() {
    return m_assigned_to;
  }

  public void setM_assigned_to(long mAssignedTo) {
    m_assigned_to = mAssignedTo;
  }

  public Date getM_open_date() {
    return m_open_date;
  }

  public void setM_open_date(Date mOpenDate) {
    m_open_date = mOpenDate;
  }

  public Date getM_close_date() {
    return m_close_date;
  }

  public void setM_close_date(Date mCloseDate) {
    m_close_date = mCloseDate;
  }

  public String getM_summary() {
    return m_summary;
  }

  public void setM_summary(String mSummary) {
    m_summary = mSummary;
  }

  public String getM_details() {
    return m_details;
  }

  public void setM_details(String mDetails) {
    m_details = mDetails;
  }

  public long getM_closed_by() {
    return m_closed_by;
  }

  public void setM_closed_by(long mClosedBy) {
    m_closed_by = mClosedBy;
  }

  public long getM_is_private() {
    return m_is_private;
  }

  public void setM_is_private(long mIsPrivate) {
    m_is_private = mIsPrivate;
  }
}
TOP

Related Classes of dataaccess.Artifact

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.