Using the GenericPuP Object
The GenericPuP object is one of several objects included with Commerce Server that implement the IPuP interface. These objects are used to assist in packaging the existing Commerce Server resources. Specifically, the GenericPuP object is used to package the data associated with three resources: Campaigns, Transactions, and Transaction Config.
These three resources have generic requirements in terms of how their data gets packaged, and if your custom resource has similar, generic requirements, you may be able to use the GenericPuP object instead of developing a new object that implements the IPuP interface.
Note
- The SDK sample "PuP Resource" in the SDK\Samples\Management folder is actually a version of the GenericPuP object. You might find it useful to study the source code or to modify it for your own purposes.
The GenericPuP object is designed to be able to package and unpack tables and data in a single SQL Server database. Several parameters control the execution of the GenericPuP object, including the names of the tables to package, and the names of SQL schema scripts to be executed when unpacking or deleting the custom data. These parameters exist as database entries in the Administration database. The remainder of this topic provides details about those entries and how they can be established.
This topic contains:
GenericPuP Database Entries
Parameter Usage During Processing
Loading GenericPuP SQL Scripts
GenericPuP Database Entries
In order to specify the use of the GenericPuP object, you must assign its ProgID (Commerce.GenericPup) to the s_ProgIDPUP column of appropriate row in the Resources table of the Administration database. Then you must establish the remaining database entries that will control the operation of the GenericPuP object for a particular resource: the Connection String, and the GenericPuP parameters.
Connection String
When the GenericPuP object is invoked to export or import data for a custom resource, it uses the passed resource name to look for the specific connection string in the set of properties associated with that resource. This connection string uses a pre-defined naming convention so that the GenericPuP object can find the connection string amongst the other properties associated with the custom resource. The syntax for the connection string propery name is: "connstr_db_<ResourceName>" where <ResourceName> is the name of the resource for which it is being invoked. There can be only one such connection string, so the GenericPuP object can only package or unpack data from one database.
Note
- If you look in the s_PropertyName column of the ResourceProps table in the Administration database, you will see the three connection strings connstr_db_Transactions, connstr_db_TransactionConfig, and connstr_db_Campaigns, corresponding to the three standard resources that use the GenericPuP object.
GenericPuP Parameters
After retrieving the connection string, the GenericPuP object will retrieve its parameters from the s_PupParam1, s_PupParam2, and s_PupParam3 columns of the row for the corresponding resource in the Resources table of the Administration database. These three parameters contain the following information:
s_PUPParam1
Contains a comma-delimited list of names of the tables to be packaged and unpacked for the resource.
For example, the table list for the Transactions resource is "TransDimension,TransCategory".
s_PUPParam2
Contains a comma-delimited list of the names of the SQL schema scripts to execute when importing the resource. These scripts are used to create the proper schema prior to importing the data.
For example, the schema script list for the Transaction Config resource is "AppConfig,TaxAndShipping".
s_PUPParam3
Contains a comma-delimited list of the names of the SQL scripts to execute when deleting the resource. If the Delete method implemented by the GenericPuP object is invoked, it will execute these scripts to clean up the database tables associated with the corresponding resource.
For example, the delete script list for the Campaigns resource contains the single script name: "SchemaDrop".
The scripts associated with the parameters s_PUPParam2 and s_PUPParam3 exist in the txt_script column of the pupdbscripts table in the Administration database. The u_scriptname column contains the name of the script as it appears in the list specified by this parameter, and the other two columns in that table, iSiteID and iResourceID, exist to prevent script name clashes between different resources.
The SiteConfig object implements three methods, GetSQLScript, PutSQLScript, and DeleteSQLScript, for managing the scripts stored in the pupdbscripts table. For more information about these three methods, see SiteConfig.GetSQLScript, SiteConfig.PutSQLScript, and SiteConfig.DeleteSQLScript, respectively.
For examples of how to set up your resource configuration to use the GenericPup object see the file SiteCreate.vbs in the SiteCreate folder of your Commerce Server installation directory. Follow the same steps as used by the three resources in that file that use the GenericPup object: Campaigns, Transactions, and Transaction Config.
Parameter Usage During Processing
When the Export method implemented by the GenericPuP object is invoked to package data, it performs the following steps:
Packages all of the data in the tables specified in the s_PUPParam1 column.
Packages all of the SQL scripts specified in s_PUPParam2 and s_PUPParam3 columns.
When the Import method implemented by the GenericPuP object is invoked to unpack data, it performs the following steps:
Executes the SQL schema scripts specified in the s_PUPParam2 column.
Unpacks the data in the tables specified by the s_PUPParam1 column. The scripts executed in step 1 must have already established the appropriate tables and schema.
When the Delete method or the DeleteGroupResource method implemented by the GenericPuP object is invoked to delete resource data, it performs the following steps:
Executes the SQL schema scripts specified in the s_PUPParam3 column.
Deletes all scripts associated with the current resource from the pupdbscripts table of the Administration database.
Loading GenericPuP SQL Scripts
The following sample code demonstrates one way to load a SQL script from a text file into the txt_script column of the pupdbscripts table of the Administration database. This sample also establishes appropriate values in the other columns. This sample uses the PutSQLScript method of the SiteConfig object to perform the actual database manipulation:
' Define a routine that takes the following four parameters:
' 1) A reference to a SiteConfig object,
' 2) The name of a resource,
' 3) The name of a text file containing the SQL script to load, and,
' 4) The name by which the script will be known in the Admin database.
Sub LoadResourceDBScript(oSiteConfig, sResource, _
sFilePath, sScriptName)
' Declare variables and constants for text file access...
Dim oFS, oFile, sScriptContents
Const ForReading = 1
Const TristateUseDefault = -2
' Read the script from the specified text file...
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oFile = oFS.OpenTextFile(sFilePath, ForReading, _
False, TristateUseDefault)
sScriptContents = oFile.ReadAll()
oFile.Close
Set oFile = Nothing
' Use the passed SiteConfig object to create
' (or overwrite) a row in the pupdbscripts table...
oSiteConfig.PutSQLScript sResource, sScriptName, _
sScriptContents
End Sub
' The following code calls the routine defined previously...
' Create the SiteConfig object...
Dim oSiteConfig
Set oSiteConfig = CreateObject("Commerce.SiteConfig")
' Initialize variables for the other
' parameters to LoadResourceScript...
Dim sResource, sFilePath, sScriptName
sResource = "Transactions"
sFilePath = "C:\temp\Requisition.sql"
sScriptName = "Requisition"
' Call the routine LoadResourceScript, previously defined...
LoadResourceScript oSiteCfgAdmin, sResource, _
sFilePath, sScriptName