package gov.maine.node.util;

import java.sql.*;
import oracle.jdbc.driver.*;

public class Transaction 
{
String serverTransactionId;
String serviceTrackingId;
String userId;
String status;
  
  public Transaction()
  {
  }

  public String getServerTransactionId()
  {
    return serverTransactionId;
  }

  public void setServerTransactionId(String m_serverTransactionId)
  {

    serverTransactionId = m_serverTransactionId;
  }
  public String getServiceTrackingId()
  {
    return serviceTrackingId;
  }

  public void setServiceTrackingId(String m_serviceTrackingId)
  {
    serviceTrackingId = m_serviceTrackingId;
  }

  public String getUserId()
  {
    return userId;
  }

  public void setUserId(String m_userId)
  {
  userId = m_userId;  
  }
  
  public String getStatus()
  {
    return status;
  }

  public void setStatus(String m_status)
  {
    status = m_status;
  }

  public void writeToDB(Connection dbConnection) throws Exception
  {
    
       /* write to incoming_notification table */
        String  sql = "INSERT INTO  transaction (server_transaction_id,service_tracking_id, user_id, status, create_date,last_updated_date) "+
                   "values (?,?,?,?,sysdate,sysdate)";
         PreparedStatement ps = dbConnection.prepareStatement(sql);
         ps.setString(1,serverTransactionId);
         ps.setString(2,serviceTrackingId);
         ps.setString(3,userId);
         ps.setString(4,status);
         ps.execute();
         dbConnection.commit();
         ps.close();
  }


   public void updateToDB(Connection dbConnection) throws Exception
  {
    
       /* write to incoming_notification table */
        String  sql = "Update transaction set user_id = ?, status= ?, last_updated_date = sysdate  "+
                   "where server_transaction_id = ? and service_tracking_id = ?";
         PreparedStatement ps = dbConnection.prepareStatement(sql);
         ps.setString(1,userId);
         ps.setString(2,status);
         ps.setString(3,serverTransactionId);
         ps.setString(4,serviceTrackingId);
         ps.execute();
         dbConnection.commit();
         ps.close();
  }
  
}