SubscriptionClass Class
Notification Services アプリケーション内のサブスクリプション クラスを表します。
名前空間: Microsoft.SqlServer.Management.Nmo
アセンブリ: Microsoft.SqlServer.Smo (microsoft.sqlserver.smo.dll 内)
構文
'宣言
Public NotInheritable Class SubscriptionClass
Inherits NamedSmoObject
public sealed class SubscriptionClass : NamedSmoObject
public ref class SubscriptionClass sealed : public NamedSmoObject
public final class SubscriptionClass extends NamedSmoObject
public final class SubscriptionClass extends NamedSmoObject
解説
サブスクリプション クラスは、アプリケーションのサブスクリプションを 1 種類定義します。Notification Services アプリケーションを定義するときには、アプリケーションによってサポートされるサブスクリプションの種類ごとに、サブスクリプション クラスを 1 つ作成する必要があります。
Notification Services によってアプリケーションが作成されるときには、サブスクリプション クラスのテーブル、ビュー、基本インデックス、およびストアド プロシージャが作成されます。主要なサブスクリプション クラス プロパティでは、これらのデータベース オブジェクトの名前と場所が定義されます。
継承階層
System.Object
Microsoft.SqlServer.Management.Smo.SmoObjectBase
Microsoft.SqlServer.Management.Smo.SqlSmoObject
Microsoft.SqlServer.Management.Smo.NamedSmoObject
Microsoft.SqlServer.Management.Nmo.SubscriptionClass
使用例
完全なサブスクリプション クラスの例を次に示します。この例は使用可能なプロパティとそれらを定義する方法を示していますが、実際のアプリケーションのサブスクリプション クラスでは、必ずしもここで示されているすべてのプロパティが使用されるわけではありません。
// Create a subscription class
SubscriptionClass flightSubscriptions =
new SubscriptionClass(myApplication, "FlightSubscriptions");
flightSubscriptions.FileGroup = "PRIMARY";
// Define subscription class fields
// Define a DeviceName field that cannot be NULL
// Add the field to the end of the field collection
SubscriptionField subDevice =
new SubscriptionField(flightSubscriptions, "DeviceName");
subDevice.Type = "nvarchar(255)";
subDevice.TypeModifier = "not null";
flightSubscriptions.SubscriptionFields.Add(subDevice);
// Define a SubscriberLocale field that cannot be NULL
// Add the field to the end of the field collection
SubscriptionField subLocale =
new SubscriptionField(flightSubscriptions, "SubscriberLocale");
subLocale.Type = "nvarchar(10)";
subLocale.TypeModifier = "not null";
flightSubscriptions.SubscriptionFields.Add(subLocale);
// Add a GoingTo field and add it at position 2
SubscriptionField subDestination =
new SubscriptionField(flightSubscriptions, "GoingTo");
subDestination.Type = "nvarchar(6)";
flightSubscriptions.SubscriptionFields.Add(subDestination, 2);
// Define a LeavingFrom field and add it before the GoingTo field
SubscriptionField subOrgin =
new SubscriptionField(flightSubscriptions, "LeavingFrom");
subOrgin.Type = "nvarchar(6)";
flightSubscriptions.SubscriptionFields.Add(subOrgin, "GoingTo");
// Define a Price field and add to the end of the collection
SubscriptionField subPrice =
new SubscriptionField(flightSubscriptions, "Price");
subPrice.Type = "float";
flightSubscriptions.SubscriptionFields.Add(subPrice);
// Add an index to the subscription class.
flightSubscriptions.IndexSqlStatements.Add(
"CREATE INDEX FlightSubscriptionsIndex ON " +
"MyAppSchema.FlightSubscriptions ( LeavingFrom, GoingTo )");
// Add a rule to generate basic event-triggered notifications
SubscriptionEventRule flightEventRule =
new SubscriptionEventRule(flightSubscriptions,
"FlightSubscriptionsEventRule");
flightEventRule.Action = "INSERT INTO FlightNotifications " +
"(SubscriberId, DeviceName, SubscriberLocale, " +
"LeavingFrom, GoingTo, Price) " +
"SELECT S.SubscriberId, S.DeviceName, S.SubscriberLocale, " +
"E.LeavingFrom, E.GoingTo, E.Price " +
"FROM FlightEvents E, FlightSubscriptions S " +
"WHERE E.LeavingFrom = S.LeavingFrom " +
"AND E.GoingTo = S.GoingTo " +
"AND E.Price < S.Price";
flightEventRule.ActionTimeout = new TimeSpan(0, 1, 0);
flightEventRule.EventClassName = "FlightEvents";
flightSubscriptions.SubscriptionEventRules.Add(flightEventRule);
// Add a rule to generate basic scheduled notifications
SubscriptionScheduledRule flightScheduledRule =
new SubscriptionScheduledRule(
flightSubscriptions, "FlightScheduledRule");
flightScheduledRule.Action = "INSERT INTO FlightNotifications " +
"(SubscriberId, DeviceName, SubscriberLocale, " +
" LeavingFrom, GoingTo, Price) " +
" SELECT S.SubscriberId, S.DeviceName, S.SubscriberLocale, " +
" EC.LeavingFrom, EC.GoingTo, EC.Price " +
" FROM FlightEventChronicle EC, FlightSubscriptions S " +
" WHERE EC.LeavingFrom = S.LeavingFrom " +
" AND EC.GoingTo = S.GoingTo " +
" AND EC.Price < S.Price";
flightScheduledRule.ActionTimeout = new TimeSpan(0, 0, 30);
flightSubscriptions.SubscriptionScheduledRules.Add(
flightScheduledRule);
// Add a rule to generate condition-based, event notifications
SubscriptionConditionEventRule flightConditionEventRule =
new SubscriptionConditionEventRule(
flightSubscriptions, "FlightConditionEventRule");
flightConditionEventRule.EventClassName = "FlightEvents";
flightConditionEventRule.ActionTimeout = new TimeSpan(0, 2, 0);
flightConditionEventRule.SqlLoginName = "MyLowPrivLogin";
flightConditionEventRule.SqlUserName = "MyLowPrivUser";
flightConditionEventRule.InputTypeName = "FlightEvents";
flightConditionEventRule.InputTypeSchema = "MyAppSchema";
flightConditionEventRule.SqlExpression =
"INSERT INTO MyAppSchema.FlightNotifications (SubscriberId, " +
"DeviceName, SubscriberLocale, LeavingFrom, GoingTo, Price) " +
"SELECT [Subscription.SubscriberId], [Subscription.DeviceName], " +
"[Subscription.SubscriberLocale], " +
"[Input.LeavingFrom], [Input.GoingTo], [Input.Price] " +
"FROM MyAppSchema.FlightConditionEventRule;";
flightSubscriptions.SubscriptionConditionEventRules.Add(
flightConditionEventRule);
// Add a rule to generate condition-based, scheduled notifications
SubscriptionConditionScheduledRule flightConditionScheduledRule =
new SubscriptionConditionScheduledRule(
flightSubscriptions, "FlightConditionScheduledRule");
flightConditionScheduledRule.ActionTimeout =
new TimeSpan(0, 2, 0);
flightConditionScheduledRule.SqlLoginName = "MyLowPrivLogin";
flightConditionScheduledRule.SqlUserName = "MyLowPrivUser";
flightConditionScheduledRule.InputTypeName = "FlightEventChronicle";
flightConditionScheduledRule.InputTypeSchema = "MyAppSchema";
flightConditionScheduledRule.SqlExpression =
"INSERT INTO MyAppSchema.FlightNotifications (SubscriberId, " +
"DeviceName, SubscriberLocale, LeavingFrom, GoingTo, Price) " +
"SELECT [Subscription.SubscriberId], " +
"[Subscription.DeviceName], [Subscription.SubscriberLocale], " +
"[Input.LeavingFrom], [Input.GoingTo], [Input.Price] " +
"FROM MyAppSchema.FlightConditionScheduledRule;";
flightSubscriptions.SubscriptionConditionScheduledRules.Add(
flightConditionScheduledRule);
// Define a chronicle for the subscription class
SubscriptionChronicle sc1 = new SubscriptionChronicle(
flightSubscriptions, "FlightSubChronicle");
sc1.SqlStatements.Add(
"CREATE TABLE MyAppSchema.FlightSubChronicle " +
" (SubscriptionId bigint, LeavingFrom nvarchar(6), " +
" GoingTo nvarchar(6), Price float);");
sc1.SqlStatements.Add(
"CREATE INDEX FlightSubChronicleIndex " +
" ON MyAppSchema.FlightSubChronicle " +
" ( LeavingFrom, GoingTo );");
flightSubscriptions.SubscriptionChronicles.Add(sc1);
// Add the subscription class to the application
myApplication.SubscriptionClasses.Add(flightSubscriptions);
' Create a subscription class
Dim flightSubscriptions As SubscriptionClass = _
New SubscriptionClass(myApplication, "FlightSubscriptions")
flightSubscriptions.FileGroup = "PRIMARY"
' Define subscription class fields
' Define a DeviceName field that cannot be NULL
' Add the field to the end of the field collection
Dim subDevice As SubscriptionField = _
New SubscriptionField(flightSubscriptions, "DeviceName")
subDevice.Type = "nvarchar(255)"
subDevice.TypeModifier = "not null"
flightSubscriptions.SubscriptionFields.Add(subDevice)
' Define a SubscriberLocale field that cannot be NULL
' Add the field to the end of the field collection
Dim subLocale As SubscriptionField = _
New SubscriptionField(flightSubscriptions, _
"SubscriberLocale")
subLocale.Type = "nvarchar(10)"
subLocale.TypeModifier = "not null"
flightSubscriptions.SubscriptionFields.Add(subLocale)
' Add a GoingTo field and add it at position 2
Dim subDestination As SubscriptionField = _
New SubscriptionField(flightSubscriptions, "GoingTo")
subDestination.Type = "nvarchar(6)"
flightSubscriptions.SubscriptionFields.Add(subDestination, 2)
' Define a LeavingFrom field and add it before the GoingTo field
Dim subOrgin As SubscriptionField = _
New SubscriptionField(flightSubscriptions, "LeavingFrom")
subOrgin.Type = "nvarchar(6)"
flightSubscriptions.SubscriptionFields.Add(subOrgin, "GoingTo")
' Define a Price field and add to the end of the collection
Dim subPrice As SubscriptionField = _
New SubscriptionField(flightSubscriptions, "Price")
subPrice.Type = "float"
flightSubscriptions.SubscriptionFields.Add(subPrice)
' Add an index to the subscription class to help improve performance
flightSubscriptions.IndexSqlStatements.Add( _
"CREATE INDEX FlightSubscriptionsIndex ON " + _
"MyAppSchema.FlightSubscriptions ( LeavingFrom, GoingTo )")
' Add a rule to generate basic event-triggered notifications
Dim flightEventRule As SubscriptionEventRule = _
New SubscriptionEventRule(flightSubscriptions, _
"FlightSubscriptionsEventRule")
flightEventRule.Action = _
"INSERT INTO FlightNotifications " + _
"(SubscriberId, DeviceName, SubscriberLocale, " + _
"LeavingFrom, GoingTo, Price) " + _
"SELECT S.SubscriberId, S.DeviceName, S.SubscriberLocale, " + _
"E.LeavingFrom, E.GoingTo, E.Price " + _
"FROM FlightEvents E, FlightSubscriptions S " + _
"WHERE E.LeavingFrom = S.LeavingFrom " + _
"AND E.GoingTo = S.GoingTo " + _
"AND E.Price < S.Price"
flightEventRule.ActionTimeout = New TimeSpan(0, 1, 0)
flightEventRule.EventClassName = "FlightEvents"
flightSubscriptions.SubscriptionEventRules.Add(flightEventRule)
' Add a rule to generate basic scheduled notifications
Dim flightScheduledRule As SubscriptionScheduledRule = _
New SubscriptionScheduledRule(flightSubscriptions, _
"FlightScheduledRule")
flightScheduledRule.Action = _
"INSERT INTO FlightNotifications " + _
"(SubscriberId, DeviceName, SubscriberLocale, " + _
"LeavingFrom, GoingTo, Price) " + _
"SELECT S.SubscriberId, S.DeviceName, S.SubscriberLocale, " + _
"EC.LeavingFrom, EC.GoingTo, EC.Price " + _
"FROM FlightEventChronicle EC, FlightSubscriptions S " + _
"WHERE EC.LeavingFrom = S.LeavingFrom " + _
"AND EC.GoingTo = S.GoingTo " + _
"AND EC.Price < S.Price"
flightScheduledRule.ActionTimeout = New TimeSpan(0, 0, 30)
flightSubscriptions.SubscriptionScheduledRules.Add( _
flightScheduledRule)
' Add a rule to generate condition-based, event notifications
Dim flightConditionEventRule As _
SubscriptionConditionEventRule = _
New SubscriptionConditionEventRule( _
flightSubscriptions, "FlightConditionEventRule")
flightConditionEventRule.EventClassName = "FlightEvents"
flightConditionEventRule.ActionTimeout = New TimeSpan(0, 2, 0)
flightConditionEventRule.SqlLoginName = "MyLowPrivLogin"
flightConditionEventRule.SqlUserName = "MyLowPrivUser"
flightConditionEventRule.InputTypeName = "FlightEvents"
flightConditionEventRule.InputTypeSchema = "MyAppSchema"
flightConditionEventRule.SqlExpression = _
"INSERT INTO MyAppSchema.FlightNotifications " + _
"(SubscriberId, DeviceName, SubscriberLocale, LeavingFrom, " + _
"GoingTo, Price) SELECT [Subscription.SubscriberId], " + _
"[Subscription.DeviceName], [Subscription.SubscriberLocale], " + _
"[Input.LeavingFrom], [Input.GoingTo], [Input.Price] " + _
"FROM MyAppSchema.FlightConditionEventRule;"
flightSubscriptions.SubscriptionConditionEventRules.Add( _
flightConditionEventRule)
' Add a rule to generate condition-based, scheduled notifications
Dim flightConditionScheduledRule As _
SubscriptionConditionScheduledRule = _
New SubscriptionConditionScheduledRule( _
flightSubscriptions, "FlightConditionScheduledRule")
flightConditionScheduledRule.ActionTimeout = _
New TimeSpan(0, 2, 0)
flightConditionScheduledRule.SqlLoginName = "MyLowPrivLogin"
flightConditionScheduledRule.SqlUserName = "MyLowPrivUser"
flightConditionScheduledRule.InputTypeName = _
"FlightEventChronicle"
flightConditionScheduledRule.InputTypeSchema = "MyAppSchema"
flightConditionScheduledRule.SqlExpression = _
"INSERT INTO MyAppSchema.FlightNotifications " + _
"(SubscriberId, DeviceName, SubscriberLocale, LeavingFrom, " + _
"GoingTo, Price) SELECT [Subscription.SubscriberId], " + _
"[Subscription.DeviceName], [Subscription.SubscriberLocale], " + _
"[Input.LeavingFrom], [Input.GoingTo], [Input.Price] " + _
"FROM MyAppSchema.FlightConditionScheduledRule;"
flightSubscriptions.SubscriptionConditionScheduledRules.Add( _
flightConditionScheduledRule)
' Define a chronicle for the subscription class
Dim sc1 As SubscriptionChronicle = New SubscriptionChronicle( _
flightSubscriptions, "FlightSubChronicle")
sc1.SqlStatements.Add( _
"CREATE TABLE MyAppSchema.FlightSubChronicle " + _
"(SubscriptionId bigint, LeavingFrom nvarchar(6), " + _
"GoingTo nvarchar(6), Price float);")
sc1.SqlStatements.Add( _
"CREATE INDEX FlightSubChronicleIndex " + _
"ON MyAppSchema.FlightSubChronicle " + _
"( LeavingFrom, GoingTo );")
flightSubscriptions.SubscriptionChronicles.Add(sc1)
' Add the subscription class to the application
myApplication.SubscriptionClasses.Add(flightSubscriptions)
スレッド セーフ
この型の public static (Microsoft Visual Basic では共有 ) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォーム
開発プラットフォーム
サポートされているプラットフォームの一覧については、「SQL Server 2005 のインストールに必要なハードウェアおよびソフトウェア」を参照してください。
対象プラットフォーム
サポートされているプラットフォームの一覧については、「SQL Server 2005 のインストールに必要なハードウェアおよびソフトウェア」を参照してください。
参照
関連項目
SubscriptionClass Members
Microsoft.SqlServer.Management.Nmo Namespace