File: eaf_n_cst_updatemanager.sru
Size: 14722
Date: Tue, 22 Jan 2008 23:40:27 +0100
$PBExportHeader$eaf_n_cst_updatemanager.sru
forward
global type eaf_n_cst_updatemanager from n_cst_baseservice
end type
end forward

global type eaf_n_cst_updatemanager from n_cst_baseservice
end type
global eaf_n_cst_updatemanager eaf_n_cst_updatemanager

type variables
n_cst_argumentservice               inv_argument

end variables

forward prototypes
public function long update (ref n_datastore ads_working[])
public function long update (ref n_datastore ads_working1, ref n_datastore ads_working2, ref n_datastore ads_working3)
public function long update (ref n_datastore ads_working1, ref n_datastore ads_working2)
public function long update (ref n_datastore ads_working)
public function long dostatus (string as_requesttype, string as_tablename, long al_id[])
public function long executeservice (string as_servicename)
public function long dostatus (string as_requesttype, string as_tablename, long al_id)
end prototypes

public function long update (ref n_datastore ads_working[]);////////////////////////////////////////////////////////////////
// Description:
//    Perform an update according to the information passed in
//    through the InterfaceStructure
// Arguments:  
//    s_mimerequest - The data that needs to be updated
// Returns: 
//     1 - Success
//     0 - Nothing to update
//    -1 - Failure

constant string METHOD_NAME = "update (REF s_mimerequest)"

// Declare local variables
long                                   ll_rc
long                                   ll_row, ll_row1, ll_seq, ll_index
string                                 ls_runtimeerror, ls_autocodecolumn, ls_trno[], ls_trnos
string                                 ls_coltype, ls_document, ls_id[], ls_null[], ls_idcolumn, ls_ids
s_mimerequest                          lstr_mimerequest
n_cst_InterfaceManager                 lnvo_interfaceManager
n_cst_argumentservice                  lnv_dsargument[]
n_cst_messageservice                   lnv_dsmessaging[]
n_cst_stringservice                    lnvo_string

try

   lnvo_string  = create n_cst_stringservice

   lnvo_interfaceManager = create n_cst_InterfaceManager
   
   for ll_row = 1 to UpperBound(ads_working)
      
      //set seq order 
      if ads_working[ll_row].Describe("DataWindow.Table.UpdateTable") <> "mistrno" then
         ls_coltype = ads_working[ll_row].Describe("seq.coltype")
         choose case ls_coltype
            case 'number', 'long', 'int', 'integer', 'smallint', 'serial', 'real'
               for ll_row1 = 1 to ads_working[ll_row].RowCount()
                  ll_seq = ads_working[ll_row].GetItemNumber(ll_row1, "seq")
                  if IsNull(ll_seq) then ll_seq = 0
                  if ll_seq <> ll_row1 then
                     ads_working[ll_row].SetItem(ll_row1, "seq", ll_row1)
                  end if
               next
         end choose
      end if
      
      // Modify update property
      // Set Where Clause as key column
      ads_working[ll_row].Modify("DataWindow.Table.updatewhere=0")
      // Set Key Modification as Use Update
      ads_working[ll_row].Modify("DataWindow.Table.updatekeyinplace=yes")  

      lnv_dsargument[ll_row] = create n_cst_argumentservice
      
      //Assign the DataSet name
      lstr_mimerequest.datasets[ll_row].name = ClassName(ads_working[ll_row])

      //Get the mime type
      lstr_mimerequest.datasets[ll_row].mimetype = inv_constants.MIME_TYPE_DW_NATIVE
      
      //Assign the Update Action
      lnv_dsargument[ll_row].addArgument( inv_constants.EAF_UPDATE_ACTION_TYPE_ARGUMENT_NAME, inv_constants.UPDATE_SENDALL )
      
      //Extract the data for update
      ll_rc = ads_working[ll_row].GetFullState ( lstr_mimerequest.datasets[ll_row].data.binary )
      if ll_rc < 0 then
         addError( METHOD_NAME,  "Failed to get the state for ID='" + lstr_mimerequest.datasets[ll_row].name  + "'") 
         return -1
      end if

      //Extract arguments from ArgumentService for EAF update processing
      lnv_dsargument[ll_row].toXML( ls_document )
      lstr_mimerequest.datasets[ll_row].arguments = ls_document      
   next
   
   inv_argument.addargument(inv_constants.REQUESTTYPE_ARGUMENT_NAME , "update")

   //Get the request level arguments
   inv_argument.toXML( lstr_mimerequest.messages )
      
   ll_rc = lnvo_interfaceManager.update(lstr_mimerequest)
   
   destroy lnvo_interfaceManager

   //Place the InterfaceManager messages into the updatemanager messaging
   inv_messaging.reset()
   inv_messaging.parse( lstr_mimerequest.messages )
   
   //Append error message to message object service
   if ll_rc = -1 then
      for ll_row = 1 to UpperBound(ads_working)
         inv_messaging.parse( lstr_mimerequest.datasets[ll_row].messages )
      next
   end if
   
   for ll_row = 1 to UpperBound(ads_working)
      
      lnv_dsmessaging[ll_row] = create n_cst_messageservice
      
      lnv_dsmessaging[ll_row].parse( lstr_mimerequest.datasets[ll_row].messages )
      
      // Set ID
      if lnv_dsmessaging[ll_row].GetMessageText("identitycolumn", ls_idcolumn) = 1 then
         lnv_dsmessaging[ll_row].GetMessageText(ls_idcolumn, ls_ids)
         ls_id = ls_null
         lnvo_string.parsestringtoarray(ls_ids, ",", ls_id)
         if UpperBound(ls_id) > 0 then
            ll_index = 0
            for ll_row1 = 1 to ads_working[ll_row].RowCount()
               if ads_working[ll_row].GetItemStatus(ll_row1, 0, Primary!) = NewModified! then
                  ll_index ++
                  if ll_index > UpperBound(ls_id) then
                     addError( METHOD_NAME,  "Failed to get the return identity ID for ID='" + lstr_mimerequest.datasets[ll_row].name  + "'")
                  end if
                  ads_working[ll_row].SetItem(ll_row1, ls_idcolumn, Long(ls_id[ll_index]))
               end if
            next
         end if
      end if
      
      // Set trno
      if lnv_dsmessaging[ll_row].GetMessageText("autocodecolumn", ls_autocodecolumn) = 1 then
         lnv_dsmessaging[ll_row].GetMessageText(ls_autocodecolumn, ls_trnos)
         ls_trno = ls_null
         lnvo_string.parsestringtoarray(ls_trnos, ",", ls_trno)
         if UpperBound(ls_trno) > 0 then
            ll_index = 0
            for ll_row1 = 1 to ads_working[ll_row].RowCount()
               if ads_working[ll_row].GetItemStatus(ll_row1, 0, Primary!) = NewModified! then
                  ll_index ++
                  if ll_index > UpperBound(ls_trno) then
                     addError( METHOD_NAME,  "Failed to get the return Auto Document Code for ID='" + lstr_mimerequest.datasets[ll_row].name  + "'")
                  end if
                  ads_working[ll_row].SetItem(ll_row1, ls_autocodecolumn, ls_trno[ll_index])
               end if
            next
         end if
      end if
      
      // Perform a resetUpdate operation to clear out internal flags
      ads_working[ll_row].ResetUpdate()
      
   next

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
   
   return -1
   
finally
   
   for ll_row = 1 to UpperBound(lnv_dsargument)
      if IsValid(lnv_dsargument[ll_row]) then
         destroy lnv_dsargument[ll_row]
      end if
   next
   
   for ll_row = 1 to UpperBound(lnv_dsmessaging)
      if IsValid(lnv_dsmessaging[ll_row]) then
         destroy lnv_dsmessaging[ll_row]
      end if
   next
   
   if IsValid(lnvo_string) then
      destroy lnvo_string
   end if
   
end try

return ll_rc
end function

public function long update (ref n_datastore ads_working1, ref n_datastore ads_working2, ref n_datastore ads_working3);n_datastore lds_working[]

lds_working[1] = ads_working1
lds_working[2] = ads_working2
lds_working[3] = ads_working3

return Update(lds_working)
end function

public function long update (ref n_datastore ads_working1, ref n_datastore ads_working2);n_datastore lds_working[]

lds_working[1] = ads_working1
lds_working[2] = ads_working2

return Update(lds_working)
end function

public function long update (ref n_datastore ads_working);n_datastore lds_working[]

lds_working[1] = ads_working

return Update(lds_working)
end function

public function long dostatus (string as_requesttype, string as_tablename, long al_id[]);////////////////////////////////////////////////////////////////
// Description:
//    Performs a execute status process according to the information passed through the MIME Request object
// Revisions
//    3.0   - Initial version
// Arguments:  
//    astr_mimerequest - REF
// 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 = "dostatus (REF s_mimerequest)"

inv_log.traceLog (METHOD_NAME, "")

// Declare local variables
string                              ls_runtimeerror
string                              ls_classname
String                              ls_InterfaceManagerName, ls_userid, ls_languageid
Long                                ll_ret
n_cst_commitobject                  lnvo_commit
ClassDefinition                     lclassdef
n_cst_stringservice                 lnvo_string

try
   
   if as_tablename = "" then
      addError( METHOD_NAME, "Faild to get valid table name for execute status processing" )
      return -1
   end if

   ls_classname = inv_constants.COMMIT_CLASSNAME_PREFIX + "_" + as_tablename
   lclassdef = FindClassDefinition(lower(ls_classname))
   if ISNULL(lclassdef) then
      addError( METHOD_NAME, "Faild to find valid NVO class for " + ls_classname)
      return -1
   end if
   
   lnvo_commit = create using ls_classname
   
   //Set Component Name
   inv_argument.getArgument( inv_constants.EAF_INTERFACEMANAGER_COMPONENT_ARGUMENT_NAME, ls_InterfaceManagerName )
   lnvo_commit.SetComponentName(ls_InterfaceManagerName)

   //Get User ID
   inv_argument.getArgument( inv_constants.EAF_USERID_ARGUMENT_NAME, ls_userid)
   lnvo_commit.SetUserName(ls_userid)
   
   //Get LanguageID
   inv_argument.getArgument( inv_constants.EAF_LANGUAGEID_ARGUMENT_NAME, ls_languageid )
   lnvo_commit.SetLanguageID(Long(ls_languageid))
   
   choose case Upper(as_requesttype)
      case "COMMIT"
         ll_ret = lnvo_commit.docommit(al_id)
      case "ROLLBACK"
         ll_ret = lnvo_commit.dorollback(al_id)
      case "CLOSE"
         ll_ret = lnvo_commit.close(al_id)
      case "CLOSEROLLBACK"
         ll_ret = lnvo_commit.closerollback(al_id)
      case else
         addError(METHOD_NAME, "Invalid request type: " + as_requesttype )
         return -1
   end choose
   
   if ll_ret = -1 then
      inv_messaging.append( lnvo_commit.inv_messaging )
      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
   addError( METHOD_NAME, "Runtime Error: " + ls_runtimeerror )
   
   return -1
   
finally
   
   if IsValid(lnvo_string) then
      destroy lnvo_string
   end if

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

return 1

end function

public function long executeservice (string as_servicename);////////////////////////////////////////////////////////////////
// Description:
//    Performs a execute service according to the information passed through the MIME Request object
// Revisions
//    3.0   - Initial version
// Arguments:  
//    astr_mimerequest - REF
// 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 = "executeservice (REF s_mimerequest)"

inv_log.traceLog (METHOD_NAME, "")

// Declare local variables
string                              ls_runtimeerror
string                              ls_classname
String                              ls_interfacemanagername, ls_userid, ls_languageid
Long                                ll_ret
n_cst_businessservice               lnvo_service
ClassDefinition                     lclassdef
s_mimerequest                       lstr_mimerequest

try
   
   ls_classname = inv_constants.BUSINESS_SERVICE_CLASSNAME_PREFIX + "_" + as_servicename
   lclassdef = FindClassDefinition(lower(ls_classname))
   if ISNULL(lclassdef) then
      addError( METHOD_NAME, "Faild to find valid NVO class for " + ls_classname)
      return -1
   end if
   
   lnvo_service = create using ls_classname
   
   
   //Set Component Name
   inv_argument.getArgument( inv_constants.EAF_INTERFACEMANAGER_COMPONENT_ARGUMENT_NAME, ls_InterfaceManagerName )
   lnvo_service.SetComponentName(ls_InterfaceManagerName)

   //Get User ID
   inv_argument.getArgument( inv_constants.EAF_USERID_ARGUMENT_NAME, ls_userid)
   lnvo_service.SetUserName(ls_userid)
   
   //Get LanguageID
   inv_argument.getArgument( inv_constants.EAF_LANGUAGEID_ARGUMENT_NAME, ls_languageid )
   lnvo_service.SetLanguageID(Long(ls_languageid))

   //Get the request level arguments
   inv_argument.toXML( lstr_mimerequest.messages )

   ll_ret = lnvo_service.process(lstr_mimerequest)

   if ll_ret = -1 then
      inv_messaging.append( lnvo_service.inv_messaging )
      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
   addError( METHOD_NAME, "Runtime Error: " + ls_runtimeerror )
   
   return -1
   
finally
   

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

return 1

end function

public function long dostatus (string as_requesttype, string as_tablename, long al_id);Long ll_id[]

ll_id[1] = al_id

return dostatus(as_requesttype, as_tablename, ll_id)
end function

on eaf_n_cst_updatemanager.create
call super::create
end on

on eaf_n_cst_updatemanager.destroy
call super::destroy
end on

event constructor;call super::constructor;//Create the instance services
inv_argument = create n_cst_argumentservice

end event

event destructor;call super::destructor;if isValid( inv_argument ) then
   destroy inv_argument
end if

end event