共用方式為


SubscriptionClass Element (ADF)

Contains the definition of one subscription class.

語法

<SubscriptionClasses>
    <SubscriptionClass>

Element Characteristics

Characteristic Description

Data type

None.

Default value

None.

Occurrence

Required once or more per SubscriptionClasses element.

Updates

Can be added and deleted when updating the application.

Element Relationships

Relationship Elements

Parent element

SubscriptionClasses Element (ADF)

Child elements

SubscriptionClassName Element (ADF)

Schema Element for SubscriptionClass (ADF)

FileGroup Element for SubscriptionClass (ADF)

IndexSqlSchema Element for SubscriptionClass (ADF)

EventRules Element (ADF)

ScheduledRules Element (ADF)

Chronicles Element for SubscriptionClass (ADF)

備註

If you delete a SubscriptionClass element, updating the application removes the subscription class and renames the existing subscription tables by appending Old to the table name. Existing subscription table indexes are left unchanged.

If you want to transfer data between the old and new subscription tables, it must be done manually. For more information, see 更新應用程式.

範例

The following example shows a SubscriptionClass element that defines a subscription class for stock notifications. The subscription class does the following:

  • Defines the subscriptions table, places the table in the Secondary filegroup, and defines an index for the table on the SubscriberID column, which Notification Services automatically includes in the subscription class schema.
  • Creates an event rule for the subscription class that generates event-triggered notifications and updates the subscription chronicle.
  • Creates a scheduled rule for the subscription class that generates scheduled subscriptions and updates the subscription chronicle.
  • Creates the subscription chronicle.
<SubscriptionClass>
    <SubscriptionClassName>StockSubscriptions</SubscriptionClassName>
    <Schema>
        <Field>
            <FieldName>DeviceName</FieldName>
            <FieldType>nvarchar(255)</FieldType>
            <FieldTypeMods>NOT NULL</FieldTypeMods>
        </Field>
        <Field>
            <FieldName>SubscriberLocale</FieldName>
            <FieldType>nvarchar(10)</FieldType>
            <FieldTypeMods>NOT NULL</FieldTypeMods>
        </Field>
        <Field>
            <FieldName>StockSymbol</FieldName>
            <FieldType>char(10)</FieldType>
            <FieldTypeMods>NOT NULL</FieldTypeMods>
        </Field>
        <Field>
            <FieldName>StockTriggerPrice</FieldName>
            <FieldType>money</FieldType>
            <FieldTypeMods>NOT NULL DEFAULT 10</FieldTypeMods>
        </Field>
    </Schema>
    <FileGroup>Secondary</FileGroup>
    <IndexSqlSchema>
        <SqlStatement>
        CREATE INDEX StockSubIndex 
        ON StockSubscriptions (SubscriberId);
        </SqlStatement>
    </IndexSqlSchema>
    <EventRules>
        <EventRule>
            <RuleName>StockSubscriptionNotifyRule</RuleName>
            <Action>
            -- Generate event-triggered notifications
            INSERT INTO StockNotifications 
            ( SubscriberId, DeviceName, SubscriberLocale,
            StockSymbol, StockPrice )
            SELECT S.SubscriberId, S.DeviceName,
                S.SubscriberLocale, E.StockSymbol, E.StockPrice
            FROM StockSubscriptions S JOIN StockEvents E
            ON S.StockSymbol = E.StockSymbol
            JOIN StockEventChron C
            ON S.StockSymbol = C.StockSymbol
            WHERE S.StockTriggerPrice &lt;= E.StockPrice
            AND S.StockTriggerPrice &gt; C.StockHighPrice;
            -- Maintain subscription chronicle
            INSERT StockSubscriptionChron
            (SubscriberId, StockSymbol, StockPrice)
            SELECT S.SubscriberId, S.StockSymbol, E.StockPrice
            FROM StockSubscriptions S JOIN StockEvents E
            ON S.StockSymbol = E.StockSymbol;
            </Action>
            <ActionTimeout>P0DT00H01M00S</ActionTimeout>
            <EventClassName>StockEvents</EventClassName>
        </EventRule>
    </EventRules>
    <ScheduledRules>
        <ScheduledRule>
            <RuleName>StockSubScheduledRule</RuleName>
            <Action>
            -- Generate scheduled notifications
            INSERT INTO ScheduledNotifications
            ( SubscriberId, DeviceName, SubscriberLocale,
            StockSymbol, StockPrice )
            SELECT S.SubscriberId, S.DeviceName, 
                S.SubscriberLocale, C.StockSymbol, C.StockPrice
            FROM StockSubscriptions S JOIN StockEventChron C
            ON S.StockSymbol = C.StockSymbol 
            WHERE S.StockTriggerPrice &lt;= C.StockHighPrice 
            GROUP BY S.StockSymbol, C.StockHighPrice;
            -- Maintain subscription chronicle
            INSERT StockSubscriptionChron
            (SubscriberId, StockSymbol, StockPrice)
            SELECT S.SubscriberId, S.StockSymbol, C.StockHighPrice
            FROM StockSubscriptions S JOIN StockEventChron C
            ON S.StockSymbol = C.StockSymbol;
            </Action>
            <ActionTimeout>P0DT00H00M45S</ActionTimeout>
        </ScheduledRule>
    </ScheduledRules>
    <Chronicles>
        <Chronicle>
            <ChronicleName>StockSubscriptionChron</ChronicleName>
            <SqlSchema>
                <SqlStatement>
                IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES 
                WHERE TABLE_NAME = &apos;StockSubscriptionChron&apos;)
                DROP TABLE StockSubscriptionChron;
                </SqlStatement>
                <SqlStatement>
                CREATE TABLE StockSubscriptionChron
                (
                SubscriberId bigint,
                StockSymbol char(10),
                StockPrice money
                PRIMARY KEY (SubscriberId)
                );
                </SqlStatement>
            </SqlSchema>
        </Chronicle>
    </Chronicles>
</SubscriptionClass>

請參閱

參考

Application Definition File Reference

其他資源

定義核心訂閱類別
更新執行個體及應用程式

說明及資訊

取得 SQL Server 2005 協助