File: eaf_n_transaction.sru
Size: 22511
Date: Tue, 22 Jan 2008 23:39:15 +0100
$PBExportHeader$eaf_n_transaction.sru
forward
global type eaf_n_transaction from transaction
end type
end forward

global type eaf_n_transaction from transaction
end type
global eaf_n_transaction eaf_n_transaction

type variables
Public:

n_cst_messageservice       inv_messaging
Boolean                    allowtransactionflag = true

Protected:
string                     is_name

//Debugging/Error references
boolean                    ib_trace = false
boolean                    ib_debug = false
boolean                    ib_detailed = false
boolean                    ib_usedatabaselogging = false
boolean                    ib_warning = false

n_cst_loggingservice_base  inv_log
n_cst_constants            inv_constants

end variables

forward prototypes
public function long setdebug (boolean ab_state)
public function long setdetailed (boolean ab_state)
public function long settrace (boolean ab_state)
public function long transactionconnect ()
public function long transactiondisconnect ()
public function boolean istransactionconnected ()
public function string getname ()
public function long copyto (n_transaction atr_target)
public function long initialize (string as_dbms, string as_database, string as_logid, string as_logpass, string as_servername, string as_userid, string as_dbpass, string as_lock, string as_dbparm, boolean ab_autocommit)
public function long setname (string as_name)
public function long initialize (string as_dbms, string as_dbparm)
public function long setwarning (boolean ab_value)
public function long setusedatabaselogging (boolean ab_value)
public function long propagatelogsettings ()
public function long adderror (string as_methodname, string as_message)
end prototypes

public function long setdebug (boolean ab_state);////////////////////////////////////////////////////////////////
// Description:
//    Sets the debug property.  If TRUE it will allow debugging 
//    messages to be sent to the logging service
// Revisions
//    1.0   - Initial version
// Arguments:  
//    ab_state - The switch to enable/disable the property
// Returns:
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "setDebug "

// Validate arguments
If isNull(ab_state) Then
   addError (METHOD_NAME, "Invalid ab_state argument")
   Return -1
End If

ib_debug = ab_state

inv_log.setDebug( ib_debug )

Return 1
end function

public function long setdetailed (boolean ab_state);////////////////////////////////////////////////////////////////
// Description:
//    Sets the detailed property.  If TRUE it will allow detailed
//    tracing and debugging messages to be sent to the logging service
// Revisions
//    1.0   - Initial version
// Arguments:  
//    ab_state - The switch to enable/disable the property
// Returns:
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "setDetailed "

// Validate arguments
If isNull(ab_state) Then
   addError (METHOD_NAME, "Invalid ab_state argument")
   Return -1
End If

ib_detailed = ab_state

inv_log.setDetailed( ib_detailed )

Return 1
end function

public function long settrace (boolean ab_state);////////////////////////////////////////////////////////////////
// Description:
//    Sets the trace property.  If TRUE it will allow tracing 
//    messages to be sent to the logging service
// Revisions
//    1.0   - Initial version
// Arguments:  
//    ab_state - The switch to enable/disable the property
// Returns:
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "setTrace "

// Validate arguments
If isNull(ab_state) Then
   addError (METHOD_NAME, "Invalid ab_state argument")
   Return -1
End If

ib_trace = ab_state

inv_log.setTrace( ib_trace )

Return 1
end function

public function long transactionconnect ();////////////////////////////////////////////////////////////////
// Description:
//    Connects to a specified database
// Revisions
//    1.0   - Initial version
// Arguments:  
//    None
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "transactionConnect ()"

if IsValid(inv_log) then
   inv_log.traceLog (METHOD_NAME, "")
end if

// Declare local variables
long     ll_rc

if not allowtransactionflag then return 1

// Check if already connected
If this.dbhandle() > 0 Then
   If ib_debug And ib_detailed Then 
      inv_log.debugLog(METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG,"Already connected")
   End If      
   Return 1
End If

// Perform the actual connect
connect using this;
ll_rc = this.SQLCode
If ll_rc <> 0 Then
   addError(METHOD_NAME, "Failed to connect.~r~n"+ &
      "   Error code = "+string(this.sqlcode)+"~r~n"+ &
      "   Error text = "+this.sqlerrtext+"~r~n"+ &
      "   dbms =       "+this.dbms+"~r~n"+ &
      "   dbparm =     "+this.dbparm)
   Return -1
End If

Return 1
end function

public function long transactiondisconnect ();////////////////////////////////////////////////////////////////
// Description:
//    Disconnects from the specified database
// Revisions
//    1.0   - Initial version
// Arguments:  
//    None
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "transactionDisconnect "

if not allowtransactionflag then return 1

If (ib_trace or ib_debug) And ib_detailed Then
   string   ls_name
   ls_name = this.is_Name
   If Len (ls_name) = 0 Then ls_name = this.ClassName()  
   If ib_trace Then
      inv_log.traceLog (METHOD_NAME, "()   using " + ls_name)
   Else
      inv_log.debugLog (METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "()   using " + ls_name)      
   End If
End If   

// Declare local variables
long     ll_rc

If this.dbhandle() = 0 Then
   If ib_debug And ib_detailed Then 
      inv_log.debugLog(METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG,"Already disconnected")
   End If      
   Return 1
End If

disconnect using this;
ll_rc = this.SQLCode
If ll_rc <> 0 Then
   addError(METHOD_NAME, "Failed to connect.~r~n"+ &
      "   Error code = "+string(this.sqlcode)+"~r~n"+ &
      "   Error text = "+this.sqlerrtext+"~r~n"+ &
      "   dbms =       "+this.dbms+"~r~n"+ &
      "   dbparm =     "+this.dbparm)
   Return -1
End If

Return 1
end function

public function boolean istransactionconnected ();////////////////////////////////////////////////////////////////
// Description:
//    Reports on the status of the connection 
// Revisions
//    1.0   - Initial version
// Arguments:  
//    None
// Returns: 
//    True - Connected
//    False - Not connected 
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "isTransactionConnected "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "")
End If   

If this.DBHandle() = 0 Then
   Return false
End If

Return true

end function

public function string getname ();////////////////////////////////////////////////////////////////
// Description:
//    Reports on the transaction object a logical name
// Revisions
//    1.0   - Initial version
// Arguments:  
//    None
// Returns: 
//     The logical name of the transaction object
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "getName "

If ib_trace Then
   inv_log.traceLog (METHOD_NAME, "")
End If   

Return is_name
end function

public function long copyto (n_transaction atr_target);////////////////////////////////////////////////////////////////
// Description:
//    Copy the contents of this object to the passed in transaction
//    object.  
//
//    Not all connection object attributes are assignable.  Those
//    are commented out.
// Revisions
//    1.0   - Initial version
// Arguments:  
//    atr_target - The target transaction object
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////  
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "copyTo "

if IsValid(inv_log) then
   inv_log.traceLog (METHOD_NAME, "(atr_target)")
end if

// Validate arguments
If IsNull(atr_target) Or Not IsValid(atr_target) Then 
   addError(METHOD_NAME, "Invalid atr_target argument")
   Return -1
End If

// Copy the basic object attributes
atr_target.DBMS = this.DBMS
atr_target.Database = this.Database
atr_target.LogID = this.LogID
atr_target.LogPass = this.LogPass
atr_target.ServerName = this.ServerName
atr_target.UserID = this.UserID
atr_target.DBPass = this.DBPass
atr_target.Lock = this.Lock
atr_target.DbParm = this.DbParm
atr_target.Autocommit = this.Autocommit
atr_target.sqlcode = this.sqlcode
atr_target.sqldbcode = this.sqldbcode
atr_target.sqlnrows = this.sqlnrows
atr_target.sqlerrtext = this.sqlerrtext
atr_target.sqlreturndata = this.sqlreturndata

// Copy the value added attributes
atr_target.setName (is_name)

Return 1
end function

public function long initialize (string as_dbms, string as_database, string as_logid, string as_logpass, string as_servername, string as_userid, string as_dbpass, string as_lock, string as_dbparm, boolean ab_autocommit);////////////////////////////////////////////////////////////////
// Description:
//    Initializes transaction object (this) attributes with values
//    passed in.
// Revisions
//    1.0   - Initial version
// Arguments:  
//    Same as the standand transaction object's attributes.
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////  
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

// Sample code
//n_cst_objectservice   lnv_objservice
//
//lnv_objservice = create n_cst_objectservice
//
//lnv_objservice.getVariable( "com.youngsoft.application.dbcache.name", ls_cachename )
//lnv_objservice.getVariable( "com.youngsoft.application.dbcache.dbms", ls_dbms )
//lnv_objservice.getVariable( "com.youngsoft.application.dbcache.dbparm", ls_dbparm )
//
//Choose Case lower( left(ls_dbms,3) )
// Case "syj"
//    lnv_objservice.getVariable( "com.youngsoft.application.dbcache.database.name", ls_databasename )
// Case "odb"
//    
// Case "o84","o90"
//    
//End Choose
//
//ls_dbparm += "CacheName='" + ls_cachename + "',UseContextObject='yes',DisableBind=1"
//
//this.initialize( ls_dbms, ls_databasename, "", "", "", "", "", "", ls_dbparm, false )
//
//if isValid( lnv_objservice ) then
// destroy lnv_objservice
//end if

constant string METHOD_NAME = "initialize ( String, String, String, String, String, String, String, String, String, String )"

if IsValid(inv_log) then
   inv_log.traceLog( METHOD_NAME, "" )
   
   inv_log.debugLog (METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "(as_dbms, as_database, as_logid" +&
            "as_logpass, as_servername, as_userid, as_dbpass, as_lock, " +&
            "as_dbparm, ab_autocommit) ~r~n" +&
            "   as_dbms=     "+as_dbms+"~r~n" + &
            "   as_database= "+as_database+"~r~n" + &
            "   as_logid=    "+as_logid+"~r~n" + &
            "   as_logpass="+"****"+"~r~n" + &
            "   as_servername="+as_servername+"~r~n" + &
            "   as_userid="+as_userid+"~r~n" + &
            "   as_dbpass="+"****"+"~r~n" + &
            "   as_lock="+as_lock+"~r~n" + &
            "   as_dbparm="+as_dbparm+"~r~n" + &
            "   ab_autocommit="+string(ab_autocommit))
end if
         
// Perform cleanup
as_dbms = Trim(as_dbms)
as_database = Trim(as_database)
as_logid = Trim(as_logid)
as_logpass = Trim(as_logpass)
as_servername = Trim(as_servername)
as_userid = Trim(as_userid)
as_lock = Trim(as_lock)
as_dbparm = Trim(as_dbparm)

// Validate arguments
If IsNull(as_dbms) Or Len(as_dbms) = 0 Then
   addError(METHOD_NAME, "Invalid as_dbms argument")  
   Return -1   
End If
If IsNull(as_dbparm) Or Len(as_dbparm) = 0 Then
   addError(METHOD_NAME, "Invalid as_dbparm argument")   
   Return -1
End If
If IsNull(ab_autocommit) Then
   addError(METHOD_NAME, "Invalid ab_autocommit argument")  
   Return -1
End If

// Assign the attributes
this.DBMS= as_dbms
this.Database = as_database
this.LogID = as_logid
this.LogPass = as_logpass
this.ServerName = as_servername
this.UserID = as_userid
this.DBPass = as_dbpass
this.Lock = as_lock
this.DBParm = as_dbparm
this.AutoCommit = ab_autocommit

Return 1
end function

public function long setname (string as_name);////////////////////////////////////////////////////////////////
// Description:
//    Gives the transaction object a logical name
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_name - The new logical name
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "setName "

If ib_trace Then
   inv_log.traceLog (METHOD_NAME, "(as_name) " +&
         "as_name='"+as_name+"'")
End If   

// Validate arguments
If IsNull(as_name) Then 
   addError(METHOD_NAME, "Invalid as_name argument")
   Return -1
End If

is_name = as_name
Return 1
end function

public function long initialize (string as_dbms, string as_dbparm);////////////////////////////////////////////////////////////////
// Description:
//    Initializes transaction object (this) attributes with values
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_dbms : DBMS value
//    as_dbparm : DBPARM value
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////  
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "initialize ( String, String )"

if IsValid(inv_log) then
   inv_log.traceLog (METHOD_NAME, "")
end if

// Declare local variables
long  ll_method_rc

ll_method_rc = initialize(as_dbms, "", "", "", "", "", "", "", as_dbparm, false)

Return ll_method_rc
end function

public function long setwarning (boolean ab_value);////////////////////////////////////////////////////////////////
// Description:
//    Sets the warning variable
//    Required for the LogPropagation interface
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_error - The actual error messsage
// Returns:
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "setWarning( boolean value ) "

ib_warning = ab_value

inv_log.setWarning( ib_warning )

Return 1
end function

public function long setusedatabaselogging (boolean ab_value);////////////////////////////////////////////////////////////////
// Description:
//    Sets the warning variable
//    Required for the LogPropagation interface
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_error - The actual error messsage
// Returns:
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "setUseDatabaseLogging( boolean value ) "

ib_usedatabaselogging = ab_value

inv_log.setUseDatabaseLogging( ib_usedatabaselogging )

Return 1

end function

public function long propagatelogsettings ();////////////////////////////////////////////////////////////////
// Description:
//    Stub method to signal the completion of log settings to allow 
//    propagation to continue to other loggable objects
// Revisions
//    3.0   - Initial version
// Arguments:  
//    None
// Returns:
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "propagateLogSettings() "

inv_log.traceLog (METHOD_NAME, "")

inv_log.setTrace( ib_trace )
inv_log.setDebug( ib_debug )
inv_log.setDetailed( ib_detailed )
inv_log.setWarning( ib_warning )
inv_log.setUseDatabaseLogging( ib_usedatabaselogging )


return 1

end function

public function long adderror (string as_methodname, string as_message);////////////////////////////////////////////////////////////////
// Description:
//    Adds the error to the message stack and logs the error
//    Sets the last error variable for legacy code support
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_error - The actual error messsage
// Returns:
//     1 - Success
//    -1 - Failure
/////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

inv_log.addError(as_methodname, as_message, inv_messaging)


return 1

end function

on eaf_n_transaction.create
call super::create
TriggerEvent( this, "constructor" )
end on

on eaf_n_transaction.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on

event constructor;////////////////////////////////////////////////////////////////
// Description:
//    Occurs when the object is created
//    1.0   - Initial version
// Arguments:  
//    None
// Returns: 
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "constructor "

inv_constants = create n_cst_constants

// Tell the logging service who requested it
inv_log = create n_cst_loggingservice_base
inv_log.setRequestor(this)
inv_log.populateSettings()
setusedatabaselogging(false)

inv_messaging = create n_cst_messageservice
end event

event destructor;////////////////////////////////////////////////////////////////
// Description:
//    Occurs when the object is destroyed
//    1.0   - Initial version
// Arguments:  
//    None
// Returns: 
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

if isValid( inv_log ) then
   destroy inv_log
end if
   
if isValid( inv_messaging ) then
   destroy inv_messaging
end if
   
if isValid( inv_constants ) then
   destroy inv_constants
end if

end event