我們示例模式的SQL映射提供了以下XML文檔:
<schema mappingType="sql" name="recipient" namespace="cus" xtkschema="xtk:schema">
<enumeration basetype="byte" name="gender">
<value label="Not specified" name="unknown" value="0"/>
<value label="Male" name="male" value="1"/>
<value label="Female" name="female" value="2"/>
</enumeration>
<element name="recipient" sqltable="CusRecipient">
<attribute desc="Recipient e-mail address" label="Email" length="80" name="email" sqlname="sEmail" type="string"/>
<attribute default="GetDate()" label="Date of creation" name="created" sqlname="tsCreated" type="datetime"/>
<attribute enum="gender" label="Gender" name="gender" sqlname="iGender" type="byte"/>
<element label="Location" name="location">
<attribute label="City" length="50" name="city" sqlname="sCity" type="string" userEnum="city"/>
</element>
</element>
</schema>
架構的根元素不再是<srcschema>
,而是<schema>
。
這會帶我們到另一種類型的文檔,它自動從源模式生成,簡稱為模式。 Adobe Campaign應用程式將會使用此結構。
SQL名稱會根據元素名稱和類型自動確定。
SQL命名規則如下:
表格:架構名稱空間和名稱的級聯
在我們的示例中,表的名稱是通過sqltable屬性中模式的主元素輸入的:
<element name="recipient" sqltable="CusRecipient">
欄位:元素的名稱,前面加上根據類型定義的首碼('i'代表整數,'d'代表雙重,'s'代表字串,'ts'代表日期等)
通過sqlname屬性輸入欄位名稱,用於鍵入每個<attribute>
和<element>
:
<attribute desc="E-mail address of recipient" label="Email" length="80" name="email" sqlname="sEmail" type="string"/>
SQL名稱可以從源方案過載。 要執行此操作,請在相關元素上填充「sqltable」或「sqlname」屬性。
建立從擴展模式生成的表的SQL指令碼如下:
CREATE TABLE CusRecipient(
iGender NUMERIC(3) NOT NULL Default 0,
sCity VARCHAR(50),
sEmail VARCHAR(80),
tsCreated TIMESTAMP Default NULL);
SQL欄位約束如下:
預設情況下,所有鍵入的<attribute>
和<element>
元素都映射到資料模式表的SQL欄位。 但是,您可以在XML中引用此欄位,而不是SQL,這表示資料儲存在包含所有XML欄位值的表的備注欄位(「mData」)中。 這些資料的儲存是一份XML檔案,可觀察架構結構。
若要在XML中填入欄位,您必須將xml屬性與值"true"新增至相關元素。
範例:以下是兩個XML欄位使用範例。
多行注釋欄位:
<element name="comment" xml="true" type="memo" label="Comment"/>
HTML格式的資料說明:
<element name="description" xml="true" type="html" label="Description"/>
「html」類型可讓您將HTML內容儲存在CDATA標籤中,並在Adobe Campaign用戶端介面中顯示特殊的HTML編輯檢查。
使用XML欄位可以添加欄位,而無需修改資料庫的物理結構。 另一個優勢是,您使用的資源較少(分配給SQL欄位的大小、每個表的欄位數限制等)。
主要缺點是無法對XML欄位進行索引或篩選。
索引可以優化應用程式中使用的SQL查詢的效能。
從資料模式的主元素中聲明索引。
<dbindex name="name_of_index" unique="true/false">
<keyfield xpath="xpath_of_field1"/>
<keyfield xpath="xpath_of_field2"/>
...
</key>
索引遵循下列規則:
索引作為標準,是從架構的主要元素中聲明的第一個元素。
索引在表映射期間(標準或FDA)自動建立。
範例:
向電子郵件地址和城市添加索引:
<srcSchema name="recipient" namespace="cus">
<element name="recipient">
<dbindex name="email">
<keyfield xpath="@email"/>
<keyfield xpath="location/@city"/>
</dbindex>
<attribute name="email" type="string" length="80" label="Email" desc="E-mail address of recipient"/>
<element name="location" label="Location">
<attribute name="city" type="string" length="50" label="City" userEnum="city"/>
</element>
</element>
</srcSchema>
將唯一索引新增至「id」名稱欄位:
<srcSchema name="recipient" namespace="cus">
<element name="recipient">
<dbindex name="id" unique="true">
<keyfield xpath="@id"/>
</dbindex>
<dbindex name="email">
<keyfield xpath="@email"/>
</dbindex>
<attribute name="id" type="long" label="Identifier"/>
<attribute name="email" type="string" length="80" label="Email" desc="E-mail address of recipient"/>
</element>
</srcSchema>
表必須至少有一個用於標識表中記錄的鍵。
從資料模式的主元素中聲明密鑰。
<key name="name_of_key">
<keyfield xpath="xpath_of_field1"/>
<keyfield xpath="xpath_of_field2"/>
...
</key>
鍵符合下列規則:
作為標準,鍵是在定義索引後從架構的主要元素聲明的元素。
索引鍵是在表格對應(標準或FDA)期間建立,Adobe Campaign會尋找唯一索引。
範例:
將密鑰添加到電子郵件地址和城市:
<srcSchema name="recipient" namespace="cus">
<element name="recipient">
<key name="email">
<keyfield xpath="@email"/>
<keyfield xpath="location/@city"/>
</key>
<attribute name="email" type="string" length="80" label="Email" desc="E-mail address of recipient"/>
<element name="location" label="Location">
<attribute name="city" type="string" length="50" label="City" userEnum="city"/>
</element>
</element>
</srcSchema>
生成的架構:
<schema mappingType="sql" name="recipient" namespace="cus" xtkschema="xtk:schema">
<element name="recipient" sqltable="CusRecipient">
<dbindex name="email" unique="true">
<keyfield xpath="@email"/>
<keyfield xpath="location/@city"/>
</dbindex>
<key name="email">
<keyfield xpath="@email"/>
<keyfield xpath="location/@city"/>
</key>
<attribute desc="E-mail address of recipient" label="Email" length="80" name="email" sqlname="sEmail" type="string"/>
<element label="Location" name="location">
<attribute label="City" length="50" name="city" sqlname="sCity" type="string" userEnum="city"/>
</element>
</element>
</schema>
在"id"名稱欄位中新增主要或內部金鑰:
<srcSchema name="recipient" namespace="cus">
<element name="recipient">
<key name="id" internal="true">
<keyfield xpath="@id"/>
</key>
<key name="email" noDbIndex="true">
<keyfield xpath="@email"/>
</key>
<attribute name="id" type="long" label="Identifier"/>
<attribute name="email" type="string" length="80" label="Email" desc="E-mail address of recipient"/>
</element>
</srcSchema>
生成的架構:
<schema mappingType="sql" name="recipient" namespace="cus" xtkschema="xtk:schema">
<element name="recipient" sqltable="CusRecipient">
<key name="email">
<keyfield xpath="@email"/>
</key>
<dbindex name="id" unique="true">
<keyfield xpath="@id"/>
</dbindex>
<key internal="true" name="id">
<keyfield xpath="@id"/>
</key>
<attribute label="Identifier" name="id" sqlname="iRecipientId" type="long"/>
<attribute desc="E-mail address of recipient" label="Email" length="80" name="email" sqlname="sEmail" type="string"/>
</element>
</schema>
大部分Adobe Campaign表格的主要索引鍵是資料庫引擎自動產生的32位元長整數。 密鑰值的計算取決於生成整個資料庫中唯一的數字的序列(預設情況下,XtkNewId SQL函式)。 在插入記錄時自動輸入該密鑰的內容。
增量密鑰的優點是,它為表之間的連接提供了不可修改的技術密鑰。 此外,由於此鍵使用雙位元組整數,因此不佔用太多記憶體。
您可以在源方案中指定要與pkSequence屬性一起使用的序列的名稱。 如果源模式中未提供此屬性,則將使用XtkNewId預設序列。 應用程式使用專用序列作為nms:broadLog和nms:trackingLog方案(分別為NmsBroadLogId和NmsTrackingLogId),因為這些表包含最多記錄。
從ACC 18.10,XtkNewId不再是現成方案中序列的預設值。 您現在可以建立架構,或使用專用序列擴充現有架構。
建立新模式或在模式擴展期間,需要為整個模式保留相同的主鍵序列值(@pkSequence)。
Adobe Campaign架構中引用的序列(例如NmsTrackingLogId)必須與SQL函式關聯,該函式會傳回參數中的ID數,並以逗號分隔。 此函式必須稱為GetNew XXX Ids,其中XXX是序列的名稱(例如GetNewNmsTrackingLogIds)。 查看隨datakit/nms/eng/sql/目錄中的應用程式提供的postgres-nmssql、mssql-nmssql或oracle-nmssql檔案,以恢復「NmsTrackingLogId」的示例為每個資料庫引擎建立序列。
要聲明唯一鍵,請在資料架構的主要元素上填入autopk屬性(值為"true")。
範例:
在源模式中聲明增量密鑰:
<srcSchema name="recipient" namespace="cus">
<element name="recipient" autopk="true">
...
</element>
</srcSchema>
生成的架構:
<schema mappingType="sql" name="recipient" namespace="cus" xtkschema="xtk:schema">
<element name="recipient" autopk="true" pkSequence="XtkNewId" sqltable="CusRecipient">
<dbindex name="id" unique="true">
<keyfield xpath="@id"/>
</dbindex>
<key internal="true" name="id">
<keyfield xpath="@id"/>
</key>
<attribute desc="Internal primary key" label="Primary key" name="id" sqlname="iRecipientId" type="long"/>
</element>
</schema>
除了索引和索引的定義外,已將名為"id"的數值欄位新增至擴充架構,以包含自動產生的主索引鍵。
建立表時,將自動插入主鍵設定為0的記錄。 此記錄用於避免對卷表無效的外部連接。 預設情況下,所有外鍵都以值0初始化,以便在未填充資料項時,始終可以在連接時返回結果。
連結描述了一個表和另一個表之間的關聯。
各種關聯類型(稱為「基數」)如下:
在介面中,您可透過其圖示,輕鬆區分不同類型的關係。
對於與促銷活動表/資料庫的連接關係:
對於使用同盟資料庫訪問的連接關係:
有關FDA表的詳細資訊,請參閱訪問外部資料庫。
必須在包含通過主元素連結的表的外鍵的架構中聲明連結:
<element name="name_of_link" type="link" target="key_of_destination_schema">
<join xpath-dst="xpath_of_field1_destination_table" xpath-src="xpath_of_field1_source_table"/>
<join xpath-dst="xpath_of_field2_destination_table" xpath-src="xpath_of_field2_source_table"/>
...
</element>
連結遵循下列規則:
在link-type <element>
上輸入連結的定義,其屬性如下:
名稱:源表中連結的名稱,
目標:目標方案的名稱、
標籤:連結標籤,
revLink (可選):目標架構的反向連結名稱(預設會自動推斷),
完整性 (可選):源表的出現與目標表的出現的參照完整性。可能的值如下:
revIntegrity (可選):目標架構上的完整性(預設情況下為「正常」,為可選),
revCardinality (可選):值"single"會填入1-1(預設為1-N)的基數。
externalJoin (可選):強制外連接
revExternalJoin (可選):將外連接強制在反向連接上
連結將源表中的一個或多個欄位引用到目標表。 組成連接(<join>
元素)的欄位無需填充,因為預設情況下,這些欄位會使用目標模式的內部鍵自動推導。
索引會自動添加到擴展模式中連結的外鍵。
連結由兩個半連結組成,其中第一個連結從源模式聲明,第二個連結在目標模式的擴展模式中自動建立。
如果添加了externalJoin屬性,且值為"true"(在PostgreSQL中受支援),則連接可以是外部連接。
作為標準,連結是在架構末尾聲明的元素。
1-N與"cus:company"模式表的關係:
<srcSchema name="recipient" namespace="cus">
<element name="recipient">
...
<element label="Company" name="company" revIntegrity="define" revLabel="Contact" target="cus:company" type="link"/>
</element>
</srcSchema>
生成的架構:
<schema mappingType="sql" name="recipient" namespace="cus" xtkschema="xtk:schema">
<element name="recipient" sqltable="CusRecipient">
<dbindex name="companyId">
<keyfield xpath="@company-id"/>
</dbindex>
...
<element label="Company" name="company" revLink="recipient" target="cus:company" type="link">
<join xpath-dst="@id" xpath-src="@company-id"/>
</element>
<attribute advanced="true" label="Foreign key of 'Company' link (field 'id')" name="company-id" sqlname="iCompanyId" type="long"/>
</element>
</schema>
連結定義由組成連接的欄位補充,即目標模式中具有其XPath("@id")的主鍵,以及模式中具有其XPath("@company-id")的外鍵。
外鍵會自動添加到使用與目標表中的關聯欄位相同特徵的元素中,並使用以下命名約定:目標架構的名稱,後面接著關聯欄位的名稱(我們範例中的「company-id」)。
目標的擴展模式("cus:company"):
<schema mappingType="sql" name="company" namespace="cus" xtkschema="xtk:schema">
<element name="company" sqltable="CusCompany" autopk="true">
<dbindex name="id" unique="true">
<keyfield xpath="@id"/>
</dbindex>
<key internal="true" name="id">
<keyfield xpath="@id"/>
</key>
...
<attribute desc="Internal primary key" label="Primary key" name="id" sqlname="iCompanyId" type="long"/>
...
<element belongsTo="cus:recipient" integrity="define" label="Contact" name="recipient" revLink="company" target="nms:recipient" type="link" unbound="true">
<join xpath-dst="@company-id" xpath-src="@id"/>
</element>
</element>
</schema>
已新增「cus:recipient」表格的反向連結,並包含下列參數:
在此示例中,我們將聲明指向"nms:address"模式表的鏈路。 該連接是外部連接,並顯式填入了收件人的電子郵件地址和連結表的「@address」欄位(「nms:address」)。
<srcSchema name="recipient" namespace="cus">
<element name="recipient">
...
<element integrity="neutral" label="Info about email" name="emailInfo" revIntegrity="neutral" revLink="recipient" target="nms:address" type="link" externalJoin="true">
<join xpath-dst="@address" xpath-src="@email"/>
</element>
</element>
</srcSchema>
與"cus:extension"模式表的1-1關係:
<element integrity="own" label="Extension" name="extension" revCardinality="single" revLink="recipient" target="cus:extension" type="link"/>
連結至資料夾("xtk:folder"結構):
<element default="DefaultFolder('nmsFolder')" label="Folder" name="folder" revDesc="Recipients in the folder" revIntegrity="own" revLabel="Recipients" target="xtk:folder" type="link"/>
預設值返回在"DefaultFolder('nmsFolder')"函式中輸入的第一個合格參數類型檔案的標識符。
在此範例中,我們希望在連結(「company」 to "cus:company"結構)上建立一個索引鍵,其中包含xlink屬性和("email")表格的欄位:
<srcSchema name="recipient" namespace="cus">
<element name="recipient">
<key name="companyEmail">
<keyfield xpath="@email"/>
<keyfield xlink="company"/>
</key>
<attribute name="email" type="string" length="80" label="Email" desc="Recipient email"/>
<element label="Company" name="company" revIntegrity="define" revLabel="Contact" target="cus:company" type="link"/>
</element>
</srcSchema>
生成的架構:
<schema mappingType="sql" name="recipient" namespace="cus" xtkschema="xtk:schema">
<element name="recipient" sqltable="CusRecipient">
<dbindex name="companyId">
<keyfield xpath="@company-id"/>
</dbindex>
<dbindex name="companyEmail" unique="true">
<keyfield xpath="@email"/>
<keyfield xpath="@company-id"/>
</dbindex>
<key name="companyEmail">
<keyfield xpath="@email"/>
<keyfield xpath="@company-id"/>
</key>
<attribute desc="E-mail address of recipient" label="Email" length="80" name="email" sqlname="sEmail" type="string"/>
<element label="Company" name="company" revLink="recipient" target="sfa:company" type="link">
<join xpath-dst="@id" xpath-src="@company-id"/>
</element>
<attribute advanced="true" label="Foreign key of link 'Company' (field 'id')" name="company-id" sqlname="iCompanyId" type="long"/>
</element>
</schema>
「companyEmail」名稱鍵的定義已與「company」連結的外鍵延伸。 此索引鍵會在兩個欄位上產生唯一索引。