|
of_register
|
|
Full name
|
pfc_n_cst_dwcache.of_register
|
Access
|
protected
|
Extend of
|
integer
|
Return value
|
integer
|
Prototype
|
protected function integer of_register(string,boolean,string,string,n_tr,any[20],powerobject[],datawindow,datastore,string,string)
|
Name
|
Datatype
|
lb_initialload
|
Boolean
|
li_cnt
|
Integer
|
li_newentry
|
Integer
|
li_openslot
|
Integer
|
li_rc
|
Integer
|
li_upper
|
Integer
|
ls_dwsyntax
|
String
|
ls_sqlerr
|
String
|
protected function integer of_register (string as_method, boolean ab_initialload, string as_id, string as_dwobjectname, n_tr atr_obj, any aa_args[20], powerobject apo_data[], datawindow adw_control, datastore ads_control, string as_importfile, string as_sql);//////////////////////////////////////////////////////////////////////////////
//
// Function: of_Register
//
// Access: protected
//
// Arguments:
// as_method The method being used, depending on the method some of
// the arguments are not used.
// ab_initialload Should an initial load of the data be performed? (T/F)
// as_id The ID to be given to this Cache Object.
// as_dwobjectname The DataWindow Object to be used on the Cache Object (if required).
// atr_obj The Transaction to use (if required).
// aa_args[20] The arguments to use (if required).
// apo_data[] The data to load (if required).
// adw_control The datawindow control which to load (if required).
// ads_control The datastore control which to load (if required).
// as_importfile The import file from which to load (if required).
// as_sql The sql to use if (required).
//
// Returns: integer
// 1 successful.
// 0 already registered.
// -1 error.
// -2 error on the transaction object.
// -3 error on the refresh process.
//
// Description:
// Registers the object into the service.
//
// If the method is RETRIEVE:
// The data to be cached is found on a DataBase. When requested, a retrive
// will be performed to load the data. Notice that DataWindow can have arguments.
// The of_Refresh() functions can be used to refresh the data on demand.
// *Note: If no initial load is performed, the 'loading' checks will be skipped.
// Among other tests, it means that retrieval arguments may not be valid.
//
// If the method is SQL:
// The cache data is found on a DataBase. When requested, a retrive
// will be performed to load the data. The of_Refresh() functions can be used
// to refresh the data on demand.
// *Note: If no initial load is performed, the 'loading' checks will be skipped.
//
// If the method is DATAOBJECTDATA:
// The cache data is found on the DataWindow Object.
// The of_Refresh() functions will reset the data to the original contents.
//
// If the method is POWEROBJECT:
// The cache data is found on the PowerObject array. There will be an initial
// load of this data.
// The of_Refresh() functions will reset the data to the original contents.
// *Note: This structure used to populate the load the data must match the
// DataWindow Object structure. If not, the result will be an application
// error message.
//
// If the method is DATAWINDOWCONTROL:
// The cache data is found on the datawindow control.
// The of_Refresh() functions will attempt to refresh the Cached data with that
// currently found on the original control.
//
// If the method is DATASTORECONTROL:
// The cache data is found on the datastore control.
// The of_Refresh() functions will attempt to refresh the Cached data with that
// currently found on the original control.
//
// If the method is IMPORTFILE:
// The cache data is found on an import file. When requested, there will be
// an initial load of this data. The of_Refresh() functions can be used
// to refresh the data on demand.
//
//////////////////////////////////////////////////////////////////////////////
//
// Revision History
//
// Version
// 6.0 Initial version
// 6.0.01 Took out duplicate trim() call.
//
//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1996-1999 Sybase, Inc. and its subsidiaries. All rights reserved.
// Any distribution of the PowerBuilder Foundation Classes (PFC)
// source code by other than Sybase, Inc. and its subsidiaries is prohibited.
//
//////////////////////////////////////////////////////////////////////////////
Integer li_rc
Integer li_upper=0
Integer li_cnt=0
Integer li_openslot=0
Integer li_newentry=0
Boolean lb_initialload = False
String ls_sqlerr, ls_dwsyntax
// Check for a valid method.
Choose Case as_method
Case RETRIEVE, DATAOBJECTDATA, POWEROBJECT, DATAWINDOWCONTROL, &
DATASTORECONTROL, IMPORTFILE, SQL
Case Else
Return -1
End Choose
// Check for a valid ID
If IsNull(as_id) or Len(Trim(as_id))= 0 Then
Return -1
End If
// --------------------------------------------------------------------------
// -- Preparation/Validation prior to attempting the actual registration.
// --------------------------------------------------------------------------
// Trim and Convert the ID to lower case.
as_id = Trim(Lower(as_id))
// Trim the DWObjectName.
as_dwobjectname = Trim(as_dwobjectname)
// Check for valid DataObjecName
Choose Case as_method
Case RETRIEVE, DATAOBJECTDATA, POWEROBJECT, IMPORTFILE
If IsNull(as_dwobjectname) or Len(as_dwobjectname)= 0 Then
Return -1
End If
End Choose
// Method dependent validation.
Choose Case as_method
Case RETRIEVE, SQL
If IsNull(atr_obj) Or Not IsValid(atr_obj) Then Return -2
If Not atr_obj.of_IsConnected() Then Return -2
If as_method = SQL Then
If IsNull(as_sql) Then Return -1
ls_dwsyntax = atr_obj.SyntaxFromSQL ( as_sql, '', ls_sqlerr )
If Len(ls_sqlerr) >0 Then Return -1
End If
Case POWEROBJECT
If IsNull(apo_data) Then Return -1
If UpperBound(apo_data) = 0 Then Return -1
Case DATAWINDOWCONTROL
If IsNull(adw_control) or Not IsValid(adw_control) Then Return -1
If Len(adw_control.DataObject) = 0 Then Return -1
// Populate the argument with the desired DataObject.
as_dwobjectname = adw_control.DataObject
Case DATASTORECONTROL
If IsNull(ads_control) or Not IsValid(ads_control) Then Return -1
If Len(ads_control.DataObject) = 0 Then Return -1
// Populate the argument with the desired DataObject.
as_dwobjectname = ads_control.DataObject
Case IMPORTFILE
If IsNull(as_importfile) or Not FileExists(as_importfile) Then
Return -1
End If
End Choose
// --------------------------------------------------------------------------
// -- Get the next Registration ID.
// --------------------------------------------------------------------------
// Determine if the ID already registered.
li_upper = UpperBound(inv_cachelist)
For li_cnt = 1 to li_upper
If as_id = inv_cachelist[li_cnt].s_id Then
// ID had already been registered.
Return 0
End If
Next
// Find an open slot (if any).
For li_cnt = 1 to li_upper
If inv_cachelist[li_cnt].s_id = EMPTY Then
// Open slot has been found.
li_openslot = li_cnt
Exit
End If
Next
// Determine the new entry slot.
If li_openslot > 0 Then
li_newentry = li_openslot
Else
li_newentry = li_upper + 1
End If
// --------------------------------------------------------------------------
// -- Begin actual registration.
// --------------------------------------------------------------------------
// Populate the ID reference
inv_cachelist[li_newentry].s_id = as_id
// Create the new cache datastore.
inv_cachelist[li_newentry].ds_obj = Create n_ds
// Populate the DataWindowObject (if any).
inv_cachelist[li_newentry].ds_obj.DataObject = as_dwobjectname
// Populate the Data Load Method.
inv_cachelist[li_newentry].s_method = as_method
// Method dependent functionality.
Choose Case as_method
Case RETRIEVE, SQL
If as_method = SQL Then
inv_cachelist[li_newentry].ds_obj.Create( ls_dwsyntax, ls_sqlerr)
If Len(ls_sqlerr) >0 Then
// There is a problem, take it out from the list.
li_rc = of_Unregister (as_id)
Return -1
End If
End If
// Set the transaction object
li_rc = inv_cachelist[li_newentry].ds_obj.of_SetTransObject(atr_obj)
If li_rc <> 1 Then
// There is a problem, take it out from the list.
li_rc = of_Unregister (as_id)
Return -2
End If
// Store the transaction object.
inv_cachelist[li_newentry].tr_obj = atr_obj
// Store the arguments (if any) for use on Retrieval process.
inv_cachelist[li_newentry].a_args = aa_args
// Keep track if an initial load needs to be performed.
lb_initialload = ab_initialload
Case POWEROBJECT
// Populate the PO_OriginalData array. Used in refresh operations.
inv_cachelist[li_newentry].po_originaldata = apo_data
// Perform the initial load of data into the object.
// *Note: if the apo_data does not match the data requirements
// of the datawindow object, Powerbuilder will provide immediate
// error feedback.
// Keep track if an initial load needs to be performed.
lb_initialload = True
Case DATAOBJECTDATA
// *Note: All the data should already be in the DataWindow object.
// Asign of the dataobject will be used in the of_refresh operation.
inv_cachelist[li_newentry].s_originaldataobject = as_dwobjectname
// Keep track if an initial load needs to be performed.
lb_initialload = False
Case DATAWINDOWCONTROL
// Populate the DW_OriginalControl reference. Used in refresh operations.
inv_cachelist[li_newentry].dw_originalcontrol = adw_control
// Keep track if an initial load needs to be performed.
lb_initialload = ab_initialload
Case DATASTORECONTROL
// Populate the DS_OriginalControl reference. Used in refresh operations.
inv_cachelist[li_newentry].ds_originalcontrol = ads_control
// Keep track if an initial load needs to be performed.
lb_initialload = ab_initialload
Case IMPORTFILE
// Populate the FileName reference
inv_cachelist[li_newentry].s_filename = as_importfile
// Keep track if an initial load needs to be performed.
lb_initialload = ab_initialload
End Choose
// If appropriate, perform the initialload of data.
If lb_initialload Then
li_rc = of_Refresh (as_id)
If li_rc < 0 Then
// There is a problem, take it out from the list.
li_rc = of_Unregister (as_id)
Return -3
End If
End If
Return 1
end function