Discussion:
Extended Model Definitions - Transformations
(too old to reply)
Sean Sexton
2011-07-13 21:48:27 UTC
Permalink
Hi. I'm trying to use Extended Model Definitions and Transformations
in the following way:

Using an Extended Model Definition in my LDM, I've defined a Boolean
Extended Attribute named "Audited". Additionally, I've created an
Extended Model Definition in my PDM with a transformation attached to
the Table metaclass. The Transformation adds the standard audit
columns and the standard audit trigger to a table whose Audited
attribute is set. I obtain the Domain for each column from the
collection obj.Model.Domains. That part of the Transformation works
fine.

I'm having trouble, though, obtaining the TriggerTemplate for the
standard audit trigger I've previously defined in my PDM. Inspecting
the property obj.Model.TriggerTemplates.Count returns a value of 0,
even though I clearly have a TriggerTemplate defined.

Can anyone tell me where I've gone astray?

Sean
rkkier
2011-07-18 14:26:09 UTC
Permalink
Sounds like the it should work (you knew that). Got a code sample?
Sean Sexton
2011-07-20 15:53:17 UTC
Permalink
Here's the section of the Global Script code that the transformation
is calling. I'm using the same method to find the appropriate Domain
for the Audit columns as I'm using to find the Trigger Template. It
works fine for the Domains, of course, but not for the Trigger
Templates. It appears that the collection
oTable.Model.TriggerTemplates is empty at the time of the
transformation. Perhaps I'm going at it the wrong way?

Let me know if you have any questions about it, or (most importantly)
if you can spot where I'm going astray. Thanks!


'******************************************************************************
'* Purpose: This VB-Script holds global definitions shared by all the
custom-
'* checks scripts of the model extension.
'******************************************************************************

Option Explicit ' This is to ensure all used variables are defined

Const cStandardTriggerCode = "_STNDRD_AUD_TRIG"

Private Function GetObjectByCode(oCollection, sCode)
Dim oObject

Set GetObjectByCode = Nothing

For Each oObject In oCollection
If oObject.Code = sCode Then
Set GetObjectByCode = oObject
Exit Function
End If
Next
End Function

Private Function GetObjectByName(oCollection, sName)
Dim oObject

Set GetObjectByName = Nothing

For Each oObject In oCollection
If oObject.Name = sName Then
Set GetObjectByName = oObject
Exit Function
End If
Next
End Function

Private Sub AddColumn( oTable, sName, sDomainCode, bMandatory )
Dim oDomain, oColumn

If GetObjectByName(oTable.Columns, sName) Is Nothing Then
output "Adding " & sName & " to " & oTable.code & "."

Set oDomain = GetObjectByCode( oTable.Model.Domains,
sDomainCode )
Set oColumn = oTable.Columns.CreateNew()
oColumn.Name = sName
oColumn.SetNameToCode
Set oColumn.Domain = oDomain
oColumn.Mandatory = bMandatory
End If

End Sub

Private Function GetTrigger( oTable, sName )
Dim oTrigger

Set GetTrigger = Nothing

For Each oTrigger in oTable.Triggers
If oTrigger.Name = sName Then
Set GetTrigger = oTrigger
Exit For
End If
Next

End Function

Private Sub AddTrigger( oTable, sName, sCode, sTemplateCode )
Dim oTrigger

Set oTrigger = GetTrigger(oTable, sName)
If oTrigger Is Nothing Then
Set oTrigger = oTable.Triggers.CreateNew()
oTrigger.SetNameAndCode sName, sCode
End If

Set oTrigger.TriggerTemplate =
GetObjectByCode(oTable.Model.TriggerTemplates, sTemplateCode)

End Sub

Private Sub MakeAuditedTable(Table)

dim oTriggerTemplate

If Table.GetExtendedAttribute("Audited") Then
AddColumn Table, "Audit Proxy", "USER_NM", False
AddColumn Table, "Audit User", "USER_NM", True
AddColumn Table, "Audit Date", "DT", True

AddTrigger Table, "T Audit " & Table.Name, "T_AUD_" &
Table.Code, cStandardTriggerCode
End If

End Sub
Sounds like the it should work (you knew that).  Got a code sample?
Loading...