This is the second part of a three part series in extending the Data Warehouse. To recap the first part, take a look at this post here.
This part will focus on adding a new Data Warehouse class for the MusicDownload event and adding the event to the CommerceEvent table in the Data Warehouse database.
Let's get right to it:
Public Const fPrimaryKey = 1Public Const fMultiValued = 2Public Const fHasDefaultVal = 4Public Const fIsRequired = 8Public Const fIsJoinKey = 16Public Const fDontClear = 32Public Const fGenerateColDef = 64Public Const fIsUniqueKey = 128Public Const fIsIdentityMember = 256
'--- flags for clsdefPublic Const fGenerateIdentity = &H1Public Const fGenerateTableDef = &H2Public Const fGenerateKeyDef = &H4Public Const fGeneratePartDef = &H8Public Const fIsAbstract = &H10
Public Const fHasAggrExp = &H100 'member is aggregatePublic Const fIsDimension = &H1000Public Const fIsMeasure = &H10000
MainSub Main()
'Create an ADO connection object.Dim objConnSet objConn = CreateObject("ADODB.Connection")'Create an ADO command object.Dim cmdCommandSet cmdCommand = CreateObject("ADODB.Command")'Create an ADO record object.Dim recNewSet recNew = CreateObject("ADODB.Record")'Open a connection to the provider.'Modify the connection string to match your configuration. objConn.Open "URL=mscop://InProcConnect/Server=localhost:" & _"Catalog=DWSchema:Database=Startersite_datawarehouse: Trusted_Connection=Yes:" _& "FastLoad=True"'Set the connection in the command object.Set cmdCommand.ActiveConnection = objConn'Turn on "Schema Change" mode.cmdCommand.CommandText = "SchemaMode=1"cmdCommand.Execute' This is the event namestrClsDef="MusicDownload"'Create a class.'Always set SourceDefName to test_Source for new classes. CreateClassDef objConn, strClsDef, "DWSchema", "test_Source", "", _False'-- MEM1 : create non key memberlMemFlags = fGenerateColDef + fHasDefaultValstrMemDef = "Event" strMemDefType = "WSTR"strDefVal = "0"CreateMemberDef objConn, strClsDef, strMemDef, strMemDefType , _lMemFlags, strDefVal, strAggrExp
'-- MEM1 : create non key memberlMemFlags = fGenerateColDef + fHasDefaultValstrMemDef = "Artist" strMemDefType = "WSTR"strDefVal = "0"CreateMemberDef objConn, strClsDef, strMemDef, strMemDefType, _lMemFlags, strDefVal,strAggrExp lMemFlags = fGenerateColDef + fHasDefaultValstrMemDef = "Album" strMemDefType = "WSTR"strDefVal = "0"CreateMemberDef objConn, strClsDef, strMemDef, strMemDefType, _lMemFlags , strDefVal,strAggrExp '-- MEM2 : create non key memberlMemFlags = fGenerateColDef + fHasDefaultValstrMemDef = "Title" strMemDefType = "WSTR"strDefVal = "0"CreateMemberDef objConn, strClsDef, strMemDef, strMemDefType, _lMemFlags, strDefVal,strAggrExp
'The follwoing members are the required for every Commerce Event.
'-- MEM4 : create non key memberlMemFlags = fGenerateColDef + fHasDefaultValstrMemDef = "DTimeStamp" strMemDefType = "FILETIME"strDefVal = "1900-1-1 0:0:0.0"
CreateMemberDef objConn, strClsDef, strMemDef, strMemDefType, _lMemFlags, strDefVal, strAggrExp '-- MEM8 : create non key memberlMemFlags = fGenerateColDef + fHasDefaultValstrMemDef = "VisitNum" strMemDefType = "INT64"strDefVal = "0"
CreateMemberDef objConn, strClsDef, strMemDef, strMemDefType, _lMemFlags, strDefVal, strAggrExp
'-- MEM5 : create non key memberlMemFlags = fGenerateColDef + fHasDefaultValstrMemDef = "RequestIndex" strMemDefType = "SHORT"strDefVal = "0"
'-- MEM6 : create non key memberlMemFlags = fGenerateColDef + fHasDefaultValstrMemDef = "UriKey" strMemDefType = "INT64"strDefVal = "0"
'-- MEM7 : create non key memberlMemFlags = fGenerateColDef + fHasDefaultValstrMemDef = "UserKey" strMemDefType = "INT64"strDefVal = "0"
strChildClassName = strClsDefiRelType = 5 'indicating virtual relationship for performance'reasons
'-- Rel1 : create virtual relationship to uristrParentClassName = "URI"strRelDefName = strParentClassName & strChildClassName & "Rel"strParentClassKey = strParentClassName & "Key"
CreateRelDef objConn, strRelDefName, strParentClassName, _strChildClassName, strParentClassKey, iRelType
'-- Rel2 : create virtual relationship to loguserstrParentClassName = "LogUser"strRelDefName = strParentClassName & strChildClassName & "Rel"strParentClassKey = strParentClassName & "Key"
iRelType = 2 'indicating real relattionship
'-- Rel3 : create relationship to RegistereduserstrParentClassName = "RegisteredUser"strRelDefName = strParentClassName & strChildClassName & "Rel"strParentClassKey = strParentClassName & "Key"
'-- Rel4 : create relationship to SitestrParentClassName = "Site"strRelDefName = strParentClassName & strChildClassName & "Rel"strParentClassKey = strParentClassName & "Key"
'-- Rel5 : create relationship to TaskHistorystrParentClassName = "TaskHistory"strRelDefName = strParentClassName & strChildClassName & "Rel"strParentClassKey = strParentClassName & "Key"
'------------------------------------------------' Commit Schema'------------------------------------------------cmdCommand.CommandText = "CommitSchema"cmdCommand.Execute
'Turn on "Schema Change" modecmdCommand.CommandText = "SchemaMode=0"cmdCommand.Execute
End Sub
'----------------------------------------------------------------------' Procedure : CreateClassDef' Parameters : objConn' strClsDef - name of classdef to be created' strCatalog - catalog in which we want to create' strSrcDef - source definition name' strBaseClsName - this is useful for aggregations' simple classes can pass ""' bGenKeyDef = true - generate key definition ' automatically' Notes : The schema change mode should have been set to true prior' to calling this function.' '----------------------------------------------------------------------Sub CreateClassDef(objConn, strClsDef, strCatalog, strSrcDef, _strBaseClsName, bGenKeyDef)
WScript.Echo "DBG: Class : " & strClsDefDim recSet rec = CreateObject("ADODB.Record")rec.Open "Class/" & strClsDef, objConn, 3, adCreateOverwriterec("IsPersistent") = 1rec("ClassDefName") = strClsDefrec("SourceDefName") = strSrcDefrec("GeneratePartitionDef") = 1rec("GenerateTableDef") = 1If bGenKeyDef Thenrec("GenerateKeyDef") = 1Elserec("GenerateKeyDef") = 0End If'to create an aggregate class --If strBaseClsName <> "" Thenrec("BaseClassName") = strBaseClsNameEnd Ifrec("GenerateIdentity") = 1rec("__Commit") = 1rec.Fields.Updaterec.CloseEnd Sub
'----------------------------------------------------------------------' Procedure : CreateMemberDef' Purpose : Utility to create members' Parameters : objConn' strClsDef - name of classdef' strMemDef - name of member' strMemDefType - type of the memberdef' lMemFlags - MemberDef Creation flags '' Notes : User is supposed to set the schema mode to updatable and' reset after the member is created.'----------------------------------------------------------------------Sub CreateMemberDef(objConn, strClsDef, strMemDef, strMemDefType, _lMemFlags , strDefVal,strAggrExp )Dim rec ' On Error Resume NextWScript.Echo "DBG: Mem : " & strMemDefset rec = CreateObject("ADODB.Record")rec.Open "Member/" & strClsDef & "/" & strMemDef, objConn, _adModeReadWrite, adCreateOverwriterec("MemberDefName") = strMemDefIf (lMemFlags And fGenerateColDef) > 0 Then 'default caserec("GenerateColumnDef") = 1End IfIf (lMemFlags And fPrimaryKey) > 0 Thenrec("IsPrimaryKey") = 1End IfIf (lMemFlags And fMultiValued) > 0 Thenrec("IsMultiValued") = 1End IfIf (lMemFlags And fHasDefaultVal) > 0 Thenrec("DefaultValueAsStr") = strDefValEnd IfIf (lMemFlags And fIsUniqueKey) > 0 Thenrec("IsUniqueKey") = 1End IfIf (lMemFlags And fIsIdentityMember) > 0 Thenrec("IsIsIdentityMember") = 1End If
'Aggregate member, then set the aggregate expressions. if (lMemFlags And fHasAggrExp) > 0 thenrec("ExpressionStr") = strAggrExpEnd ifif (lMemFlags And fIsDimension) > 0 thenrec("IsDimension") =1End ifif (lMemFlags And fIsMeasure ) > 0 thenrec("IsMeasure") = 1End ifrec("TypeName") = strMemDefTyperec("__Commit") = 1rec.Fields.Updaterec.CloseEnd Sub
'----------------------------------------------------------------------' Procedure: CreateRelationDef' Purpose: Create a Relation Definition' Notes : The classes that the parent and child referred to must' exist. The Keydefinition for the parent must exist ' (1-M).''----------------------------------------------------------------------Sub CreateRelDef(objConn, strRelName, strClsParent, strClsChild, _strKeyParent, iRelType)Dim rec 'On Error Resume NextWScript.Echo "DBG: Rel : " & strRelNameset rec = CreateObject("ADODB.Record")rec.Open "Relation/" & strRelName, objConn, adModeWrite, _adCreateOverwriterec("ParentClassName") = strClsParentrec("ParentClasskey") = strKeyParentrec("ChildClassName") = strClsChildrec("RelType") = iRelTyperec("__Commit") = 1rec.Fields.Update
rec.CloseSet rec = NothingEnd Sub
If you want to see the sample project and also the scripts used, I have uploaded the project as a zip file in our GotDotNet Workspace located here.
For our next part of the series, I will show you how to create a new report that utilizes the MusicDownload event.
Hope this helps!
Alan