File: eaf_n_cst_dataaccessservice.sru
Size: 22446
Date: Tue, 22 Jan 2008 23:39:42 +0100
$PBExportHeader$eaf_n_cst_dataaccessservice.sru
forward
global type eaf_n_cst_dataaccessservice from n_cst_baseservice
end type
end forward

global type eaf_n_cst_dataaccessservice from n_cst_baseservice
string is_logservice = "n_cst_loggingservice"
event activate pbm_component_activate
event deactivate pbm_component_deactivate
end type
global eaf_n_cst_dataaccessservice eaf_n_cst_dataaccessservice

type variables
Protected:

n_cst_dberrorattrib        inv_dberror

end variables

forward prototypes
protected function long updateend (ref n_cst_dataaccessattrib anv_dataaccessattrib)
protected function long updatestart (ref n_cst_dataaccessattrib anv_dataaccessattrib)
protected function long retrieveend (ref n_cst_dataaccessattrib anv_dataaccessattrib)
public function long getlastdberror (ref n_cst_dberrorattrib anv_dberrorattrib)
public function long update (ref n_cst_dataaccessattrib anv_dataaccessattrib)
public function long getlastdberror (ref long al_sqldbcode, ref string as_message)
protected function long updatemain (ref n_cst_dataaccessattrib anv_dataaccessattrib)
protected function long retrievestart (ref n_cst_dataaccessattrib anv_dataaccessattrib)
protected function long retrievemain (ref n_cst_dataaccessattrib anv_dataaccessattrib)
public function long retrieve (ref n_cst_dataaccessattrib anv_dataaccessattrib)
end prototypes

protected function long updateend (ref n_cst_dataaccessattrib anv_dataaccessattrib);////////////////////////////////////////////////////////////////
// Description:
//    Invoked by the Framework from the update().
//    Occurs when the Update is complete.
// Revisions
//    1.0   - Initial version
// Arguments:  
//    anv_dataaccessattrib - Includes: 
//                Identification of a dataset being updated
//                A datastore which holds data to be updated
//                Any other "custom" values or object
// Returns: 
//     1 - Success - Continue Action
//    -1 - Failure - Fail the update process
////////////////////////////////////////////////////////////////
// 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 = "updateEnd ( REF n_cst_dataaccessattrib )"

inv_log.traceLog (METHOD_NAME, "")

Return 1

end function

protected function long updatestart (ref n_cst_dataaccessattrib anv_dataaccessattrib);////////////////////////////////////////////////////////////////
// Description:
//    Invoked by the Framework from the update().
//    Occurs when the Update process is about to begin
// Revisions
//    1.0   - Initial version
// Arguments:  
//    anv_dataaccessattrib - Includes: 
//                Identification of a dataset being updated
//                A datastore which holds data to be updated
//                Any other "custom" values or object
// Returns: 
//     2 - Success - Update has been performed (skip update process)
//     1 - Success - Continue Action
//     0 - Do not perform the update
//    -1 - Failure - Do not perform the update
////////////////////////////////////////////////////////////////
// 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 = "updateStart ( REF n_cst_dataaccessattrib )"

inv_log.traceLog (METHOD_NAME, "")

Return 1
end function

protected function long retrieveend (ref n_cst_dataaccessattrib anv_dataaccessattrib);////////////////////////////////////////////////////////////////
// Description:
//    Invoked by the Framework from the retrieve().
//    Occurs when the Retrieval is complete.
// Revisions
//    1.0   - Initial version
// Arguments:  
//    anv_dataaccessattrib - Includes: 
//                Identification of a dataset being retrieved
//                A datastore on which to perform a retrieve
//                The Arguments to apply on the datastore
//                Any other "custom" values or object
// Returns: 
//     1 - Success - Continue Action
//    -1 - Failure - Fail the retrieval process
////////////////////////////////////////////////////////////////
// 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 = "retrieveEnd ( REF n_cst_dataaccessattrib )"

inv_log.traceLog (METHOD_NAME, "")

Return 1
end function

public function long getlastdberror (ref n_cst_dberrorattrib anv_dberrorattrib);////////////////////////////////////////////////////////////////
// Description:
//    Gets the last known dberror from the dberror event. (if any) 
// Revisions
//    1.0   - Initial version
// Arguments:  
//    anv_dberrorattrib - Place holder to hold the last known error
// Returns: 
//     1 - Success
//     0 - No error was stored
//    -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 = "getLastDBError "

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

// Declare local variables
n_cst_dberrorattrib  lnv_dberror

// Validate required references
If isNull(inv_dberror) Or Not isValid(inv_dberror) Then
   addError (METHOD_NAME, "Invalid inv_dberror reference")
   Return -1
End If

// See if there is an error
If len(inv_dberror.is_message) = 0 Then
   Return 0
End If

// Pass back a copy of the error object
lnv_dberror = inv_dberror
anv_dberrorattrib = lnv_dberror
Return 1
end function

public function long update (ref n_cst_dataaccessattrib anv_dataaccessattrib);////////////////////////////////////////////////////////////////
// Description:
//    Update the passed in object(s) found on the Attribute object
// Revisions
//    1.0   - Initial version
// Arguments:  
//    anv_dataaccessattrib - Includes: 
//                Identification of a dataset being updated
//                A datastore which holds data to be updated
//                Any other "custom" values or object
// Returns: 
//     # of rows populated
//    -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 = "update ( REF n_cst_dataaccessattrib )"

inv_log.traceLog (METHOD_NAME, "")
 
// Declare local variables 
long           ll_start_rc
long           ll_end_rc
long           ll_rc

// Validate arguments
If IsNull(anv_dataaccessattrib) Or Not IsValid(anv_dataaccessattrib) Then
   addError (METHOD_NAME, "Invalid anv_dataaccessattrib argument")
   Return -1
End If
If IsNull(anv_dataaccessattrib.is_identifier) Then 
   addError(METHOD_NAME, "Invalid NULL anv_dataaccessattrib.is_identifier argument")
   Return -1
End If
If IsNull(anv_dataaccessattrib.ids_data) Or Not isValid(anv_dataaccessattrib.ids_data) Then
   addError(METHOD_NAME, "Invalid anv_dataaccessattrib.ids_data argument")
   Return -1   
End If

// Invoke the Start processing method
ll_start_rc = updateStart(anv_dataaccessattrib)

If ll_start_rc < 0 Then 
   addError(METHOD_NAME, "Operation updateStart() failed with RC="+string(ll_start_rc))
   Return -1
ElseIf ll_start_rc = 0 Then
   If ib_debug or ib_warning Then 
      inv_log.warningLog(METHOD_NAME, "Operation updateStart() has cancelled update operation RC="+string(ll_start_rc))
   End If      
   Return -1   
End if

// Invoke the Main processing (skipped if ll_start_rc =2 )
If ll_start_rc = 1 Then
   ll_rc = updateMain(anv_dataaccessattrib)
   If ll_rc < 0 Then 
      addError(METHOD_NAME, "Operation updateMain() failed with RC="+string(ll_start_rc))
      Return -1
   End if   
End If   
   
// Invoke the End processing method
ll_end_rc = updateEnd(anv_dataaccessattrib)
If ll_end_rc < 0 Then
   addError(METHOD_NAME, "Invalid updateEnd operation")
   Return -1   
End If

Return 1
end function

public function long getlastdberror (ref long al_sqldbcode, ref string as_message);////////////////////////////////////////////////////////////////
// Description:
//    Gets the last known dberror from the dberror event. (if any) 
// Revisions
//    1.0   - Initial version
// Arguments:  
//    al_sqldbcode   - Place holder to hold the last known sqldbcode
//    as_message     - Place holder to hold the last known message
// Returns: 
//     1 - Success
//     0 - No error was stored
//    -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 = "getLastDBError "

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

// Validate required references
If isNull(inv_dberror) Or Not isValid(inv_dberror) Then
   addError (METHOD_NAME, "Invalid inv_dberror reference")
   Return -1
End If

// See if there is an error
If len(inv_dberror.is_message) = 0 Then
   Return 0
End If

// Pass the contents of the error object
al_sqldbcode =  inv_dberror.il_sqldbcode
as_message =  inv_dberror.is_message
Return 1
end function

protected function long updatemain (ref n_cst_dataaccessattrib anv_dataaccessattrib);////////////////////////////////////////////////////////////////
// Description:
//    Invoked by the Framework from the update().
//    The Main Update process where the actual update occurrs
// Revisions
//    1.0   - Initial version
// Arguments:
//    anv_dataaccessattrib - Includes: 
//                Identification of a dataset being updated
//                A datastore which holds data to be updated
//                Any other "custom" values or 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 = "updateMain ( REF n_cst_dataaccessattrib )"

inv_log.traceLog (METHOD_NAME, "")
 
// Declare local variables 
long           ll_rc

// Validate arguments
If IsNull(anv_dataaccessattrib) Or Not IsValid(anv_dataaccessattrib) Then
   addError (METHOD_NAME, "Invalid anv_dataaccessattrib argument")
   Return -1
End If
If IsNull(anv_dataaccessattrib.is_identifier) Then 
   addError(METHOD_NAME, "Invalid NULL anv_dataaccessattrib.is_identifier argument")
   Return -1
End If
If IsNull(anv_dataaccessattrib.ids_data) Or Not isValid(anv_dataaccessattrib.ids_data) Then
   addError(METHOD_NAME, "Invalid anv_dataaccessattrib.ids_data argument")
   Return -1   
End If

// Perform the actual datastore update
ll_rc = anv_dataaccessattrib.ids_data.update(true,false)
If isNull(ll_rc) Or ll_rc <= 0 Then
   // Get the last  DB error
   anv_dataaccessattrib.ids_data.getLastDBError(inv_dberror)

   //append error message to message service
   inv_messaging.append( anv_dataaccessattrib.ids_data.inv_messaging )
   
   addError(METHOD_NAME, "Failed to update data using anv_dataaccessattrib.ids_data, identifier = " + anv_dataaccessattrib.is_identifier)
   Return -1
End If
   
Return 1
end function

protected function long retrievestart (ref n_cst_dataaccessattrib anv_dataaccessattrib);////////////////////////////////////////////////////////////////
// Description:
//    Invoked by the Framework from the retrieve().
//    Occurs when the Retrieval process is about to begin
// Revisions
//    1.0   - Initial version
// Arguments:  
//    anv_dataaccessattrib - Includes: 
//                Identification of a dataset being retrieved
//                A datastore on which to perform a retrieve
//                The Arguments to apply on the datastore
//                Any other "custom" values or object
// Returns: 
//     2 - Success - Retrieval has been performed (skip retrieval process)
//     1 - Success - Continue Action
//     0 - Do not perform the retrieval
//    -1 - Failure - Do not perform the retrieval
////////////////////////////////////////////////////////////////
// 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 = "retrieveStart ( REF n_cst_dataaccessattrib )"

inv_log.traceLog (METHOD_NAME, "")

Return 1

end function

protected function long retrievemain (ref n_cst_dataaccessattrib anv_dataaccessattrib);////////////////////////////////////////////////////////////////
// Description:
//    Invoked by the Framework from the retrieve().
//    The Main Retrieve process where the actual retrieve occurrs
// Revisions
//    1.0   - Initial version
// Arguments:  
//    anv_dataaccessattrib - Includes: 
//                Identification of a dataset being retrieved
//                A datastore on which to perform a retrieve
//                The Arguments to apply on the datastore
//                Any other "custom" values or 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 = "retrieveMain ( REF n_cst_dataaccessattrib )"

inv_log.traceLog (METHOD_NAME, "")

// Declare local variables
constant       long     MAX_ARGUMENTS = 20

string                  ls_runtimeerror
any                     la_args[20]
long                    ll_rc
long                    ll_upper
long                    ll_idx
long                    ll_row
string                  ls_oldsql, ls_sql
n_cst_helperservice     lnvo_helper

try
   
   // Validate arguments
   If IsNull(anv_dataaccessattrib) Or Not IsValid(anv_dataaccessattrib) Then
      addError (METHOD_NAME, "Invalid anv_dataaccessattrib argument")
      Return -1
   End If
   If IsNull(anv_dataaccessattrib.is_identifier) Then 
      addError(METHOD_NAME, "Invalid NULL anv_dataaccessattrib.is_identifier argument")
      Return -1
   End If
   If IsNull(anv_dataaccessattrib.ids_data) Or Not IsValid(anv_dataaccessattrib.ids_data) Then
      addError (METHOD_NAME, "Invalid anv_dataaccessattrib.ids_data argument")
      Return -1
   End If
   
   // Validate the number of arguments
   ll_upper = upperBound(anv_dataaccessattrib.ia_args)
   If ll_upper > MAX_ARGUMENTS Then 
      addError (METHOD_NAME, "Maximum number of arguments supported is "+ &
         string(MAX_ARGUMENTS))
      Return -1   
   End If   
   
   
   // Get into the padded array
   For ll_idx = 1 to ll_upper
      la_args[ll_idx] = anv_dataaccessattrib.ia_args[ll_idx]
      inv_log.debugLog( METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "Argument " + string(ll_idx) + ":" + string( la_args[ll_idx] ) )
   Next
   
   if ll_upper = 0 and anv_dataaccessattrib.is_querywhere <> "" then
      lnvo_helper = create n_cst_helperservice
      ls_oldsql = anv_dataaccessattrib.ids_data.GetSqlSelect()
      ls_sql = lnvo_helper.modifyselectsqlwhere(ls_oldsql, anv_dataaccessattrib.is_querywhere)
      if anv_dataaccessattrib.ids_data.SetSqlSelect(ls_sql) = -1 then
         addError(METHOD_NAME, "Failed anv_dataaccessattrib.ids_data.SetSqlSelect(), sql= " + ls_sql)
         Return -1   
      end if
   end if
   
   // Perform the actual datastore retrieve
   ll_rc = anv_dataaccessattrib.ids_data.retrieve( &
         la_args[1],la_args[2],la_args[3],la_args[4],la_args[5], &
         la_args[6],la_args[7],la_args[8],la_args[9],la_args[10], &
         la_args[11],la_args[12],la_args[13],la_args[14],la_args[15], &
         la_args[16],la_args[17],la_args[18],la_args[19],la_args[20])
   
   if ls_oldsql <> "" then
      anv_dataaccessattrib.ids_data.SetSqlSelect(ls_oldsql)
   end if
   
   inv_log.debugLog( METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "Result of retrieve: " + string( ll_rc ) )
   
   If isNull(ll_rc) Or ll_rc < 0 Then
      // Get the last  DB error
      anv_dataaccessattrib.ids_data.getLastDBError(inv_dberror)
      inv_messaging.append( anv_dataaccessattrib.ids_data.inv_messaging )
      addError(METHOD_NAME, "Failed anv_dataaccessattrib.ids_data.retrieve() " + &
         "operation RC="+string(ll_rc))
      Return -1   
   End If
   
catch ( RuntimeError re )
   
   ls_runtimeerror = "Runtime Error:" + inv_constants.CRLF + inv_constants.CRLF
   ls_runtimeerror += "Error Code: " + string(re.number) + inv_constants.CRLF
   ls_runtimeerror += "Object: " + re.objectName + inv_constants.CRLF
   ls_runtimeerror += "Class: " + re.class + inv_constants.CRLF
   ls_runtimeerror += "Function/Event: " + re.routineName + inv_constants.CRLF
   ls_runtimeerror += "Line: " + string(re.line) + inv_constants.CRLF
   ls_runtimeerror += "Message: " + re.getMessage() + inv_constants.CRLF
   
   AddError(METHOD_NAME, "Runtime Error: " + ls_runtimeerror)

   return -1
   
finally

   if IsValid(lnvo_helper) then
      destroy lnvo_helper
   end if
   
end try



Return 1
end function

public function long retrieve (ref n_cst_dataaccessattrib anv_dataaccessattrib);////////////////////////////////////////////////////////////////
// Description:
//    Populate the passed in object(s) found on Attribute object 
//
//    Contains Start and End processing
// Revisions
//    1.0   - Initial version
// Arguments:  
//    anv_dataaccessattrib - Includes: 
//                Identification of a dataset being retrieved
//                A datastore on which to perform a retrieve
//                The Arguments to apply on the datastore
//                Any other "custom" values or object
// Returns: 
//     1 - Success (even if there were no rows populated)
//    -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 = "retrieve ( REF n_cst_dataaccessattrib )"

inv_log.traceLog (METHOD_NAME, "")

// Declare local variables
long     ll_rc
long     ll_start_rc
long     ll_end_rc
long     ll_upper
long     ll_idx
long     ll_sqldbcode

// Validate arguments
If IsNull(anv_dataaccessattrib) Or Not IsValid(anv_dataaccessattrib) Then
   addError (METHOD_NAME, "Invalid anv_dataaccessattrib argument")
   Return -1
End If
If IsNull(anv_dataaccessattrib.is_identifier) Then 
   addError(METHOD_NAME, "Invalid NULL anv_dataaccessattrib.is_identifier argument")
   Return -1
End If
If IsNull(anv_dataaccessattrib.ids_data) Or Not IsValid(anv_dataaccessattrib.ids_data) Then
   addError (METHOD_NAME, "Invalid anv_dataaccessattrib.ids_data argument")
   Return -1
End If

// Get bound arguments from argument service if ia_args is empty
if ( upperBound( anv_dataaccessattrib.ia_args ) = 0 ) then
   if ( anv_dataaccessattrib.inv_argumentservice.getBoundArguments(anv_dataaccessattrib.ia_args) = -1 ) then
      addError( METHOD_NAME, "anv_dataaccessattrib.inv_argumentservice.getBoundArguments() failed. " )
   end if
end if

// Get querywhere arguments from argument service if ia_args is empty
if upperBound( anv_dataaccessattrib.ia_args ) = 0 and anv_dataaccessattrib.is_querywhere = "" then
   anv_dataaccessattrib.inv_argumentservice.getArgument("querywhere", anv_dataaccessattrib.is_querywhere)
end if

// Invoke the Start processing method
ll_start_rc = this.retrieveStart(anv_dataaccessattrib)
If ll_start_rc < 0 Then
   addError (METHOD_NAME, "Operation retrieveStart()failed with RC="+string(ll_start_rc))
   Return -1   
ElseIf ll_start_rc = 0 Then
   If ib_debug or ib_warning Then
      inv_log.warningLog(METHOD_NAME, "Call to retrieveStart() has cancelled retrieve operation RC="+string(ll_start_rc))
   End If
   Return -1
End If

// Invoke the Main processing (skipped if ll_updatestart_rc =2 )
If ll_start_rc = 1 Then
   ll_rc = this.retrieveMain(anv_dataaccessattrib)
   If ll_rc < 0 Then
      addError (METHOD_NAME, "Operation retrieveMain()failed with RC="+string(ll_start_rc))
      Return -1   
   End If   
End If   
      
// Invoke the End processing method
ll_end_rc = this.retrieveEnd(anv_dataaccessattrib)
If ll_end_rc <=0 Then
   addError (METHOD_NAME, "Call to retrieveEnd() returned with error condition")
   Return -1
End If

Return 1
end function

on eaf_n_cst_dataaccessservice.create
call super::create
end on

on eaf_n_cst_dataaccessservice.destroy
call super::destroy
end on

event constructor;call super::constructor;////////////////////////////////////////////////////////////////
// Description:
//    Occurs when the object is created
// Revisions
//    1.0   - Initial version
// Arguments:  
//    None
// Returns: 
////////////////////////////////////////////////////////////////

inv_dberror = create n_cst_dberrorattrib        

end event

event destructor;call super::destructor;////////////////////////////////////////////////////////////////
// Description:
//    Occurs when the object is destroyed
// Revisions
//    1.0   - Initial version
// Arguments:  
//    None
// Returns: 
////////////////////////////////////////////////////////////////

if isValid( inv_dberror ) then
   destroy inv_dberror
end if

end event