File: eaf_n_cst_dataset.sru
Size: 72907
Date: Tue, 22 Jan 2008 23:40:20 +0100
$PBExportHeader$eaf_n_cst_dataset.sru
forward
global type eaf_n_cst_dataset from n_cst_baseservice
end type
end forward

global type eaf_n_cst_dataset from n_cst_baseservice
string is_logservice = "n_cst_loggingservice"
long il_languageid = 0
string is_crlf = ""
end type
global eaf_n_cst_dataset eaf_n_cst_dataset

type variables
Protected:

constant string               DATAACCESS_BASE =                               "n_cst_dataaccessservice"
constant string               DATASTORE_BASE =                                "n_datastore"

constant string               CHILD_ARGUMENT_ELEMENT_NAME =                   "EAFChildArgument"
constant string               CHILD_ARGUMENT_CHILD_NAME_ELEMENT_NAME =        "EAFChildArgumentChildName"
constant string               CHILD_ARGUMENT_NAME_ELEMENT_NAME =              "EAFChildArgumentName"
constant string               CHILD_ARGUMENT_VALUE_ELEMENT_NAME =             "EAFChildArgumentValue"
constant string               CHILD_ARGUMENT_ISNULL_ELEMENT_NAME =            "EAFChildArgumentIsNull"


string                        is_dataobjects[]
long                          il_languages[]
string                        is_dataaccessservice =                          "n_cst_dataaccessservice"
string                        is_datastore =                                  "n_datastore"
string                        is_sessionid =                                  ""

string                        is_retrieveaction
string                        is_languagepropertyname =                       ""

n_cst_htmldwservice           inv_htmldw
n_cst_stringservice           inv_string
n_cst_dataaccessservice       inv_dataaccess
n_cst_objectservice           inv_objecthelper
n_cst_dberrorattrib           inv_dberror

string                        is_componentname

string                        is_username
end variables

forward prototypes
public function long getlastdberror (ref long al_sqldbcode, ref string as_message)
public function long getlastdberror (ref n_cst_dberrorattrib anv_dberrorattrib)
public function long setdataaccess (n_cst_dataaccessservice anv_dataaccess)
public function long setdatastore (string as_datastore)
public function integer setretrieveaction (string as_action)
protected function string getretrieveaction ()
public function long setdataaccess (string as_dataaccess)
public function long propagatelogsettings ()
public function long retrievechildend (string as_columnname, ref datawindowchild adwc_working, ref n_cst_datasetattrib anv_datasetattrib)
public function long retrievechildstart (string as_columnname, ref datawindowchild adwc_working, ref n_cst_datasetattrib anv_datasetattrib)
public function long retrievechildmain (string as_columnname, ref datawindowchild adwc_working, ref n_cst_datasetattrib anv_datasetattrib)
public function long retrievechild (string as_columnname, ref datawindowchild adwc_working, ref n_cst_datasetattrib anv_datasetattrib)
protected function long retrieveend (ref n_cst_datasetattrib anv_datasetattrib)
protected function long retrievestart (ref n_cst_datasetattrib anv_datasetattrib)
protected function long retrievemain (ref n_cst_datasetattrib anv_datasetattrib)
public function long retrieve (ref n_cst_datasetattrib anv_datasetattrib)
public function long retrievechildren (ref n_cst_datasetattrib anv_datasetattrib)
public function long setdataobject (string as_dataobject)
public function long setsessionid (string as_sessionid)
public function long createcontentbegin (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset)
public function long createcontentend (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset)
public function long updatebetweenbo (ref n_cst_datasetattrib anv_datasetattrib, long al_boidx)
public function long update (n_cst_datasetattrib anv_datasetattrib)
protected function long updateend (n_cst_datasetattrib anv_datasetattrib)
protected function long updatemain (n_cst_datasetattrib anv_datasetattrib)
protected function long updatestart (n_cst_datasetattrib anv_datasetattrib)
public subroutine dberror (ref n_cst_datasetattrib anv_datasetattrib)
public function long replacedataobject (string as_dataobject, long al_languageid)
public function long replacedataobject (string as_dataobject)
public function long setlanguageid (long al_languageid)
public function string getcomponentname ()
public subroutine setcomponentname (string as_componentname)
public function long getdefaultupdatebonames (string as_datasetid, datastore ads_working, ref string as_updateboname[])
public function long getdataobject (ref string as_dataobject)
public function string getusername ()
public function long setusername (string as_username)
public function long retrievesyntax (n_cst_datasetattrib anv_datasetattrib)
public function long setdataobject (string as_dataobject, long al_languageid)
end prototypes

public function long getlastdberror (ref long al_sqldbcode, ref string as_message);////////////////////////////////////////////////////////////////
// Description:
//    Gets the last known dberror (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 (REF long, REF string)"

inv_log.traceLog (METHOD_NAME, "")

// 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

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 (ref n_cst_dberrorattrib)"

inv_log.traceLog (METHOD_NAME, "")

// 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 setdataaccess (n_cst_dataaccessservice anv_dataaccess);////////////////////////////////////////////////////////////////
// Description:
//    Set a DataAccess service for the object to use
//
//    Can only be set once
// Revisions
//    1.0   - Initial version
// Arguments:  
//    anv_dataaccess - The created dataaccess 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 = "setDataAccess (REF n_cst_dataaccess) "

inv_log.traceLog (METHOD_NAME, "")

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

// Value can only be set once
If IsValid(inv_dataaccess) Then
   addError(METHOD_NAME, "DataAccess can only be set once")
   Return -1   
End If

// Assign the object to the instance variable
inv_dataaccess = anv_dataaccess
is_dataaccessservice = anv_dataaccess.className()

//propagate log settings to the dataaccess service
inv_log.propagateSettings( anv_dataaccess )

Return 1
end function

public function long setdatastore (string as_datastore);////////////////////////////////////////////////////////////////
// Description:
//    Set a Datastore object for the object to use
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_datastore - The datastore to be used
// 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 = "setDatastore ( string )"

inv_log.traceLog (METHOD_NAME, "as_datastore="+as_datastore)

// Declare local variables
n_cst_classdefinitionservice  lnv_classdefinition

// Perform clenaup
as_datastore = trim(lower(as_datastore))

// Validate arguments
If IsNull(as_datastore) Or len(as_datastore) = 0 Then 
   addError(METHOD_NAME, "Invalid as_datastore argument")
   Return -1
End If

try
   lnv_classdefinition = create n_cst_classdefinitionservice
   inv_log.propagateSettings( lnv_classdefinition )
   // If not the base datastore object, confirm the object class is 
   // valid prior to creating it
   If as_datastore <> DATASTORE_BASE Then
      // Confirm the object is a descendant of the base datastore
      If Not lnv_classdefinition.isDescendant &
            (as_datastore, DATASTORE_BASE) Then
         addError(METHOD_NAME, "Datastore object " + &
            "("+as_datastore+") is Not a descendant of " + DATASTORE_BASE)
         Return -1      
      End If
   End If
finally
   destroy lnv_classdefinition
end try

// Store the new Datastore object
is_datastore = as_datastore

Return 1
end function

public function integer setretrieveaction (string as_action);////////////////////////////////////////////////////////////////
// Description:
//    Set the retrieve type (FULL, Syntax, Data etc...
// 
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_action   - The type of retrieve
// 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 = "setretrieveaction ( string )"

inv_log.traceLog (METHOD_NAME, "as_action="+as_action)

is_retrieveaction = as_action

return 1
end function

protected function string getretrieveaction ();////////////////////////////////////////////////////////////////
// Description:
//    Gets the current retrieval action code
// Revisions
//    1.0   - Initial version
// Arguments
//    None
// Returns: 
//    The retrieval action code
////////////////////////////////////////////////////////////////
// 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.
//////////////////////////////////////////////////////////////// 

Return is_retrieveaction
end function

public function long setdataaccess (string as_dataaccess);////////////////////////////////////////////////////////////////
// Description:
//    Set a DataAccess service for the object to use
//
//    Can only be set oncel
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_dataaccess - The created dataaccess 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 = "setDataAccess ( string )"

inv_log.traceLog (METHOD_NAME, "")

// Declare local variables
long                          ll_method_rc

n_cst_dataaccessservice       lnv_dataaccess
n_cst_classdefinitionservice  lnv_classdefinition

// Perform clenaup
as_dataaccess = trim(lower(as_dataaccess))

// Validate arguments
If IsNull(as_dataaccess) Or len(as_dataaccess) = 0 Then 
   addError(METHOD_NAME, "Invalid as_dataaccess argument")
   Return -1
End If   

try
   lnv_classdefinition = create n_cst_classdefinitionservice
   inv_log.propagateSettings( lnv_classdefinition )
   // If not the base dataaccess object, confirm the object is class is 
   // valid prior to creating it
   If as_dataaccess <> DATAACCESS_BASE Then
      // Confirm the object is a descendant of the DataAccess Service
      If Not lnv_classdefinition.isDescendant &
            (as_dataaccess, DATAACCESS_BASE) Then
         addError(METHOD_NAME, "DataAccess object " + &
            "("+as_dataaccess+") is Not a descendant of " + DATAACCESS_BASE)  
         Return -1      
      End If
   End If
finally
   destroy lnv_classdefinition
end try

// Create the service
lnv_dataaccess = Create Using as_dataaccess
inv_log.propagateSettings( lnv_dataaccess )

// Assign the service object
ll_method_rc = setDataaccess (lnv_dataaccess)
If ll_method_rc <= 0 Then
   If isValid(lnv_dataaccess) Then destroy lnv_dataaccess
End If

Return ll_method_rc

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() "

super::propagatelogSettings()

long        ll_rccount

ll_rccount += inv_log.propagateSettings( inv_htmldw )
ll_rccount += inv_log.propagateSettings( inv_string )
ll_rccount += inv_log.propagateSettings( inv_objecthelper )

if ll_rccount = 3 then
   return 1
else
   return -1
end if

end function

public function long retrievechildend (string as_columnname, ref datawindowchild adwc_working, ref n_cst_datasetattrib anv_datasetattrib);////////////////////////////////////////////////////////////////
// Description:
//    Final method in child retrieve process
//
//    Contains Start and End processing
// Revisions
//    3.0   - Initial version
// Arguments:
//    as_columnname  - DWC Column Name
//    adwc_working   - DWC Reference
//    anv_datasetattrib    -  Dataset Attribute 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 = "retrieveChildEnd ( string , REF datawindowchild , REF n_cst_datasetattrib )"

inv_log.traceLog (METHOD_NAME, "")


Return 1
end function

public function long retrievechildstart (string as_columnname, ref datawindowchild adwc_working, ref n_cst_datasetattrib anv_datasetattrib);////////////////////////////////////////////////////////////////
// Description:
//    Beginning method in child retrieve process
//
//    Contains Start and End processing
// Revisions
//    3.0   - Initial version
// Arguments:
//    as_columnname  - DWC Column Name
//    adwc_working   - DWC Reference
//    anv_datasetattrib    -  Dataset Attribute Object
// Returns: 
//     1 - Success (even if there were no rows populated)
//    -1 - Failure
//     2 - Skips retrieval process without error
//     0 - Cancels retrieve operation in an error condition
////////////////////////////////////////////////////////////////
// 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 = "retrieveChildStart ( String, REF DataWindowChild, REF n_cst_datasetattrib )"

inv_log.traceLog (METHOD_NAME, "")


Return 1
end function

public function long retrievechildmain (string as_columnname, ref datawindowchild adwc_working, ref n_cst_datasetattrib anv_datasetattrib);////////////////////////////////////////////////////////////////
// Description:
//    Main method in child retrieve process
//
//    Contains Start and End processing
// Revisions
//    3.0   - Initial version
// Arguments:
//    as_columnname  - DWC Column Name
//    adwc_working   - DWC Reference
//    anv_datasetattrib    -  Dataset Attribute 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 = "retrieveChildMain ( string, REF DataWindowChild, REF n_cst_datasetattrib )"

inv_log.traceLog (METHOD_NAME, "")

string                           ls_argumentnames[]
string                           ls_argumenttypes[]
string                           ls_dwsyntax

long                          ll_argumentcount
long                          ll_argumentindex
long                          ll_childargumentcount
long                          ll_childargumentindex
long                          ll_matchedargumentcount
long                          ll_matchedargumentindex
long                          ll_valuecount
long                          ll_valueindex
long                          ll_currentcount

string                           ls_errormessage

any                           la_values[20]
any                           la_argvalue

n_cst_datastoreservice        lnv_dssrv
n_cst_stringservice           lnv_string
n_datastore                   lds_working

n_cst_argumentattrib       lnv_argumentattrib[]

try
   
   lnv_dssrv = create n_cst_datastoreservice
   
   //get the dw syntax of the child datawindow
   ls_dwsyntax = adwc_working.describe( "DataWindow.Syntax" )
   
   //get the list of arguments from the child datawindow
   if lnv_dssrv.getArguments( ls_dwsyntax, ls_argumentnames, ls_argumenttypes ) = -1 then
      inv_messaging.append( lnv_dssrv.inv_messaging )
      addError( METHOD_NAME, "Retrieval of DDDW '" + as_columnname + "' failed." )
      return -1
   end if
   
   ll_argumentcount = upperBound( ls_argumentnames )
   
   //Create working datastore to allow logging and error catching
   lds_working = create n_datastore
   inv_log.Dynamic propagateSettings( lds_working )

   //Place contents of DDDW in working datastore
   if lds_working.create( ls_dwsyntax ) = -1 then
      addError( METHOD_NAME, "Retrieval of DDDW '" + as_columnname + "' failed due to lds_working.create() failing when using the DDDW's DataObject syntax." )
      return -1
   end if

   if lds_working.setTransObject( sqlca ) = -1 then
      addError( METHOD_NAME, "Retrieval of DDDW '" + as_columnname + "' failed due to setTransObject() failing." )
      return -1
   end if      
   
   //return immediately if argument count is zero
   if ll_argumentCount = 0 then
      if lds_working.retrieve() = -1 then
         inv_messaging.append( lds_working.inv_messaging )
         addError( METHOD_NAME, "Retrieval of DDDW '" + as_columnname + "' failed." )
         return -1
      else
         lds_working.rowsMove(1, lds_working.rowCount(), Primary!, adwc_working,  1, Primary! )
         return 1
      end if
   end if
   
   //Get total child argument count
   ll_childargumentcount = upperBound( anv_datasetattrib.inv_argumentservice.inv_childargumentattrib )
   
   lnv_string = create n_cst_stringservice
   
   for ll_childargumentindex = 1 to ll_childargumentcount
      //Only process arguments for current column name
      if Lower(anv_datasetattrib.inv_argumentservice.inv_childargumentattrib[ll_childargumentindex].is_childcolumnname ) = Lower( as_columnname ) then
         //Need to get the current count of attrib objects instead of relying on the index of the xml arguments as arguments could have been found for another dddw
         ll_currentcount = upperBound( lnv_argumentattrib ) + 1
         lnv_argumentattrib[ll_currentcount] = anv_datasetattrib.inv_argumentservice.inv_childargumentattrib[ll_childargumentindex]
         
         //Match by name to associate type of argument
         for ll_argumentindex = 1 to ll_argumentcount
            if lower( ls_argumentnames[ll_argumentindex] ) = Lower( lnv_argumentattrib[ll_currentcount].is_name ) then
                  lnv_argumentattrib[ll_currentcount].is_type = ls_argumenttypes[ll_argumentindex]
                  exit
            end if
         next
         
         ll_valuecount = upperBound( lnv_argumentattrib[ll_currentcount].is_values )

         //Set all the values to their any equivalent
         for ll_valueindex = 1 to ll_valuecount
            if anv_datasetattrib.inv_argumentservice.stringToAny( &
               lnv_argumentattrib[ll_currentcount].is_values[ll_valueindex], &
               lnv_argumentattrib[ll_currentcount].is_type, &
               lnv_argumentattrib[ll_currentcount].ib_isnull[ll_valueindex], &
               lnv_argumentattrib[ll_currentcount].ia_values[ll_valueindex] ) = -1 then
               
               addError( METHOD_NAME, "Invalid type found when analyzing DDDW arguments for column name " + as_columnname + " in dataset " + anv_datasetattrib.is_name )
               return -1
            end if
         next
      end if
   next
   
   //Check to make sure that the argument attrib count is the same as the argument count from the DDDW
   if upperBound( lnv_argumentattrib ) <> ll_argumentcount then
      ls_errormessage = "The number of passed in arguments for the DropDownDataWindow '" + as_columnname + "' is not correct. There were " + string( upperBound( lnv_argumentattrib ) ) + " arguments passed in.  The DDDW requires " + string( ll_argumentcount ) + "."
      inv_log.addError( METHOD_NAME, ls_errormessage, anv_datasetattrib.inv_messaging )
      return -1
   end if
   
   ll_matchedargumentcount = upperBound( lnv_argumentattrib )
   
   //loop through the datawindow arguments matching on argument name
   for ll_argumentindex = 1 to ll_argumentcount
      for ll_matchedargumentindex = 1 to ll_matchedargumentcount
         if lower( ls_argumentnames[ll_argumentindex] ) = Lower( lnv_argumentattrib[ll_matchedargumentindex].is_name ) then
            //establish the argument as an any and store in la_argvalue
            if ( Pos( lnv_argumentattrib[ll_matchedargumentindex].is_type, "list" ) > 0 ) then
               la_values[ll_argumentindex] = lnv_argumentattrib[ll_matchedargumentindex].ia_values
            else
               //add it to the retrieve array
               la_values[ll_argumentindex] = lnv_argumentattrib[ll_matchedargumentindex].ia_values[1]
            end if
            exit
         end if
      next
   next
   
   if lds_working.setTransObject( sqlca ) = -1 then
      inv_messaging.append( lds_working.inv_messaging )
      addError( METHOD_NAME, "Retrieve of DDDW '"+ as_columnname + "' failed due to failure in setTransObject() on lds_working." )
      return -1
   end if
   
   if lds_working.retrieve( la_values[1], la_values[2],la_values[3], la_values[4],la_values[5], la_values[6], &
      la_values[7], la_values[8],la_values[9], la_values[10],la_values[11], la_values[12],la_values[13], la_values[14], &
      la_values[15], la_values[16],la_values[17], la_values[18],la_values[19], la_values[20] ) = -1 then

      //failed to retrieve DDDW
      inv_messaging.append( lds_working.inv_messaging )
      addError( METHOD_NAME, "Failed to retrieve DDDW for column name " + as_columnname + " in dataset " + anv_datasetattrib.is_name  )
      return -1
   else
      lds_working.rowsMove(1, lds_working.rowCount(), Primary!, adwc_working,  1, Primary! )
      return 1
   end if
   
finally
   if isValid( lnv_dssrv ) then
      destroy lnv_dssrv
   end if
   
   if isValid( lnv_string ) then
      destroy lnv_string
   end if
   if isValid( lds_working ) then
      destroy lds_working
   end if
end try


Return 1
end function

public function long retrievechild (string as_columnname, ref datawindowchild adwc_working, ref n_cst_datasetattrib anv_datasetattrib);////////////////////////////////////////////////////////////////
// Description:
//    Parent method in child retrieve process
//
//    Contains Start and End processing
// Revisions
//    3.0   - Initial version
// Arguments:
//    as_columnname  - DWC Column Name
//    adwc_working   - DWC Reference
//    anv_datasetattrib    -  Dataset Attribute 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 = "retrieveChild ( String, REF DataWindowChild, REF n_cst_datasetattrib )"

inv_log.traceLog (METHOD_NAME, "")

// Declare local variables
long                    ll_rc
long                    ll_start_rc
long                    ll_end_rc

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

// Invoke the Start processing method
ll_start_rc = this.retrieveChildStart(as_columnname, adwc_working, anv_datasetattrib)
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
   inv_log.warningLog(METHOD_NAME, "Call to retrieveStart() has cancelled retrieve operation RC="+string(ll_start_rc))
   Return -1
End If

// Invoke the Main processing (skipped if ll_start_rc =2 )
If ll_start_rc = 1 Then
   ll_rc = this.retrieveChildMain(as_columnname, adwc_working, anv_datasetattrib)
   If ll_rc < 0 Then
      //Check to see if error was caused by a database error
      if inv_messaging.getMessageCount( inv_constants.MESSAGE_TYPE_EAF_DB_ERROR ) > 0 then
         //Invoke the DB Error method
         dbError( anv_datasetattrib )
      end if
      addError (METHOD_NAME, "Operation retrieveMain() failed with RC="+string(ll_rc))
      Return -1   
   End If   
End If

// Invoke the End processing method
ll_end_rc = this.retrieveChildEnd(as_columnname, adwc_working, anv_datasetattrib)

If ll_end_rc <=0 Then
   addError (METHOD_NAME, "Call to retrieveEnd() returned with error condition")
   Return -1
End If


Return 1
end function

protected function long retrieveend (ref n_cst_datasetattrib anv_datasetattrib);////////////////////////////////////////////////////////////////
// Description:
//    Invoked by the Framework from the retrieve().
//    Occurs when the Retrieval is complete.
// Revisions
//    3.0   - Initial version
// Arguments:  
//    anv_datasetattrib -  DataSet Attributes
// 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_datasetattrib"

inv_log.traceLog (METHOD_NAME, "")

Return 1
end function

protected function long retrievestart (ref n_cst_datasetattrib anv_datasetattrib);////////////////////////////////////////////////////////////////
// Description:
//    Invoked by the Framework from the retrieve().
//    Occurs when the Retrieval process is about to begin
// Revisions
//    3.0   - Initial version
// Arguments:  
//    anv_datasetattrib    -  All DataSet attributes
// 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_datasetattrib"

String ls_str
Boolean lb_insert
Long ll_row
n_cst_stringservice lnv_string

inv_log.traceLog (METHOD_NAME, "")

//Insert blank row
anv_datasetattrib.inv_argumentservice.GetArgument("insertblankrow", ls_str)
if ls_str <> "" then
   lnv_string = create n_cst_stringservice
   lb_insert = lnv_string.toBoolean( ls_str )
   destroy lnv_string
   if lb_insert then
      anv_datasetattrib.inv_argumentservice.GetArgument("insertblankrowcount", ls_str)
      if IsNumber(ls_str) then
         for ll_row = 1 to Long(ls_str)
            anv_datasetattrib.ids_working.InsertRow(0)
         next
      else
         anv_datasetattrib.ids_working.InsertRow(0)
      end if
      return 2
   end if
end if

Return 1
end function

protected function long retrievemain (ref n_cst_datasetattrib anv_datasetattrib);////////////////////////////////////////////////////////////////
// Description:
//    Invoked by the Framework from the retrieve().
//    The Main Retrieve process where the actual retrieve occurrs
// Revisions
//    3.0   - Initial version
// Arguments:  
//    anv_datasetattrib -  All DataSet 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.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "retrieveMain REF n_cst_datasetattrib"

inv_log.traceLog (METHOD_NAME, "")

// Declare local variables
long                    ll_rc
n_cst_dataaccessattrib  lnv_dataaccessattrib


try
   lnv_dataaccessattrib = create n_cst_dataaccessattrib
   // Validate arguments
   If isNull(anv_datasetattrib) Then
      addError (METHOD_NAME, "Invalid anv_argumentservice argument")
      Return -1
   End If   
   
   If this.getretrieveaction() = inv_constants.RETRIEVE_SYNTAXONLY then
      ll_rc = anv_datasetattrib.ids_working.insertrow(0) // force and dddw's to be retrieved
      anv_datasetattrib.ids_working.deleterow(ll_rc) // remove the row we just added.  
   else
   
      // Populate the DataAccess Attribute object
      lnv_dataaccessattrib.is_identifier = this.className()
      lnv_dataaccessattrib.ids_data = anv_datasetattrib.ids_working
      lnv_dataaccessattrib.inv_argumentservice = anv_datasetattrib.inv_argumentservice
      
      // Execute by calling on the dataaccess object
      ll_rc = inv_dataaccess.retrieve(lnv_dataaccessattrib)
      If isNull(ll_rc) Or ll_rc < 0 Then
         // Get the last  DB error
         inv_dataaccess.getLastDBError(inv_dberror)
         inv_messaging.append( inv_dataaccess.inv_messaging )
         addError(METHOD_NAME, "Failed inv_dataaccess.retrieve() operation RC="+string(ll_rc))
         Return -1   
      End If      
   end if
finally
   destroy lnv_dataaccessattrib
end try

Return 1
end function

public function long retrieve (ref n_cst_datasetattrib anv_datasetattrib);////////////////////////////////////////////////////////////////
// Description:
//    Populate the passed in object
//
//    Contains Start and End processing
// Revisions
//    3.0   - Initial version
// Arguments:  
//    anv_datasetattrib -  All DataSet Attributes
// 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_datasetattrib )"

inv_log.traceLog (METHOD_NAME, "")

// Declare local variables
long                                   ll_rc
long                                   ll_start_rc
long                                   ll_end_rc
string                                 ls_argumentnames[]
string                                 ls_argumenttypes[]
n_cst_datastoreservice                 lnv_dssrv

try
   // Validate arguments
   If isNull(anv_datasetattrib) Then
      addError (METHOD_NAME, "Invalid anv_argumentservice argument")
      Return -1
   End If   
   
   // If appropriate create the DataAccess object
   If isNull(inv_dataaccess) Or Not isValid(inv_dataaccess) Then
      // An specific DataAccess object was not requested
      If setDataAccess(is_dataaccessservice) <= 0 Then
         addError(METHOD_NAME, "Unexpected failure of setDataAccess() operation")
         Return -1                     
      End If
   End If
   
   //Set the retrieved property to indicate that the retrieve process has been fired for the DataSet
   anv_datasetattrib.ib_retrieved = true
   
   // Invoke the Retrieve Syntax processing method
   If this.getretrieveaction() <> inv_constants.RETRIEVE_DATAONLY then
      if retrievesyntax( anv_datasetattrib ) = -1 then
         addError (METHOD_NAME, "Operation retrieveSyntax() failed ")
         return -1
      end if
   end if
   
   // Invoke the Start processing method
   ll_start_rc = this.retrieveStart( anv_datasetattrib)
   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
      inv_log.warningLog(METHOD_NAME, "Call to retrieveStart() has cancelled retrieve operation RC="+string(ll_start_rc))
      Return -1
   End If
   
   // Invoke the Main processing (skipped if ll_start_rc =2 )
   If ll_start_rc = 1 Then
      //Get bound argument information
      lnv_dssrv = create n_cst_datastoreservice
      inv_log.propagateSettings( lnv_dssrv )
      lnv_dssrv.setRequestor(anv_datasetattrib.ids_working)
      If lnv_dssrv.getArguments ( ls_argumentnames, ls_argumenttypes) < 0 Then
         inv_log.addError( METHOD_NAME, "Failed to get argument definition for DataSet '" + anv_datasetattrib.is_name + "'", anv_datasetattrib.inv_messaging )
         Return -1
      End If
   
      //Prepare arguments (if retrieve datawindow syntax, don't check it)
      If this.getretrieveaction() <> inv_constants.RETRIEVE_SYNTAXONLY then
         if ( anv_datasetattrib.inv_argumentservice.prepareArguments( ls_argumentnames, ls_argumenttypes ) = -1 ) then
            anv_datasetattrib.inv_messaging.append( anv_datasetattrib.inv_argumentservice.inv_messaging )
            inv_log.addError( METHOD_NAME, "Failed to prepare arguments for DataSet '" + anv_datasetattrib.is_name + "'", anv_datasetattrib.inv_messaging )
            return -1
         end if
      End if
      
      ll_rc = this.retrieveMain( anv_datasetattrib)
      If ll_rc < 0 Then
         //Check to see if error was caused by a database error
         if inv_messaging.getMessageCount( inv_constants.MESSAGE_TYPE_EAF_DB_ERROR ) > 0 then
            //Invoke the DB Error method
            dbError( anv_datasetattrib )
         end if
         addError (METHOD_NAME, "Operation retrieveMain() failed with RC="+string(ll_rc))
         Return -1   
      End If   
   End If
   
   // Invoke the End processing method
   ll_end_rc = this.retrieveEnd( anv_datasetattrib)
   If ll_end_rc <=0 Then
      addError (METHOD_NAME, "Call to retrieveEnd() returned with error condition")
      Return -1
   End If
   
finally
   
   inv_dataaccess.inv_messaging.reset()
   
   if isValid( lnv_dssrv ) then
      destroy lnv_dssrv
   end if
   
end try

Return 1
end function

public function long retrievechildren (ref n_cst_datasetattrib anv_datasetattrib);////////////////////////////////////////////////////////////////
// Description:
//    Triggers the retrieve of all DropDownDataWindows
//    Parent method to the retrieveChild process
//
// Revisions
//    3.0   - Initial version
// Arguments:
//    anv_datasetattrib -  (REF) Dataset attribute 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 = "retrieveChildren ( REF n_cst_datasetattrib )"

string         ls_action
string         ls_context
string         ls_dddwname
string         ls_column
string         ls_debug

long           ll_rc
long           ll_retrieve_rc
long           ll_colcount
long           ll_idx_dddw

DataWindowChild   ldwc_dddw

//Process DropDownDataWindows
ll_colcount = long(anv_datasetattrib.ids_working.describe("DataWindow.Column.Count")) 

For ll_idx_dddw = 1 To ll_colcount
   // Attempt to get the name of a DropDownDatawindow
   ls_dddwname = anv_datasetattrib.ids_working.describe('#'+string(ll_idx_dddw)+'.dddw.name')
   If ls_dddwname <> '?' Then 
      // Found a dropdown datawindow
      ls_column = anv_datasetattrib.ids_working.describe('#'+string(ll_idx_dddw)+'.name')
      // Get a reference to the DropDownDatawindow
      If anv_datasetattrib.ids_working.getChild(ls_column, ldwc_dddw) < 0 Then
         inv_log.debugLog(METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG,"Summary of..." + ls_debug)              
         addError(METHOD_NAME, anv_datasetattrib.is_name+": Unable to get reference to DDDW for column '"+ls_column+"'")   
         return -1         
      End If
      If is_retrieveaction = inv_constants.RETRIEVE_DATAONLY Then
         // Simply Add a row so that no DDDW retrieve can take place
         ldwc_dddw.insertRow(0)
      else
         //Invoke DDDW retrieval processing through the DataSet
         if retrieveChild( ls_column, ldwc_dddw, anv_datasetattrib ) = -1 then
            addError( METHOD_NAME, "Retrieve children failed due to failure in retrieveChild" )
            return -1
         end if
      end if
   End If
Next

return 1

end function

public function long setdataobject (string as_dataobject);////////////////////////////////////////////////////////////////
// Description:
//    Overloaded version to set the language = 1
//
//    Call to set value can only be made once.
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_dataobject  - The name of the dataobject to be assigned
// 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 = "setDataobject ( string )"

inv_log.traceLog (METHOD_NAME, "" )

Return setDataObject( as_dataobject, this.GetLanguageid( ) )

end function

public function long setsessionid (string as_sessionid);////////////////////////////////////////////////////////////////
// Description:
//    Sets the session id for the current user
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_sessionid - The session id of the current user
// 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 = "setDatastore ( string )"


is_sessionid = as_sessionid

Return 1
end function

public function long createcontentbegin (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset);////////////////////////////////////////////////////////////////
// Description:
//    Method called before content is created
// Revisions
//    3.0   - Initial version
// Arguments:  
//    anv_datasetattrib -  All DataSet Attributes
//    astr_mimedataset - All passed in parameters from the client
// Returns: 
//     2 - Skip content creation by content provider service
//     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 = "createContentBegin ( REF n_cst_datasetattrib, REF str_mimedataset )"

inv_log.traceLog (METHOD_NAME, "")


Return 1
end function

public function long createcontentend (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset);////////////////////////////////////////////////////////////////
// Description:
//    Method called after content is created
// Revisions
//    3.0   - Initial version
// Arguments:  
//    anv_datasetattrib -  All DataSet Attributes
//    astr_mimedataset - All passed in parameters from the client
// 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 = "createContentEnd ( REF n_cst_datasetattrib, REF str_mimedataset )"

inv_log.traceLog (METHOD_NAME, "")


Return 1
end function

public function long updatebetweenbo (ref n_cst_datasetattrib anv_datasetattrib, long al_boidx);////////////////////////////////////////////////////////////////
// Description:
//    Called by the update process before any BO's have been 
//    called and after each successsful BO update call
//    It is possible to 're-order' the list of BO's.
// Revisions
//    3.0   - Initial version
// Arguments:  
//    anv_datasetattrib - DataSet Attribute objects
//    al_boidx -  the index of the BO used for the dataset in the as_bonames array
//                if al_boidx = 0 then the method was called BEFORE any
//                BO's have been called yet
//                If  al_boidx = upperbound(as_bonames) then it's after all BO's have been called
// 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 = "updateBetweenBO ( REF anv_datasetattrib, long )"

string ls_summary

If ib_trace Then
   if al_boidx = 0 then
      ls_summary = 'dataset='+anv_datasetattrib.is_name+'BOName=Before any BO has been executed'
   else
      ls_summary =  'dataset='+anv_datasetattrib.is_name+'BOName='+anv_datasetattrib.is_updatebonames[al_boidx]
   end if
   inv_log.traceLog (METHOD_NAME, ls_summary)
End If   

return 1
end function

public function long update (n_cst_datasetattrib anv_datasetattrib);////////////////////////////////////////////////////////////////
// Description:
//    Update the passed in object
//
//    This is only used when allowing updates without the
//    benefit of Business Objects
// Revisions
//    3.0   - Initial version
// Arguments:  
//    anv_datasetattrib -  All DataSet 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.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "update ( REF n_cst_datasetattrib )"

inv_log.traceLog (METHOD_NAME, "")

// Declare local variables 
long                 ll_start_rc
long                 ll_end_rc
long                 ll_rc

try
      
   // Validate arguments
   If IsNull(anv_datasetattrib) Or Not IsValid(anv_datasetattrib) Then
      addError (METHOD_NAME, "Invalid anv_datasetattrib argument")
      Return -1
   End If
   
   // If appropriate create the DataAccess object
   If isNull(inv_dataaccess) Or Not isValid(inv_dataaccess) Then
      // An specific DataAccess object was not requested
      If setDataAccess(is_dataaccessservice) <= 0 Then
         addError(METHOD_NAME, "Unexpected failure of setDataAccess() operation")
         Return -1                     
      End If
   End If   
   
   if anv_datasetattrib.ids_working.FilteredCount() > 0 then
      anv_datasetattrib.ids_working.SetFilter("")
      anv_datasetattrib.ids_working.Filter()    
   end if
   
   if anv_datasetattrib.is_action <> inv_constants.UPDATE_SENDALL then
      anv_datasetattrib.ids_working.SetFilter("isRowModified() or isRowNew()")
      anv_datasetattrib.ids_working.Filter()
   end if

   // Invoke the Start processing method
   ll_start_rc = updateStart(anv_datasetattrib)
   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
      addError(METHOD_NAME, "Update failed due to validation failure in updateStart()")
      Return -1   
   End if
   
   // Invoke the Main processing  (skipped if ll_start_rc =2 )
   If ll_start_rc = 1 Then
      ll_rc = updateMain(anv_datasetattrib)
      If ll_rc < 0 Then
         //Check to see if error was caused by a database error
         if inv_messaging.getMessageCount( inv_constants.MESSAGE_TYPE_EAF_DB_ERROR ) > 0 or &
            anv_datasetattrib.inv_messaging.getMessageCount( inv_constants.MESSAGE_TYPE_EAF_DB_ERROR ) > 0 then
            //Invoke the DB Error method
            dbError( anv_datasetattrib )
         end if
         addError(METHOD_NAME, "Operation updateMain() failed with RC="+string(ll_rc))
         Return -1
      End if   
   End If   
      
   // Invoke the End processing method
   ll_end_rc = updateEnd(anv_datasetattrib)
   If ll_end_rc < 0 Then
      addError(METHOD_NAME, "Update failed due to failure in updateEnd()")
      Return -1   
   End If
finally
   
   if anv_datasetattrib.is_action = inv_constants.UPDATE_SENDCHANGESONLY then
      anv_datasetattrib.ids_working.SetFilter("")
      anv_datasetattrib.ids_working.Filter()
      anv_datasetattrib.ids_working.Sort()
   end if

   inv_dataaccess.inv_messaging.reset()
   
end try

Return 1
end function

protected function long updateend (n_cst_datasetattrib anv_datasetattrib);////////////////////////////////////////////////////////////////
// Description:
//    Invoked by the Framework from the update().
//    Occurs when the Update is complete.
// Revisions
//    3.0   - Initial version
// Arguments:  
//    anv_datasetattrib -  All DataSet Attributes
// 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_datasetattrib"

inv_log.traceLog (METHOD_NAME, "")

Return 1
end function

protected function long updatemain (n_cst_datasetattrib anv_datasetattrib);////////////////////////////////////////////////////////////////
// Description:
//    Invoked by the Framework from the update().
//    The Main Update process where the actual update occurrs
// Revisions
//    3.0   - Initial version
// Arguments:  
//    anv_datasetattrib -  All DataSet 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.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "updateMain ( REF n_cst_datasetattrib )"

inv_log.traceLog (METHOD_NAME, "")

// Declare local variables 
long                    ll_rc
long                    ll_boidx
long                    ll_bocount

string                  ls_boname
string                  ls_debug
string                  ls_characterset
string                  ls_defupdatebonames[]

s_mimedataset           lstr_mimedataset

n_cst_dataaccessattrib  lnv_dataaccessattrib
n_cst_businessobject    lnv_businessobject 

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

try
   
   // Get default Update businessobjects
   if this.GetDefaultUpdateBONames(anv_datasetattrib.is_name, anv_datasetattrib.ids_working, ls_defupdatebonames) = 1 then
      for ll_boidx = 1 to UpperBound(ls_defupdatebonames)
         anv_datasetattrib.is_updatebonames[UpperBound(anv_datasetattrib.is_updatebonames) + 1] = ls_defupdatebonames[ll_boidx]
      next
   end if

   ll_bocount = upperBound( anv_datasetattrib.is_updatebonames )

   //Test to see if this update is performed by BusinessObjects
   if ll_bocount > 0 then
      
      //Test if LUW is enabled
      if anv_datasetattrib.ib_luw then
         ll_rc = updateBetweenBO(anv_datasetattrib, ll_boidx)
         if ll_rc < 0 Then
            addError( METHOD_NAME, "Failed to prepare update for DataSet '" + anv_datasetattrib.is_name + "'" )
            return -1
         End If   
      end if
      
      //Get the Character Set
      anv_datasetattrib.inv_argumentservice.getArgument( inv_constants.EAF_CHARACTER_SET_ARGUMENT_NAME, ls_characterset )
      
      //Set the DataSet Name
      lstr_mimedataset.name = anv_datasetattrib.is_name

      //Get the Arguments into the structure to pass to the BusinessObject
      anv_datasetattrib.inv_argumentservice.toXML( lstr_mimedataset.arguments )
      
      //Loop around all Business Objects performing updates
      for ll_boidx = 1 To ll_bocount
         //Get the data out of the DataSet's datastore and place it in the ResultSets variable
         ll_rc = anv_datasetattrib.ids_working.GetFullState (lstr_mimedataset.data.state )         
         if ll_rc = -1 then
            addError( METHOD_NAME, "prepareUpdateMain failed due to failure in getfullstate or getchanges service." )
            return -1
         end if
      
         ls_boname = anv_datasetattrib.is_updatebonames[ll_boidx]
         
         ls_debug += "~r~n   Processing BusinessObject: " + ls_boname +" ("+string(ll_boidx)+" of "+string(ll_bocount)+")"
   
         // Create the Next Business Object
         try
            lnv_businessobject = create using ls_boname
         catch ( RuntimeError re )
            addError( METHOD_NAME, "Cannot create instance of BusinessObject '" + ls_boname + "'" )
            return -1
         End try
         
         // Set User Name
         lnv_businessobject.SetUserName(this.GetUserName())
         
         // Set Component Name
         lnv_businessobject.SetComponentName(this.GetComponentName())

         // Set Language ID
         lnv_businessobject.SetLanguageid(this.GetLanguageID())

         //Copy messages back to structure to pass to the BusinessObject
         anv_datasetattrib.inv_messaging.toXML( ls_characterset, lstr_mimedataset.messages )
         
         
         // Request the Business Object to Perform the Update
         ll_rc = lnv_businessobject.update(lstr_mimedataset)
                  
         ls_debug += "~r~n   "+ ls_boname+'.update() returned rc='+string(ll_rc)

         destroy lnv_businessobject
         
         //Copy messages back to message service instance
         anv_datasetattrib.inv_messaging.parse( lstr_mimedataset.messages )

         //Check return code
         Choose Case ll_rc
            Case -1
               //Update processing failed
               addError(METHOD_NAME, "Update Failed for Dataset("+anv_datasetattrib.is_name+") in BusinessObject " + ls_boname + "." )
               return -1
            Case 1
               //Get back the Updated Data
               ll_rc = anv_datasetattrib.ids_working.SetFullState(lstr_mimedataset.data.state)
               if ll_rc < 0 Then
                  addError(METHOD_NAME, "Failed to apply changes in the ResultSet service for DataSet '" + anv_datasetattrib.is_name + "'")
                  return -1
               End If   
         End Choose

         if anv_datasetattrib.ib_luw then
            ll_rc = updateBetweenBO(anv_datasetattrib, ll_boidx)
            if ll_rc < 0 Then
               addError(METHOD_NAME, "Update failed.  Cancelled in updateBetweenBO processing.")
               return -1
            end If   
         end if
      next
   
   else
      lnv_dataaccessattrib = create n_cst_dataaccessattrib
   
      // Populate the DataAccess Attribute object
      lnv_dataaccessattrib.is_identifier = this.className()
      lnv_dataaccessattrib.ids_data = anv_datasetattrib.ids_working
      
      // Execute by calling on the dataaccess object
      ll_rc = inv_dataaccess.update(lnv_dataaccessattrib)
      If isNull(ll_rc) Or ll_rc <= 0 Then
         // Get the last  DB error
         inv_dataaccess.getLastDBError(inv_dberror)   
         
         //append error message from dataaccess object
         inv_messaging.append( inv_dataaccess.inv_messaging )
         
         addError(METHOD_NAME, "Failed to update using data access service")
         
         Return -1   
      End If
   end if
finally
   inv_log.debugLog( METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, ls_debug )
   
   if isValid( lnv_dataaccessattrib ) then
      destroy lnv_dataaccessattrib
   end if
   
   if isValid( lnv_businessobject ) then
      destroy lnv_businessobject
   end if
end try

Return 1
end function

protected function long updatestart (n_cst_datasetattrib anv_datasetattrib);////////////////////////////////////////////////////////////////
// Description:
//    Invoked by the Framework from the update().
//    Occurs when the Update process is about to begin
// Revisions
//    3.0   - Initial version
// Arguments:  
//    anv_datasetattrib -  All DataSet Attributes
// 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_datasetattrib )"

inv_log.traceLog (METHOD_NAME, "")


Return 1
end function

public subroutine dberror (ref n_cst_datasetattrib anv_datasetattrib);////////////////////////////////////////////////////////////////
// Description:
//    Method to handle database errors
//    Fired when retrieveMain, retrieveChildMain or updateMain fails due to database errors
//    Place to analyze database errors and provide users with friendly messages
//    Error information can be garnered by getting messages of type EAF DB Error or by name
//       Message Names:
//          Buffer
//          Row
//          SQLDBCode
//          SQLErrText
//          SQLSyntax
//
//    
// Revisions
//    3.0   - Initial version
// Arguments:  
//    anv_datasetattrib -  All DataSet 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.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "dbError ( REF n_cst_datasetattrib )"

inv_log.traceLog (METHOD_NAME, "")



end subroutine

public function long replacedataobject (string as_dataobject, long al_languageid);////////////////////////////////////////////////////////////////
// Description:
//    Replaces the DataWindow Dataobjects and their language
//    to be used by this object.
//    The only difference on all datawindows should be the language.
//    Only one datawindow per language
//
// Revisions
//    4.0   - Initial version
// Arguments:  
//    as_dataobject  - The name of the dataobject to be assigned
//    al_languageid  - The language id
//                         1=English, 2=Spanish, 3...
// 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 = "replaceDataObject (string, long)"

// Declare local variables
long           ll_upper
long           ll_idx

string            ls_describeresult

boolean        lb_registered 

n_datastore    lds_working    

inv_log.traceLog (METHOD_NAME, "" )

inv_log.debugLog (METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "   as_dataobject="+as_dataobject+"~r~nal_languageid="+string(al_languageid) )

// Perform cleanup
as_dataobject = Trim(as_dataobject)

// Validate arguments
If IsNull(as_dataobject) Or Len(as_dataobject) = 0 Then 
   addError(METHOD_NAME, "Invalid as_dataobject argument")  
   Return -1
End If
If IsNull(al_languageid) Or al_languageid < 0 Then 
   addError(METHOD_NAME, "Invalid al_language argument") 
   Return -1
End If

// Create the working datastore
If isNull(is_datastore) Or len(trim(is_datastore)) = 0 Then
   addError(METHOD_NAME, "Error on is_datastore value")
   Return -1      
End If
lds_working = create using is_datastore
inv_log.Dynamic propagateSettings( lds_working )

// Test for a valid dataobject
If lds_working.setDataobject(as_dataobject) <= 0 Then
   addError(METHOD_NAME, "Failed setDataobject(" + as_dataobject + ") operation")   
   destroy lds_working
   Return -1
End If
destroy lds_working

// If dataobject is already registered for the language, replace it
ll_upper = upperBound(is_dataobjects)
For ll_idx = 1 to ll_upper
   If al_languageid = il_languages[ll_idx] Then
      // Already registered for the language, exit the loop
      lb_registered = true
      exit
   End If
Next

if lb_registered then
   ll_upper = ll_idx
else
   ll_upper ++
end if

// Set the dataobject and its language
is_dataobjects[ll_upper] = as_dataobject
il_languages[ll_upper] = al_languageid

Return 1

end function

public function long replacedataobject (string as_dataobject);////////////////////////////////////////////////////////////////
// Description:
//    Replaces the DataWindow Dataobjects for the default language
//
// Revisions
//    4.0   - Initial version
// Arguments:  
//    as_dataobject  - The name of the dataobject to be assigned
//
// 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 = "replaceDataObject (string)"

return replaceDataObject( as_dataobject, 1 )

end function

public function long setlanguageid (long al_languageid);super::setlanguageid(al_languageid)

if IsValid(inv_objecthelper) then
   inv_objecthelper.SetLanguageid(al_languageid)
end if

return 1
end function

public function string getcomponentname ();return is_componentname
end function

public subroutine setcomponentname (string as_componentname);is_componentname = as_componentname

inv_log.Dynamic Setcomponentname( as_componentname )
end subroutine

public function long getdefaultupdatebonames (string as_datasetid, datastore ads_working, ref string as_updateboname[]);////////////////////////////////////////////////////////////////
// Description:
//    Gets the default update business objects
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_datasetid - the current dataset id
//    ads_working  - the current working datastore
//    as_updateboname[] - Returns the update business objects
// Returns: 
//     1 - Success - There are default update business objects entries
//     0 - Success - No default update business objects entries
//    -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 = "getDefaultUpdateBONames (dataset name, datastore ads_woring, REF as_updateboname[])"

String                                 ls_table
String                                 ls_classname
Long                                   ll_rc
n_cst_classdefinitionservice           lnvo_classdef

inv_log.traceLog (METHOD_NAME, "")

ls_table = Lower(ads_working.Describe("DataWindow.Table.UpdateTable"))

ls_classname = inv_constants.UPDATE_CLASSNAME_PREFIX + "_" + ls_table

lnvo_classdef = create n_cst_classdefinitionservice

ll_rc = 0
if lnvo_classdef.isclassexist(lower(ls_classname)) then
   as_updateboname[1] = ls_classname
   ll_rc = 1
else
   ls_classname = inv_constants.UPDATE_CLASSNAME_PREFIX + "_shared_base"
   if lnvo_classdef.isclassexist(lower(ls_classname)) then
      as_updateboname[1] = ls_classname
      ll_rc = 1
   end if
end if

destroy lnvo_classdef

return ll_rc
end function

public function long getdataobject (ref string as_dataobject);////////////////////////////////////////////////////////////////
// Description:
//    Returns the appropriate DataWindow Dataobject to be used
//    for the user. It also returns the language being used
//    by the dataobject.
//
//    Even on Failure (-1), if possible method will return the
//    most like dataobject desired
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_dataobject  - Place holder to return the DataWindow
//                     Dataobject being be used by this object
//    al_languageid  - Place holder to return the Language ID
// Returns: 
//     1 - Success
//    -1 - Failure but if possible still returns a dataobject
////////////////////////////////////////////////////////////////
// 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 = "getDataobject (REF string, REF long)"

inv_log.traceLog (METHOD_NAME, "")

// Declare local variables
long     ll_upper, ll_row

try
   
   // Perform cleanup
   as_dataobject = ""
   
   ll_upper = upperBound(is_dataobjects)
   if ll_upper > 0 then
      if ll_upper = 1 then
         as_dataobject = is_dataobjects[1]
         Return 1
      else
         for ll_row = 1 to ll_Upper
            if Getlanguageid() = il_languages[ll_row] then
               as_dataobject = is_dataobjects[ll_row]
               Return 1
            end if
         next
      end if
   end if
   
finally

end try

// Code should never reach here
Return -1
end function

public function string getusername ();///////////////////////////////////////////////////////////////////////////////////
// Description:
//    Gets the User Name property.  
//    1.0   - Initial version
// Arguments:  
//    None
// Returns:
//     The User Name property
///////////////////////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Applirk
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
/////////////////////////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "getUserName "

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

Return is_username
end function

public function long setusername (string as_username);///////////////////////////////////////////////////////////////////////////////////
// Description:
//    Sets the User Name property.  
//    1.0   - Initial version
// Arguments:  
//    al_UserName - The Login User Name
// Returns:
//     1 - Success
//    -1 - Failure
///////////////////////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of thems, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
/////////////////////////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "setUserName "

If ib_trace Then
   inv_log.traceLog (METHOD_NAME, "(as_UserName)   as_UserName="+string(as_UserName))
End If   

// Validate arguments
If isNull(as_UserName) Or Len(as_UserName) <= 0 Then
   addError (METHOD_NAME, "Invalid al_UserName argument")
   Return -1
End If

is_UserName = as_UserName

if IsValid(inv_log) then
   inv_log.Dynamic SetUserName(as_username)
end if

Return 1
end function

public function long retrievesyntax (n_cst_datasetattrib anv_datasetattrib);////////////////////////////////////////////////////////////////
// Description:
//    Invoked by the Framework from the retrieve().
//    Occurs when the Retrieval is begin.
// Revisions
//    3.0   - Initial version
// Arguments:  
//    anv_datasetattrib -  DataSet Attributes
// 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.
//////////////////////////////////////////////////////////////// 

return 1
end function

public function long setdataobject (string as_dataobject, long al_languageid);////////////////////////////////////////////////////////////////
// Description:
//    Sets the DataWindow Dataobjects and their language
//    to be used by this object.
//    The only difference on all datawindows should be the
//    language.
//    Only one datawindow per language
//
//    Call to set value can only be made once.
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_dataobject  - The name of the dataobject to be assigned
//    al_languageid  - The language id
//                         1=English, 2=Spanish, 3=SimplifiedChinese, 4=TraditionalChinese...
// 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 = "setDataobject (string, long)"

inv_log.traceLog (METHOD_NAME, "" )

inv_log.debugLog (METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "   as_dataobject="+as_dataobject+"~r~nal_languageid="+string(al_languageid) )

// Declare local variables
long           ll_upper
long           ll_idx
string         ls_describeresult
n_datastore    lds_working    

// Perform cleanup
as_dataobject = Trim(as_dataobject)

// Validate arguments
If IsNull(as_dataobject) Or Len(as_dataobject) = 0 Then 
   addError(METHOD_NAME, "Invalid as_dataobject argument")  
   Return -1
End If
If IsNull(al_languageid) Or al_languageid < 0 Then 
   addError(METHOD_NAME, "Invalid al_language argument") 
   Return -1
End If

// Create the working datastore
If isNull(is_datastore) Or len(trim(is_datastore)) = 0 Then
   addError(METHOD_NAME, "Error on is_datastore value")
   Return -1      
End If

lds_working = create using is_datastore
inv_log.Dynamic propagateSettings( lds_working )

// Test for a valid dataobject
If lds_working.setDataobject(as_dataobject) <= 0 Then
   addError(METHOD_NAME, "Failed setDataobject(" + as_dataobject + ") operation")   
   destroy lds_working
   Return -1
End If
destroy lds_working

// Enforce the language can only set once
ll_upper = upperBound(is_dataobjects)
For ll_idx = 1 to ll_upper
   If al_languageid = il_languages[ll_idx] Then
      addError(METHOD_NAME, "Language ID value ("+string(al_languageid)+") " + &
         "can only be set once. " ) 
      Return -1      
   End If
Next

// Set the dataobject and its language
ll_upper ++
is_dataobjects[ll_upper] = as_dataobject
il_languages[ll_upper] = al_languageid

Return 1
end function

on eaf_n_cst_dataset.create
call super::create
end on

on eaf_n_cst_dataset.destroy
call super::destroy
end on

event constructor;call super::constructor;////////////////////////////////////////////////////////////////
// Description:
//    Constructor
// Revisions
//    1.0   - Initial version
// Arguments:  
//    None
// Returns: 
//    None
////////////////////////////////////////////////////////////////
// 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 "

//create the instance services

inv_htmldw = create n_cst_htmldwservice         
inv_string = create n_cst_stringservice         
inv_objecthelper = create n_cst_objectservice         

// Create the working datastore
If isNull(is_datastore) Or len(trim(is_datastore)) = 0 Then
   addError(METHOD_NAME, "Error on is_datastore value")
   Return
End If

inv_dberror = create n_cst_dberrorattrib        
end event

event destructor;call super::destructor;////////////////////////////////////////////////////////////////
// Description:
//    Destructor
//    Perform cleanup
// Revisions
//    1.0   - Initial version
// Arguments:  
//    None
// Returns: 
//    None
////////////////////////////////////////////////////////////////
// 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() "
   
if isValid( inv_htmldw ) then
   destroy inv_htmldw
end if
   
if isValid( inv_string ) then
   destroy inv_string
end if
   
if isValid( inv_objecthelper ) then
   destroy inv_objecthelper
end if
   
if isValid( inv_dberror ) then
   destroy inv_dberror
end if

end event