Creating a New Class
This topic describes how to create a new class in the Data Warehouse. A class is created by inserting a new instance in the Class Definition (ClsDef) table, populating the attributes, and saving the changes. For information on the Class Definition table, see Class Definition Meta-data.
To begin the example, create the 'new' OrderFormHeader class, which represents header information required for the processing of order forms. For details on the existing class, see the OrderFormHeader class.
By default, a Binary (6) unique ID is automatically generated for the class.
Since the OrderFormHeader class has a multi-membered key, the GenerateKeyDef attribute is set to False (0). This attribute can be set to True for classes with a single key member (along with setting the IsPrimaryKey attribute to True on the Member definition corresponding to the key) to have the OLE DB Provider for Commerce Server automatically generate the key. For more information about creating a class key, see Creating a New Class Key.
The following table lists the attributes and values in the Class Definition table for the OrderFormHeader class. Unspecified optional attributes are not shown. In the R/O column, R = required, O = optional.
Attribute Name | Attribute Value | Type | R/O | Purpose |
ClassDefName | "OrderFormHeader" | String | R | Uniquely identifies the class in the Data Warehouse logical schema. |
SourceDefName | "DataSource" | String | R | Identifies the data source for storing instances of the class. |
Description | "Header data for a order form." | String | O | Describes the logical class. |
GenerateKeyDef | 0 | Integer | O | Do not generate the key automatically. The key will be specified manually using the "ClsKeyDef" meta-data component. |
IsActive | 1 | Integer | O | The class is active (instances may be added). |
IsPersistent | 1 | Integer | O | Persist instance data. |
Running Example - Steps 1 and 2
Connect to the Data Warehouse and create the OrderFormHeader class.
'Create an ADO connection object
Dim cnnConnection
Set cnnConnection = CreateObject("ADODB.Connection")
'Create an ADO command object.
Dim cmdCommand
Set cmdCommand = CreateObject("ADODB.Command")
'Create an ADO record object.
Dim recNew
Set recNew = CreateObject("ADODB.Record")
'Open a connection (bind) to the provider.
cnnConnection.Open "URL=mscop://InProcConnect/Server=MyServer:" _ &
"Catalog=DWSchema:Database=Retail_dw:User=admin:Password=*****:" _ &
"FastLoad=True"
'Set the connection in the command object
Set cmdCommand.ActiveConnection = cnnConnection
'Turn on "Schema Change" mode
cmdCommand.CommandText = "SchemaMode=1"
cmdCommand.Execute
'Create an instance in the Class Definition table.
recNew.Open "ClsDef/OrderFormHeader", cnnConnection, _
adModeWrite, adCreateOverwrite
'Set the attributes
recNew("SourceDefName") = "DataSource"
recNew("Description") = "Header data for a order form."
'Create our own key
recNew("GenerateKeyDef") = 0
recNew("IsActive") = 1
recNew("IsPersistent") = 1
'Save the new row.
recNew("__Commit") = 1
recNew.Fields.Update
Now that the new class exists, populate the class with data members.