Creating a New Class

This topic describes how to create a new class in the Data Warehouse. A class is created by creating a new instance of a Class Definition (clsdef), populating the attributes, and saving the changes. For information about 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 about the existing class, see OrderFormHeader.

By default, a binary (6 byte) unique ID is automatically generated for the class. This ID is used as a surrogate key for relations, so all classes in the Data Warehouse must have this ID.

Because 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 "test_Source" String R A source def is a schema object that describes a data source. Always set SourceDefName to test_Source for new classes.
Description "Header data for a order form." String O Describes the logical class.
GenerateTableDef 1 Integer R Generates the table definition automatically when set to True (1).
GeneratePartitionDef 1 Integer R Generates the partition definition automatically when set to True (1).
GenerateKeyDef 0 Integer O Do not generate the key automatically. The key will be specified manually by using the "Key" meta-data component.
IsActive 1 Integer O The class is active (instances can be added).
IsPersistent 1 Integer O Persist instance data.
GenerateIdentity 1 Integer R Generates the ID for the class automatically when set to True (1).

Running Example - Steps 1 and 2

Connect to the Data Warehouse and create the OrderFormHeader class.

Ee796391.note(en-US,CS.20).gifNotes

  • The code provided in this example is for demonstration purposes only. The OrderFormHeader class created in this example already exists in the Data Warehouse schema. The CreateSchemaObject.vbs file included in the Commerce Server 2002 Software Development Kit should be used to automate the process of extending the schema. For more information about the script, see Create Schema Object Script.
  • The SQL Server operations involved in extending the logical schema require the user to be in the appropriate SQL role. For more information about user roles, see the SQL Server Help.
  • This example will not create a class definition unless at least one member is added. For more information about adding a data member, see Creating a New Class Data Member.
'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.
'Modify the values for Catalog, Database, User, and Password to match your
'resources.
   cnnConnection.Open "URL=mscop://InProcConnect/Server=MyServer:" & _
    "Catalog=DWSchema:Database=Retail_dw:  Trusted_Connection=Yes:" & _
    "FastLoad=True"

'Set the connection in the command object.
   Set cmdCommand.ActiveConnection = cnnConnection 

'Turn on "Schema Change" mode.
'SchemaMode can be set to On, True, or 1 to turn the
' schema change mode on. 
   cmdCommand.CommandText = "SchemaMode=1"
   cmdCommand.Execute

'Create a new class in the Class Definition table.
   recNew.Open "Class/OrderFormHeader", cnnConnection, _
    adModeWrite, adCreateOverwrite

'Set the attributes.
   recNew("ClassDefName") = "OrderFormHeader"
'Always set SourceDefName to test_Source for new classes. 
   recNew("SourceDefName") = "test_Source"
   recNew("Description") = "Header data for a order form."
   recNew("GenerateTableDef") = 1
   recNew("GeneratePartitionDef") = 1

'Create your own key.
   recNew("GenerateKeyDef") = 0

   recNew("GenerateIdentity") = 1

'Save the new row.
   recNew("__Commit") = 1
   recNew.Fields.Update
   recNew.Close

You can now create the data members for this class.

See Also

Creating a New Class Data Member

Create Schema Object Script

Copyright © 2005 Microsoft Corporation.
All rights reserved.