Creating a New Class

For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.

This topic describes how to create a new class in the Data Warehouse. A class is created by creating a new row in the clsdef table, populating the columns, and saving the changes. For information about the clsdef table, see Clsdef Table: Class Definition Metadata.

To start the example, create a row in the clsdef table for the "new" OrderFormHeader class, which represents header information that is required for the processing of order forms. For more information 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. Therefore all classes in the Data Warehouse must have this ID.

Because the OrderFormHeader class has a multi-member key, set the value of the GenerateKeyDef column to False (0). You can set the value of this column to True for classes that have a single key member (together with setting the value of the IsPrimaryKey column to True in the row of the memdef table that corresponds to the key) to have the OLE DB provider for Commerce Server automatically generate the key. For more information about how to create a class key, see Creating a New Class Key.

The following table lists the columns and values in the clsdef table for the OrderFormHeader class. Unspecified optional columns are not shown. In the R/O column, R = required, O = optional.

Column name

Column 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 toTrue (1).

Example - Steps 1 and 2

Connect to the Data Warehouse and create the OrderFormHeader class.

Note

The code provided in this example is for demonstration only.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 data member is added. For more information about how to add a data member, see Creating a New 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

Other Resources

Creating a New Data Member

Extending the Data Warehouse Logical Schema