/**************************************************************************
*
* Class : Daemon.Monitor
*
* Purpose : Generic object monitor used to stop and start threads.
*
**************************************************************************
* Revision History
*
* V1.0.0 03/07/2000 James Bischoff
* Created
*
*************************************************************************/
public class Monitor
{
public Monitor() {}
public synchronized void Unlock() {
notifyAll();
}
public synchronized void Lock() {
try {
wait();
}
catch (InterruptedException ex) {
}
}
}
/**************************************************************************
*
* Script : com.btsinet.Database.java
*
* Purpose : Generic database methods
*
**************************************************************************
* 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.com.*; // Variant
/**************************************************************************
* Custom Classes
*************************************************************************/
import com.btsinet.Message; // Custom Galaxy Local Messenger wrapper
/**************************************************************************
* Class : Database
* Purpose : Main Database Class
*************************************************************************/
public class Database
{
/***********************************************************************
* Class Constants
**********************************************************************/
private final static String gcstrClassName = new String("Database");
/***********************************************************************
* Class Globals
***********************************************************************/
private Message gobjMessage = null;
/***********************************************************************
* Method : Class Constructor
* Purpose : Called when the class is instantiated.
**********************************************************************/
public Database() throws Throwable{
final String cstrMethodName = new String("Database Constructor");
try {
gobjMessage = new Message();
}
catch (Throwable exc) {
gobjMessage.SendError(gcstrClassName, cstrMethodName, exc.toString());
throw exc;
}
finally {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "End");
}
}
/***********************************************************************
* Method : SetUpMessenger
* Purpose : Use parent's messenger.
**********************************************************************/
public void SetUpMessenger(Message objMessage) {
final String cstrMethodName = new String("SetUpMessenger");
try {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Start");
gobjMessage = objMessage;
}
catch (Throwable exc) {
gobjMessage.SendError(gcstrClassName, cstrMethodName, exc.toString());
}
finally {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "End");
}
}
/***********************************************************************
* Method : OpenADOConnection
* Purpose : Create and open an ADO connection object.
**********************************************************************/
public Connection OpenADOConnection(String strConnectString) throws Throwable {
final String cstrMethodName = new String("OpenADOConnection");
Connection objADOConnection = null;
try {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Start");
objADOConnection = new Connection();
objADOConnection.setConnectionString(strConnectString);
objADOConnection.open( "", "", "", -1); // -1 is synchronous
return objADOConnection;
}
catch(com.ms.wfc.data.AdoException exc){
DumpADOErrors(objADOConnection, exc, cstrMethodName);
throw exc;
}
catch (Throwable exc) {
gobjMessage.SendError(gcstrClassName, cstrMethodName, exc.toString());
throw exc;
}
finally {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "End");
}
}
/***********************************************************************
* Method : DestroyADOConnection
* Purpose : Close and destroy an ADO connection object.
**********************************************************************/
public void DestroyADOConnection(Connection objADOConnection){
final String cstrMethodName = new String("DestroyADOConnection");
try {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Start");
if (objADOConnection.getState() == AdoEnums.ObjectState.OPEN) {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Close Connection");
objADOConnection.close();
}
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Destroy Connection");
objADOConnection = null;
}
catch(com.ms.wfc.data.AdoException exc){
DumpADOErrors(objADOConnection, exc, cstrMethodName);
}
catch (Throwable exc) {
gobjMessage.SendError(gcstrClassName, cstrMethodName, exc.toString());
}
finally {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "End");
}
}
/***********************************************************************
* Method : OpenADORecordset
* Purpose : Create and open a disconnected ADO recordset object.
**********************************************************************/
public Recordset OpenADORecordset(
Connection objADOConnection,
String strSQL,
boolean blnReadOnly) throws Throwable {
final String cstrMethodName = new String("OpenReadOnlyRS");
Recordset objADORecordset = null;
Variant vntSQL = null;
Variant vntSkip = null;
try {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Start");
objADORecordset = new Recordset();
vntSQL = new Variant();
vntSkip = new Variant();
vntSQL.putString(strSQL);
vntSkip.noParam();
objADORecordset.setActiveConnection(objADOConnection);
objADORecordset.setCursorLocation(AdoEnums.CursorLocation.CLIENT);
objADORecordset.open(
vntSQL,
vntSkip,
AdoEnums.CursorType.STATIC,
blnReadOnly ? AdoEnums.LockType.READONLY : AdoEnums.LockType.BATCHOPTIMISTIC,
AdoEnums.CommandType.TEXT);
return objADORecordset;
}
catch(com.ms.wfc.data.AdoException exc){
DumpADOErrors(objADOConnection, exc, cstrMethodName);
throw exc;
}
catch (Throwable exc) {
gobjMessage.SendError(gcstrClassName, cstrMethodName, exc.toString());
throw exc;
}
finally {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "End");
}
}
/***********************************************************************
* Method : ExecuteCommandValue
* Purpose : Execute command and return a variant.
**********************************************************************/
public Variant ExecuteCommandValue(
Command objADOCommand,
String strField) throws Throwable {
final String cstrMethodName = new String("ExecuteCommandValue");
com.ms.wfc.data.Recordset objADORecordset = null;
com.ms.com.Variant vntResult = null;
try {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Start");
// gobjMessage.SendDebug(gcstrClassName, cstrMethodName, objADOCommand.getCommandText());
objADORecordset = new Recordset();
objADORecordset.setCursorLocation(AdoEnums.CursorLocation.CLIENT);
objADORecordset.setCursorType(AdoEnums.CursorType.FORWARDONLY);
objADORecordset.setLockType(AdoEnums.LockType.READONLY);
objADORecordset.open(objADOCommand);
if (objADORecordset.getBOF() & objADORecordset.getEOF()) {
vntResult = new Variant();
vntResult.putNull();
}
else
vntResult = objADORecordset.getField(strField).getValue();
return vntResult;
}
catch(com.ms.wfc.data.AdoException exc){
DumpADOErrors(objADOCommand.getActiveConnection(), exc, cstrMethodName);
throw exc;
}
catch (Throwable exc)
{
gobjMessage.SendError(gcstrClassName, cstrMethodName, exc.toString());
throw exc;
}
finally {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "End");
}
}
/***********************************************************************
* Method : ExecuteCommand
* Purpose : Execute non query command and return the number of records
* effected.
**********************************************************************/
public int ExecuteCommand(Command objADOCommand) throws Throwable {
final String cstrMethodName = new String("ExecuteCommand");
int intRecords = 0;
try {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Start");
//gobjMessage.SendDebug(gcstrClassName, cstrMethodName, objADOCommand.getCommandText());
intRecords = objADOCommand.executeUpdate();
return intRecords;
}
catch(com.ms.wfc.data.AdoException exc){
DumpADOErrors(objADOCommand.getActiveConnection(), exc, cstrMethodName);
throw exc;
}
catch (Throwable exc)
{
gobjMessage.SendError(gcstrClassName, cstrMethodName, exc.toString());
throw exc;
}
finally {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "End");
}
}
/***********************************************************************
* Method : CreateCommand
* Purpose : Create a paramaterized command object.
**********************************************************************/
public Command CreateCommand(
Connection objADOConnection,
String strSQL,
boolean blnPrepared) throws Throwable {
final String cstrMethodName = new String("CreateCommand");
com.ms.wfc.data.Command objADOCommand = null;
try {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Start");
objADOCommand = new Command();
objADOCommand.setActiveConnection(objADOConnection);
objADOCommand.setCommandText(strSQL);
objADOCommand.setCommandType(AdoEnums.CommandType.TEXT);
objADOCommand.setPrepared(blnPrepared);
objADOCommand.getParameters().refresh();
return objADOCommand;
}
catch(com.ms.wfc.data.AdoException exc){
DumpADOErrors(objADOConnection, exc, cstrMethodName);
throw exc;
}
catch (Throwable exc)
{
gobjMessage.SendError(gcstrClassName, cstrMethodName, exc.toString());
throw exc;
}
finally {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "End");
}
}
/***********************************************************************
* Method : DumpADOErrors
* Purpose : Get the general ADO error and all errors in the connection's
* error collection.
**********************************************************************/
private void DumpADOErrors(
com.ms.wfc.data.Connection objADOConnetion,
com.ms.wfc.data.AdoException ADOexc,
String strMethod)
{
int intCount, intTotal;
try {
gobjMessage.SendError(gcstrClassName, strMethod, "ADO -> " + ADOexc.getMessage());
if (objADOConnetion != null) {
intTotal = objADOConnetion.getErrors().getCount();
for (intCount = 0; intCount < intTotal; intCount++ ) {
gobjMessage.SendError(gcstrClassName, strMethod,
"ADO Connection -> " + objADOConnetion.getErrors().getItem(intCount).getDescription());
}
}
}
catch (Throwable exc) {
}
}
}
/**************************************************************************
*
* Class : com.btsinet.Message.java
*
* Purpose : All application messages are routed here.
*
**************************************************************************
* Revision History
*
* V1.0.0 03/07/2000 James Bischoff
* Created
*
*************************************************************************/
package com.btsinet;
/**************************************************************************
* Java Callable Wrappers - JCWs
*************************************************************************/
import glxlocmsgobj.*; // Galaxy Local Messenger
/**************************************************************************
* Main Message Class
*************************************************************************/
public class Message {
/***********************************************************************
* Class Constants
**********************************************************************/
private final static String gcstrClassName = new String("Message");
private final static int gcTraceToFile = 10;
/***********************************************************************
* Class Globals
**********************************************************************/
private int gintTraceLevel = 0;
private ILocalMessenger gobjLocalMessenger = null;
/***********************************************************************
* Method : Class Constructor
* Purpose : Called when the class is instantiated.
**********************************************************************/
public Message() throws Throwable{
final String cstrMethodName = new String("Message Constructor");
try {
gobjLocalMessenger = new LocalMessenger();
}
catch (Throwable exc) {
SendError(gcstrClassName, cstrMethodName, exc.toString());
throw exc;
}
finally {
SendDebug(gcstrClassName, cstrMethodName, "End");
}
}
/***********************************************************************
* Method : BuildMessage
* Purpose : Create a full message string.
* Note : Should also remove CrLf's
**********************************************************************/
private String BuildMessage(
String strMethod,
String strMessage) throws Throwable {
final String cstrMethodName = new String("BuildMessage");
String strFullMessage = "";
try {
strFullMessage = strMethod + " {" + strMessage + "}";
return strFullMessage;
}
catch (Throwable exc) {
throw exc;
}
}
/***********************************************************************
* Method : SetTraceLevel
* Purpose : Set the debug trace level.
**********************************************************************/
public void SetTraceLevel(int intTraceLevel) {
final String cstrMethodName = new String("SetTraceLevel");
try {
SendDebug(gcstrClassName, cstrMethodName, "Start");
SendDebug(gcstrClassName, cstrMethodName,
"Trace level set to [" + intTraceLevel + "]");
gintTraceLevel = intTraceLevel;
}
catch (Throwable exc) {
}
finally {
SendDebug(gcstrClassName, cstrMethodName, "End");
}
}
/***********************************************************************
* Method : SetFiles
* Purpose : Set up the trace files.
**********************************************************************/
public void SetFiles(
String strDebugFile,
String strMessageFile,
String strErrorFile) {
final String cstrMethodName = new String("SetFiles");
try {
SendDebug(gcstrClassName, cstrMethodName, "Start");
gobjLocalMessenger.SetDebugFile(strDebugFile);
gobjLocalMessenger.SetMessageFile(strMessageFile);
gobjLocalMessenger.SetErrorFile(strErrorFile);
}
catch (Throwable exc) {
SendDebug(gcstrClassName,cstrMethodName,exc.toString());
}
finally {
SendDebug(gcstrClassName, cstrMethodName, "End");
}
}
/***********************************************************************
* Method : SendDebug, SendError, SendMessage
* Purpose : Output messages using the LocalMessenger object.
*
* SendLocalMessage takes the following string parameters:
*
* Type = Error, Warning, Message, Debug
* Channel = File, Debug, Event, All
* AppName = Application Name
* Message = The Message
*
**********************************************************************/
/***********************************************************************
* Debug window and optionally debug file
**********************************************************************/
public void SendDebug(
String strClass,
String strMethod,
String strMessage) {
String strFullMessage = null;
try {
strFullMessage = BuildMessage(strMethod, strMessage);
if (gintTraceLevel > 0) {
gobjLocalMessenger.SendLocalMessage(
"Debug",
"Debug",
strClass,
strFullMessage);
if (gintTraceLevel > gcTraceToFile)
gobjLocalMessenger.SendLocalMessage(
"Debug",
"File",
strClass,
strFullMessage);
}
}
catch (Throwable exc) {
}
}
/***********************************************************************
* Message file and optionally debug window
**********************************************************************/
public void SendMessage(
String strClass,
String strMethod,
String strMessage) {
String strFullMessage = null;
try {
strFullMessage = BuildMessage(strMethod, strMessage);
if (gintTraceLevel > 0) {
gobjLocalMessenger.SendLocalMessage(
"Debug",
"Debug",
strClass,
strFullMessage);
}
gobjLocalMessenger.SendLocalMessage(
"Message",
"File",
strClass,
strFullMessage);
}
catch (Throwable exc) {
}
}
/***********************************************************************
* Debug, File, and Event Log
**********************************************************************/
public void SendError(
String strClass,
String strMethod,
String strMessage) {
String strFullMessage = null;
try {
strFullMessage = BuildMessage(strMethod, strMessage);
gobjLocalMessenger.SendLocalMessage(
"Error",
"All",
strClass,
strFullMessage);
gobjLocalMessenger.SendLocalMessage(
"Debug",
"Debug",
strClass,
strFullMessage);
}
catch (Throwable exc) {
}
}
}
/**************************************************************************
*
* Script : com.btsinet.TimeUtils.java
*
* Purpose : Generic time utilities methods
*
**************************************************************************
* Revision History
*
* V1.0.0 03/07/2000 James Bischoff
* Created
*
*************************************************************************/
package com.btsinet;
/**************************************************************************
* System Classes
*************************************************************************/
import com.ms.com.*; // Variant
import com.ms.wfc.util.Value;
import com.ms.wfc.app.Time;
import com.ms.wfc.data.Timestamp;
/**************************************************************************
* Custom Classes
*************************************************************************/
import com.btsinet.Message.*; // Custom Galaxy Local Messenger wrapper
/**************************************************************************
* Class : TimeUtils
* Purpose : Main TimeUtils Class
*************************************************************************/
public class TimeUtils
{
/***********************************************************************
* Class Constants
**********************************************************************/
private final static String gcstrClassName = new String("TimeUtils");
/***********************************************************************
* Class Globals
***********************************************************************/
private Message gobjMessage = null;
/***********************************************************************
* Method : Class Constructor
* Purpose : Called when the class is instantiated.
**********************************************************************/
public TimeUtils() throws Throwable{
final String cstrMethodName = new String("TimeUtils Constructor");
try {
gobjMessage = new Message();
}
catch (Throwable exc) {
gobjMessage.SendError(gcstrClassName, cstrMethodName, exc.toString());
throw exc;
}
finally {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "End");
}
}
/***********************************************************************
* Method : SetUpMessenger
* Purpose : Use parent's messenger.
**********************************************************************/
public void SetUpMessenger(Message objMessage) {
final String cstrMethodName = new String("SetUpMessenger");
try {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Start");
gobjMessage = objMessage;
}
catch (Throwable exc) {
gobjMessage.SendError(gcstrClassName, cstrMethodName, exc.toString());
}
finally {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "End");
}
}
/***********************************************************************
* Method : VariantToTimestamp
* Purpose : Convert a Variant to an ADO compatible Timestamp.
**********************************************************************/
public Timestamp VariantToTimestamp(Variant vntInput) throws Throwable {
final String cstrMethodName = new String("VariantToTimestamp");
com.ms.wfc.util.Value objValue = null;
com.ms.wfc.app.Time objTime = null;
com.ms.wfc.data.Timestamp objTimestamp = null;
try {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Start");
objValue = new Value();
objTime = new Time(objValue.toDouble(vntInput));
objTimestamp = new Timestamp(objTime);
return objTimestamp;
}
catch (Throwable exc) {
gobjMessage.SendError(gcstrClassName, cstrMethodName, exc.toString());
throw exc;
}
finally {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "End");
}
}
/***********************************************************************
* Method : VariantToTime
* Purpose : Convert a Variant to a WFC compatible Time.
**********************************************************************/
public Time VariantToTime(Variant vntInput) throws Throwable {
final String cstrMethodName = new String("VariantToTime");
com.ms.wfc.util.Value objValue = null;
com.ms.wfc.app.Time objTime = null;
try {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Start");
objValue = new Value();
objTime = new Time(objValue.toDouble(vntInput));
return objTime;
}
catch (Throwable exc) {
gobjMessage.SendError(gcstrClassName, cstrMethodName, exc.toString());
throw exc;
}
finally {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "End");
}
}
/***********************************************************************
* Method : VariantToTime
* Purpose : Convert a Variant to a WFC compatible Time.
**********************************************************************/
public Variant TimeToVariant(Time objTime) throws Throwable {
final String cstrMethodName = new String("TimeToVariant");
com.ms.wfc.util.Value objValue = null;
com.ms.com.Variant vntTime = null;
try {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "Start");
objValue = new Value();
vntTime = Value.toVariant(objTime);
return vntTime;
}
catch (Throwable exc) {
gobjMessage.SendError(gcstrClassName, cstrMethodName, exc.toString());
throw exc;
}
finally {
gobjMessage.SendDebug(gcstrClassName, cstrMethodName, "End");
}
}
}
|