/**************************************************************************
*
* Class : com.btsinet.RawData.java
*
* Purpose : Tank Emission class for retrieving raw tank data
*
**************************************************************************
* Revision History
*
* V1.0.0 03/07/2000 James Bischoff
* Created
*
*************************************************************************/
package com.btsinet;
/**************************************************************************
* System Classes
*************************************************************************/
import com.ms.wfc.data.*; // ADO
import com.ms.mtx.*; // Transaction Server
import com.ms.wfc.app.*; // Registry, Time
import com.ms.com.*; // Variant
import com.ms.wfc.util.*; // Date Conversion
import java.util.*; // String Tokenizer
/**************************************************************************
* Custom Classes
*************************************************************************/
import com.btsinet.Message.*; // Custom Galaxy Local Messenger wrapper
import com.btsinet.Database.*; // Custom Database Functions
import com.btsinet.TimeUtils.*; // Custom Time Utilities
/**************************************************************************
* Class : RawData
* Purpose : Retrieve APPLY and Galaxy Tank Data and write Plantware
* data.
* Note : This is a COM in process DLL to be hosted in the transaction
* server
*
* @com.register ( clsid=EB30A778-A3FC-421C-B04B-9647BE56955E,
* typelib=A08303FB-6BF5-4271-929B-42A72E223BAA )
* @com.transaction (supported)
*************************************************************************/
public class RawData implements com.ms.mtx.IObjectControl
{
/***********************************************************************
* Class Constants
**********************************************************************/
private final static String gcstrClassName = new String("db_TankEmissions.RawData");
private final static String gcstrRegistryRoot = "Software\\UpperBay\\db_TankEmission\\1.0\\";
/////////////////////////////////////////////////////////////
// Tank Temperature ADO Command Constants
private final static int gcintTempTagOrd = 0;
private final static int gcintTempDateStartOrd = 1;
private final static int gcintTempDateEndOrd = 2;
private final static String gcstrTempSQL = new String(
"select " +
" avg(tag_value) tag_average " +
"from " +
" hourly_result " +
"where " +
" tag_id = ? and " +
" tag_timestamp between ? and ? ");
/////////////////////////////////////////////////////////////
// Tank Throughput ADO Command Constants
private final static int gcintTputTankOrd = 0;
private final static int gcintTputDateOrd = 1;
private final static String gcstrTputSQL = new String(
"select " +
" (nvl(tank_to_ship_vol,0) + " +
" nvl(to_tanks_vol,0) + " +
" nvl(to_units_vol,0)) tank_throughput " +
"from " +
" tank_data " +
"where " +
" tank_code = ? and " +
" act_period_end_date = ? ");
/////////////////////////////////////////////////////////////
// Tank Property ADO Command Constants
private final static int gcintPropTankOrd = 0;
private final static int gcintPropPropOrd = 1;
private final static int gcintPropDateOrd = 2;
private final static String gcstrPropSQL = new String(
"select " +
" composition_value " +
"from " +
" tank_prop_data " +
"where " +
" tank_code = ? and " +
" property_id = ? and " +
" act_period_end_date = ? ");
/////////////////////////////////////////////////////////////
// Tank Property Parameter Constants
private final static int gcintSPGPropID = 1;
private final static int gcintRVPPropID = 9;
/////////////////////////////////////////////////////////////
// Galaxy Tag ID ADO Command Constants
private final static String gcstrTagIDSQL = new String(
"select " +
" tag_id " +
"from " +
" tag " +
"where " +
" tag_name = ? ");
/////////////////////////////////////////////////////////////
// Plantware Process Unit ADO Command Constants
private final static String gcstrProcUnitSQL = new String(
"select " +
" vld_proc_unit_id " +
"from " +
" vld_proc_unit " +
"where " +
" proc_unit_iden = ? ");
/////////////////////////////////////////////////////////////
// Plantware Production Unit ADO Command Constants
private final static String gcstrProdUnitSQL = new String(
"select " +
" vld_prod_id " +
"from " +
" vld_prod " +
"where " +
" prod_unit_name = ? ");
/////////////////////////////////////////////////////////////
// Plantware parameter ADO Command Constants
private final static String gcstrParamSQL = new String(
"select " +
" vld_param_tdv_id " +
"from " +
" vld_param_tdv " +
"where " +
" param_name = ? ");
/////////////////////////////////////////////////////////////
// Plantware parameter ADO Command Constants
private final static int gcintProcTdvUnitOrd = 0;
private final static int gcintProcTdvParamOrd = 1;
private final static String gcstrProcTdvSQL = new String(
"select " +
" vld_proc_tdv_id " +
"from " +
" vld_proc_tdv " +
"where " +
" vld_proc_unit_id = ? and " +
" vld_param_tdv_id = ? ");
/////////////////////////////////////////////////////////////
// Plantware Insert ADO Command Constants
private final static int gcintTdvInsSiteOrd = 0;
private final static int gcintTdvInsUnitOrd = 1;
private final static int gcintTdvInsTdvOrd = 2;
private final static int gcintTdvInsDateOrd = 3;
private final static int gcintTdvInsResultOrd = 4;
private final static int gcintTdvInsResultUnitOrd = 5;
private final static String gcstrTdvInsSQL = new String(
"insert into " +
" vld_proc_tdv_result " +
"( " +
" vld_site_id, " +
" vld_proc_unit_id, " +
" vld_proc_tdv_id, " +
" result_date, " +
" result, " +
" result_unit ) " +
"values (?, ?, ?, ?, ?, ?) ");
/////////////////////////////////////////////////////////////
// Plantware Insert ADO Command Constants
private final static int gcintTdvUpdSiteOrd = 2;
private final static int gcintTdvUpdUnitOrd = 3;
private final static int gcintTdvUpdTdvOrd = 4;
private final static int gcintTdvUpdDateOrd = 5;
private final static int gcintTdvUpdResultOrd = 0;
private final static int gcintTdvUpdResultUnitOrd = 1;
private final static String gcstrTdvUpdSQL = new String(
"update " +
" vld_proc_tdv_result " +
"set " +
" result = ?, " +
" result_unit = ? " +
"where " +
" vld_site_id = ? and " +
" vld_proc_unit_id = ? and " +
" vld_proc_tdv_id = ? and " +
" result_date = ? ");
/***********************************************************************
* Class Globals
***********************************************************************/
private com.ms.mtx.IObjectContext gobjContext = null;
/////////////////////////////////////////////////////////////
// Default Values in case registry values not found
private int gintTraceLevel = 1;
private String gstrActConnectString = new String("FILEDSN=DCRAccounting");
private String gstrGlxConnectString = new String("FILEDSN=DCREclipse");
private String gstrPwConnectString = new String("FILEDSN=DCRPlantware");
private String gstrSiteID = new String("10000");
private String gstrTputName = new String("Net Throughput");
private String gstrTempName = new String("Average Liquid Temperature");
private String gstrRvpName = new String("Reid Vapor Pressure");
private String gstrTputUom = new String("bbl/day");
private String gstrTempUom = new String("F");
private String gstrRvpUom = new String("psi");
/////////////////////////////////////////////////////////////
// Utility Objects
private com.btsinet.Message gobjMessage = null;
private com.btsinet.Database gobjDatabase = null;
private com.btsinet.TimeUtils gobjTimeUtils = null;
/////////////////////////////////////////////////////////////
// ADO Connection and Command Objects
private com.ms.wfc.data.Connection gobjActADOConnection = null;
private com.ms.wfc.data.Connection gobjGlxADOConnection = null;
private com.ms.wfc.data.Connection gobjPwADOConnection = null;
private com.ms.wfc.data.Command gobjTempADOCommand = null;
private com.ms.wfc.data.Command gobjTputADOCommand = null;
private com.ms.wfc.data.Command gobjPropADOCommand = null;
private com.ms.wfc.data.Command gobjTagIDADOCommand = null;
private com.ms.wfc.data.Command gobjProcUnitADOCommand = null;
private com.ms.wfc.data.Command gobjProdUnitADOCommand = null;
private com.ms.wfc.data.Command gobjParamADOCommand = null;
private com.ms.wfc.data.Command gobjProcTdvADOCommand = null;
private com.ms.wfc.data.Command gobjTdvInsADOCommand = null;
private com.ms.wfc.data.Command gobjTdvUpdADOCommand = null;
/***********************************************************************
* Method : Class Constructor
* Purpose : Called when the class is instantiated.
**********************************************************************/
RawData() throws Throwable {
final String cstrMethodName = new String("RawData Constructor");
try {
gobjMessage = new Message();
gobjMessage.SetTraceLevel(gintTraceLevel);
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Start");
gobjDatabase = new Database();
gobjDatabase.SetUpMessenger(gobjMessage);
gobjTimeUtils = new TimeUtils();
gobjTimeUtils.SetUpMessenger(gobjMessage);
}
catch (Throwable exc) {
gobjMessage.SendError(gcstrClassName, cstrMethodName, exc.toString());
throw exc;
}
finally {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "End");
}
}
/***********************************************************************
* Method : IObjectControl.Activate
* Purpose : Called by MTS/COM+ when this object is created or recycled.
**********************************************************************/
public void Activate() {
final String cstrMethodName = new String("Activate");
try {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Start");
LoadRegistryValues();
gobjMessage.SetTraceLevel(gintTraceLevel);
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Get Transaction Context");
gobjContext = (IObjectContext) MTx.GetObjectContext();
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Open Accounting Database");
gobjActADOConnection = gobjDatabase.OpenADOConnection(gstrActConnectString);
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Open Galaxy Database");
gobjGlxADOConnection = gobjDatabase.OpenADOConnection(gstrGlxConnectString);
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Open Plantware Database");
gobjPwADOConnection = gobjDatabase.OpenADOConnection(gstrPwConnectString);
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Create Temperature Command");
gobjTempADOCommand = gobjDatabase.CreateCommand(
gobjGlxADOConnection, gcstrTempSQL, true);
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Create Throughput Command");
gobjTputADOCommand = gobjDatabase.CreateCommand(
gobjActADOConnection, gcstrTputSQL, true);
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Create Property Command");
gobjPropADOCommand = gobjDatabase.CreateCommand(
gobjActADOConnection, gcstrPropSQL, true);
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Create Tag ID Command");
gobjTagIDADOCommand = gobjDatabase.CreateCommand(
gobjGlxADOConnection, gcstrTagIDSQL, true);
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Create Process Unit Command");
gobjProcUnitADOCommand = gobjDatabase.CreateCommand(
gobjPwADOConnection, gcstrProcUnitSQL, true);
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Create Production Unit Command");
gobjProdUnitADOCommand = gobjDatabase.CreateCommand(
gobjPwADOConnection, gcstrProdUnitSQL, true);
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Create Parameter Command");
gobjParamADOCommand = gobjDatabase.CreateCommand(
gobjPwADOConnection, gcstrParamSQL, true);
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Create Unit Parameter Command");
gobjProcTdvADOCommand = gobjDatabase.CreateCommand(
gobjPwADOConnection, gcstrProcTdvSQL, true);
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Create Insert Command");
gobjTdvInsADOCommand = gobjDatabase.CreateCommand(
gobjPwADOConnection, gcstrTdvInsSQL, true);
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Create Update Command");
gobjTdvUpdADOCommand = gobjDatabase.CreateCommand(
gobjPwADOConnection, gcstrTdvUpdSQL, true);
}
catch (Throwable exc) {
gobjMessage.SendError(gcstrClassName, cstrMethodName, exc.toString());
}
finally {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "End");
}
}
/***********************************************************************
* Method : IObjectControl.CanBePooled
* Purpose : Called by MTS/COM+ after Deactivate to see if the object
* should be destroyed or recycled.
**********************************************************************/
public boolean CanBePooled() {
final String cstrMethodName = new String("CanBePooled");
try {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Start");
}
catch (Throwable exc) {
gobjMessage.SendError(gcstrClassName, cstrMethodName, exc.toString());
}
finally {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "End");
}
return true;
}
/***********************************************************************
* Method : IObjectControl.Deactivate
* Purpose : Called by MTS/COM+ after SetAbort or SetComplete is called,
* or the last reference is released or the objects transaction
* is commited.
**********************************************************************/
public void Deactivate() {
final String cstrMethodName = new String("Deactivate");
try {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Start");
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Destroy Temperature Command");
gobjTempADOCommand = null;
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Destroy Throughput Command");
gobjTputADOCommand = null;
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Destroy Property Command");
gobjPropADOCommand = null;
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Destroy Tag ID Command");
gobjTagIDADOCommand = null;
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Destroy Process Unit Command");
gobjProcUnitADOCommand = null;
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Destroy Production Unit Command");
gobjProdUnitADOCommand = null;
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Destroy Parameter Command");
gobjParamADOCommand = null;
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Destroy Unit Parameter Command");
gobjProcTdvADOCommand = null;
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Destroy Insert Command");
gobjTdvInsADOCommand = null;
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Destroy Update Command");
gobjTdvUpdADOCommand = null;
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Destroy Accounting Database");
gobjDatabase.DestroyADOConnection(gobjActADOConnection);
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Destroy Galaxy Database");
gobjDatabase.DestroyADOConnection(gobjGlxADOConnection);
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Destroy Plantware Database");
gobjDatabase.DestroyADOConnection(gobjPwADOConnection);
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Release Transaction Context");
gobjContext = null;
}
catch (Throwable exc) {
gobjMessage.SendError(gcstrClassName, cstrMethodName, exc.toString());
}
finally {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "End");
}
}
/***********************************************************************
* Method : LoadRegistryValues
* Purpose : Load all class cconfiguration values from the registry.
**********************************************************************/
private void LoadRegistryValues() throws Throwable {
final String cstrMethodName = new String("LoadRegistryValues");
String strTemp = null;
com.ms.wfc.app.RegistryKey hKey = null;
try {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Start");
if ((hKey = Registry.LOCAL_MACHINE.getSubKey(gcstrRegistryRoot)) == null)
gobjMessage.SendError(gcstrClassName, cstrMethodName,
"Unable to open registry key [" + gcstrRegistryRoot + "]");
else {
if ((strTemp = (String) hKey.getValue("TRACE_LEVEL")) != null)
gintTraceLevel = Integer.parseInt(strTemp);
if ((strTemp = (String) hKey.getValue("CONNECT_STRING_ACT")) != null)
gstrActConnectString = strTemp;
if ((strTemp = (String) hKey.getValue("CONNECT_STRING_GLX")) != null)
gstrGlxConnectString = strTemp;
if ((strTemp = (String) hKey.getValue("CONNECT_STRING_PW")) != null)
gstrPwConnectString = strTemp;
if ((strTemp = (String) hKey.getValue("SITE_ID")) != null)
gstrSiteID = strTemp;
if ((strTemp = (String) hKey.getValue("TRHOUGHPUT_PW_NAME")) != null)
gstrTputName = strTemp;
if ((strTemp = (String) hKey.getValue("TEMPERATURE_PW_NAME")) != null)
gstrTempName = strTemp;
if ((strTemp = (String) hKey.getValue("RVP_PW_NAME")) != null)
gstrRvpName = strTemp;
if ((strTemp = (String) hKey.getValue("TRHOUGHPUT_PW_UOM")) != null)
gstrTputUom = strTemp;
if ((strTemp = (String) hKey.getValue("TEMPERATURE_PW_UOM")) != null)
gstrTempUom = strTemp;
if ((strTemp = (String) hKey.getValue("RVP_PW_UOM")) != null)
gstrRvpUom = strTemp;
}
}
catch (Throwable exc) {
gobjMessage.SendError(gcstrClassName, cstrMethodName, exc.toString());
throw exc;
}
finally {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName,
"TRACE_LEVEL = [" + gintTraceLevel + "]");
gobjMessage.SendDebug(gcstrClassName, cstrMethodName,
"CONNECT_STRING_ACT = [" + gstrActConnectString + "]");
gobjMessage.SendDebug(gcstrClassName, cstrMethodName,
"CONNECT_STRING_GLX = [" + gstrGlxConnectString + "]");
gobjMessage.SendDebug(gcstrClassName, cstrMethodName,
"CONNECT_STRING_PW = [" + gstrPwConnectString + "]");
gobjMessage.SendDebug(gcstrClassName, cstrMethodName,
"SITE_ID = [" + gstrSiteID + "]");
gobjMessage.SendDebug(gcstrClassName, cstrMethodName,
"TRHOUGHPUT_PW_NAME = [" + gstrTputName + "]");
gobjMessage.SendDebug(gcstrClassName, cstrMethodName,
"TEMPERATURE_PW_NAME = [" + gstrTempName + "]");
gobjMessage.SendDebug(gcstrClassName, cstrMethodName,
"RVP_PW_NAME = [" + gstrRvpName + "]");
gobjMessage.SendDebug(gcstrClassName, cstrMethodName,
"TRHOUGHPUT_PW_UOM = [" + gstrTputUom + "]");
gobjMessage.SendDebug(gcstrClassName, cstrMethodName,
"TEMPERATURE_PW_UOM = [" + gstrTempUom + "]");
gobjMessage.SendDebug(gcstrClassName, cstrMethodName,
"RVP_PW_UOM = [" + gstrRvpUom + "]");
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "End");
}
}
/***********************************************************************
* Method : GetTankEmissionData
* Purpose : Return a tanks data as a recordset.
* Note : The vntStartDate and vntEndDate can be VB Date variables
* or date variants.
**********************************************************************/
public Object GetTankEmissionData(
String strTankCodes,
String strTempTagNames,
String strProdUnits,
String strProcUnits,
Variant vntStartDate,
Variant vntEndDate) throws Throwable {
final String cstrMethodName = new String("GetTankEmissionData");
boolean blnSuccess = true;
com.ms.com.Variant vntThroughput = null;
com.ms.com.Variant vntSPG = null;
com.ms.com.Variant vntRVP = null;
com.ms.com.Variant vntTemp = null;
com.ms.com.Variant vntWorkingDate = null;
com.ms.wfc.app.Time dtmStartTime = null;
com.ms.wfc.app.Time dtmEndTime = null;
com.ms.wfc.app.Time dtmWorkingDate = null;
com.ms.wfc.app.Time dtmTempStartDate = null;
com.ms.wfc.app.Time dtmTempEndDate = null;
com.ms.com.Variant vntTempStartDate = null;
com.ms.com.Variant vntTempEndDate = null;
com.ms.wfc.data.Recordset objADORecordset = null;
java.util.StringTokenizer objTanks = null;
java.util.StringTokenizer objTagNames = null;
java.util.StringTokenizer objProdUnits = null;
java.util.StringTokenizer objProcUnits = null;
String strTankCode = null;
String strTagName = null;
String strProdUnit = null;
String strProcUnit = null;
int intTagID;
String strProdUnitID = null;
String strProcUnitID = null;
String strTputID = null;
String strTempID = null;
String strRvpID = null;
String strUnitParamTputID = null;
String strUnitParamTempID = null;
String strUnitParamRvpID = null;
try
{
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Start");
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Create Tonekizer Objects");
objTanks = new StringTokenizer(strTankCodes, ",", false);
objTagNames = new StringTokenizer(strTempTagNames, ",", false);
objProdUnits = new StringTokenizer(strProdUnits, ",", false);
objProcUnits = new StringTokenizer(strProcUnits, ",", false);
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Create Time Objects");
dtmStartTime = gobjTimeUtils.VariantToTime(vntStartDate);
dtmEndTime = gobjTimeUtils.VariantToTime(vntEndDate);
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Create Result Recordset");
objADORecordset = CreateTankRS();
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Get Tput Param ID");
gobjParamADOCommand.getParameters().getItem(0).setString(gstrTputName);
strTputID = gobjDatabase.ExecuteCommandValue(gobjParamADOCommand, "vld_param_tdv_id").toString();
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Get Temp Param ID");
gobjParamADOCommand.getParameters().getItem(0).setString(gstrTempName);
strTempID = gobjDatabase.ExecuteCommandValue(gobjParamADOCommand, "vld_param_tdv_id").toString();
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Get RVP Param ID");
gobjParamADOCommand.getParameters().getItem(0).setString(gstrRvpName);
strRvpID = gobjDatabase.ExecuteCommandValue(gobjParamADOCommand, "vld_param_tdv_id").toString();
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Loop Through Tank/Tag Lists");
while (objTanks.hasMoreTokens() & objTagNames.hasMoreTokens()) {
strTankCode = objTanks.nextToken().trim();
strTagName = objTagNames.nextToken().trim();
strProdUnit = objProdUnits.nextToken().trim();
strProcUnit = objProcUnits.nextToken().trim();
gobjMessage.SendDebug(gcstrClassName, cstrMethodName,
"Working on Tank [" + strTankCode + "]");
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Get Tag ID");
gobjTagIDADOCommand.getParameters().getItem(0).setString(strTagName);
intTagID = Integer.parseInt(gobjDatabase.ExecuteCommandValue(
gobjTagIDADOCommand, "tag_id").toString());
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Get Production Unit ID");
gobjProdUnitADOCommand.getParameters().getItem(0).setString(strProdUnit);
strProdUnitID = gobjDatabase.ExecuteCommandValue(gobjProdUnitADOCommand, "vld_prod_id").toString();
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Get Process Unit ID");
gobjProcUnitADOCommand.getParameters().getItem(0).setString(strProcUnit);
strProcUnitID = gobjDatabase.ExecuteCommandValue(gobjProcUnitADOCommand, "vld_proc_unit_id").toString();
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Get Unit Tput Parameter ID");
gobjProcTdvADOCommand.getParameters().getItem(gcintProcTdvUnitOrd).setString(strProcUnitID);
gobjProcTdvADOCommand.getParameters().getItem(gcintProcTdvParamOrd).setString(strTputID);
strUnitParamTputID = gobjDatabase.ExecuteCommandValue(gobjProcTdvADOCommand, "vld_proc_tdv_id").toString();
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Get Unit Temp Parameter ID");
gobjProcTdvADOCommand.getParameters().getItem(gcintProcTdvParamOrd).setString(strTempID);
strUnitParamTempID = gobjDatabase.ExecuteCommandValue(gobjProcTdvADOCommand, "vld_proc_tdv_id").toString();
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Get Unit RVP Parameter ID");
gobjProcTdvADOCommand.getParameters().getItem(gcintProcTdvParamOrd).setString(strRvpID);
strUnitParamRvpID = gobjDatabase.ExecuteCommandValue(gobjProcTdvADOCommand, "vld_proc_tdv_id").toString();
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Set Tank/Tag Parameters");
gobjTputADOCommand.getParameters().getItem(gcintTputTankOrd).setString(strTankCode);
gobjPropADOCommand.getParameters().getItem(gcintPropTankOrd).setString(strTankCode);
gobjTempADOCommand.getParameters().getItem(gcintTempTagOrd).setInt(intTagID);
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Loop Through Date Range");
dtmWorkingDate = gobjTimeUtils.VariantToTime(vntStartDate);
while (dtmWorkingDate.compareTo(dtmEndTime) <= 0) {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName,
"Working on [" + dtmWorkingDate.toString() + "]");
vntWorkingDate = gobjTimeUtils.TimeToVariant(dtmWorkingDate);
dtmTempStartDate = dtmWorkingDate.addHours(1);
vntTempStartDate = gobjTimeUtils.TimeToVariant(dtmTempStartDate);
dtmTempEndDate = dtmWorkingDate.addDays(1);
vntTempEndDate = gobjTimeUtils.TimeToVariant(dtmTempEndDate);
gobjTputADOCommand.getParameters().getItem(gcintTputDateOrd).setValue(vntWorkingDate);
gobjPropADOCommand.getParameters().getItem(gcintPropDateOrd).setValue(vntWorkingDate);
gobjTempADOCommand.getParameters().getItem(gcintTempDateStartOrd).setValue(vntTempStartDate);
gobjTempADOCommand.getParameters().getItem(gcintTempDateEndOrd).setValue(vntTempEndDate);
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Get Tank Throughput");
vntThroughput = gobjDatabase.ExecuteCommandValue(gobjTputADOCommand, "tank_throughput");
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Get Tank RVP");
gobjPropADOCommand.getParameters().getItem(gcintPropPropOrd).setInt(gcintRVPPropID);
vntRVP = gobjDatabase.ExecuteCommandValue(gobjPropADOCommand, "composition_value");
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Get Tank SPG");
gobjPropADOCommand.getParameters().getItem(gcintPropPropOrd).setInt(gcintSPGPropID);
vntSPG = gobjDatabase.ExecuteCommandValue(gobjPropADOCommand, "composition_value");
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Get Tank Temp");
vntTemp = gobjDatabase.ExecuteCommandValue(gobjTempADOCommand, "tag_average");
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Add Record To Result Set");
AddToTankRS(objADORecordset, strTankCode, vntWorkingDate,
strTagName, intTagID, strProdUnit, strProdUnitID, strProcUnit, strProcUnitID,
strUnitParamTempID, vntTemp, strUnitParamTputID, vntThroughput,
strUnitParamRvpID, vntRVP, vntSPG);
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Add 1 Day");
dtmWorkingDate = dtmWorkingDate.addDays(1);
}
}
return (Object) objADORecordset.getDataSource(); //Return underlying COM object
}
catch(Throwable exc)
{
blnSuccess = false;
gobjMessage.SendError(gcstrClassName, cstrMethodName, exc.toString());
throw exc;
}
finally
{
if (gobjContext.IsInTransaction())
if (blnSuccess)
gobjContext.SetComplete();
else
gobjContext.SetAbort();
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "End");
}
}
/***********************************************************************
* Method : CreateTankRS
* Purpose : Create and return an ADO recordset for all tank data
* collected from the Accounting database and Galaxy .
**********************************************************************/
private Recordset CreateTankRS() throws Throwable {
final String cstrMethodName = new String("GetTankEmissionData");
final int intUnspecified = AdoEnums.FieldAttribute.UNSPECIFIED;
final int intIsNullable = AdoEnums.FieldAttribute.ISNULLABLE;
final int intKeyColumn = AdoEnums.FieldAttribute.KEYCOLUMN;
final int intVarchar = AdoEnums.DataType.VARCHAR;
final int intDBTimestamp = AdoEnums.DataType.DBTIMESTAMP;
final int intDouble = AdoEnums.DataType.DOUBLE;
final int intInteger = AdoEnums.DataType.INTEGER;
com.ms.wfc.data.Recordset objADORecordset = new Recordset();
com.ms.wfc.data.Fields objADOFields = null;
try {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Start");
objADORecordset.setCursorLocation(AdoEnums.CursorLocation.CLIENT);
objADOFields = objADORecordset.getFields();
objADOFields.append("TankCode", intVarchar, 15, intKeyColumn);
objADOFields.append("TankDate", intDBTimestamp, intUnspecified, intKeyColumn);
objADOFields.append("TagName", intVarchar, 30, intUnspecified);
objADOFields.append("TagID", intInteger, intUnspecified, intUnspecified);
objADOFields.append("ProdUnitName", intVarchar, 100, intUnspecified);
objADOFields.append("ProdUnitID", intVarchar, 38, intUnspecified);
objADOFields.append("ProcUnitName", intVarchar, 40, intUnspecified);
objADOFields.append("ProcUnitID", intVarchar, 38, intUnspecified);
objADOFields.append("TempParamID", intVarchar, 38, intUnspecified);
objADOFields.append("AvgTemp", intDouble, intUnspecified, intIsNullable);
objADOFields.append("TempUom", intVarchar, 20, intUnspecified);
objADOFields.append("TputParamID", intVarchar, 38, intUnspecified);
objADOFields.append("Throughput", intDouble, intUnspecified, intIsNullable);
objADOFields.append("TputUom", intVarchar, 20, intUnspecified);
objADOFields.append("RvpParamID", intVarchar, 38, intUnspecified);
objADOFields.append("RVP", intDouble, intUnspecified, intIsNullable);
objADOFields.append("RvpUom", intVarchar, 20, intUnspecified);
objADOFields.append("SPG", intDouble, intUnspecified, intIsNullable);
objADORecordset.open();
return objADORecordset;
}
catch (Throwable exc)
{
gobjMessage.SendError(gcstrClassName, cstrMethodName, exc.toString());
throw exc;
}
finally {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "End");
}
}
/***********************************************************************
* Method : AddToTankRS
* Purpose : Add a record to the manually created recordset.
* Note : Use variants here to support null values.
**********************************************************************/
private void AddToTankRS(
Recordset objADORecordset,
String strTankCode,
Variant vntTankDate,
String strTagName,
int intTagID,
String strProdUnitName,
String strProdUnitID,
String strProcUnitName,
String strProcUnitID,
String strTempParamID,
Variant vntAvgTemp,
String strTputParamID,
Variant vntThroughput,
String strRvpParamID,
Variant vntRVP,
Variant vntSPG) throws Throwable {
final String cstrMethodName = new String("AddToTankRS");
com.ms.wfc.data.Fields objADOFields = null;
com.ms.wfc.data.Timestamp dtmTankDate = null;
try {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Start");
dtmTankDate = gobjTimeUtils.VariantToTimestamp(vntTankDate);
objADOFields = objADORecordset.getFields();
objADORecordset.addNew();
objADOFields.getItem("TankCode").setString(strTankCode);
objADOFields.getItem("TankDate").setTimestamp(dtmTankDate);
objADOFields.getItem("TagName").setString(strTagName);
objADOFields.getItem("TagID").setInt(intTagID);
objADOFields.getItem("ProdUnitName").setString(strProdUnitName);
objADOFields.getItem("ProdUnitID").setString(strProdUnitID);
objADOFields.getItem("ProcUnitName").setString(strProcUnitName);
objADOFields.getItem("ProcUnitID").setString(strProcUnitID);
objADOFields.getItem("TempParamID").setString(strTempParamID);
objADOFields.getItem("AvgTemp").setValue(vntAvgTemp);
objADOFields.getItem("TempUom").setString(gstrTempUom);
objADOFields.getItem("TputParamID").setString(strTputParamID);
objADOFields.getItem("Throughput").setValue(vntThroughput);
objADOFields.getItem("TputUom").setString(gstrTputUom);
objADOFields.getItem("RvpParamID").setString(strRvpParamID);
objADOFields.getItem("RVP").setValue(vntRVP);
objADOFields.getItem("RvpUom").setString(gstrRvpUom);
objADOFields.getItem("SPG").setValue(vntSPG);
objADORecordset.update();
}
catch (Throwable exc)
{
gobjMessage.SendError(gcstrClassName, cstrMethodName, exc.toString());
throw exc;
}
finally {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "End");
}
}
/***********************************************************************
* Method : PutTankEmissionData
* Purpose : Write a single tank parameter datum into Plantware.
* Note : The vntDate can be a VB Date variable or a date variant.
**********************************************************************/
public int PutTankEmissionData(
String strProcUnitID,
String strUnitParamID,
Variant vntDate,
Variant vntValue,
String strValueUnit) throws Throwable {
final String cstrMethodName = new String("PutTankEmissionData");
boolean blnSuccess = true;
int intRecords = 0;
try
{
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Start");
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Establish Variant Types");
vntDate.changeType(Variant.VariantDate);
vntValue.changeType(Variant.VariantDouble);
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Execute Update");
gobjTdvUpdADOCommand.getParameters().getItem(gcintTdvUpdSiteOrd).setString(gstrSiteID);
gobjTdvUpdADOCommand.getParameters().getItem(gcintTdvUpdUnitOrd).setString(strProcUnitID);
gobjTdvUpdADOCommand.getParameters().getItem(gcintTdvUpdTdvOrd).setString(strUnitParamID);
gobjTdvUpdADOCommand.getParameters().getItem(gcintTdvUpdDateOrd).setValue(vntDate);
gobjTdvUpdADOCommand.getParameters().getItem(gcintTdvUpdResultOrd).setValue(vntValue);
gobjTdvUpdADOCommand.getParameters().getItem(gcintTdvUpdResultUnitOrd).setString(strValueUnit);
intRecords = gobjDatabase.ExecuteCommand(gobjTdvUpdADOCommand);
if (intRecords == 0) {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Execute Insert");
gobjTdvInsADOCommand.getParameters().getItem(gcintTdvInsSiteOrd).setString(gstrSiteID);
gobjTdvInsADOCommand.getParameters().getItem(gcintTdvInsUnitOrd).setString(strProcUnitID);
gobjTdvInsADOCommand.getParameters().getItem(gcintTdvInsTdvOrd).setString(strUnitParamID);
gobjTdvInsADOCommand.getParameters().getItem(gcintTdvInsDateOrd).setValue(vntDate);
gobjTdvInsADOCommand.getParameters().getItem(gcintTdvInsResultOrd).setValue(vntValue);
gobjTdvInsADOCommand.getParameters().getItem(gcintTdvInsResultUnitOrd).setString(strValueUnit);
intRecords = gobjDatabase.ExecuteCommand(gobjTdvInsADOCommand);
}
return intRecords;
}
catch(Throwable exc)
{
blnSuccess = false;
gobjMessage.SendError(gcstrClassName, cstrMethodName, exc.toString());
throw exc;
}
finally
{
if (gobjContext.IsInTransaction())
if (blnSuccess)
gobjContext.SetComplete();
else
gobjContext.SetAbort();
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "End");
}
}
}
|