Generator 클래스

데이터 생성기에 대한 추상 기본 클래스를 나타냅니다.

상속 계층 구조

System.Object
  Microsoft.Data.Schema.Tools.DataGenerator.Generator

네임스페이스:  Microsoft.Data.Schema.Tools.DataGenerator
어셈블리:  Microsoft.Data.Schema.Tools(Microsoft.Data.Schema.Tools.dll)

구문

‘선언
<GeneratorAttribute(GetType(DefaultGeneratorDesigner))> _
<CLSCompliantAttribute(True)> _
Public MustInherit Class Generator _
    Implements IGenerator, IDisposable, IExtensionInformation, IExtension
[GeneratorAttribute(typeof(DefaultGeneratorDesigner))]
[CLSCompliantAttribute(true)]
public abstract class Generator : IGenerator, 
    IDisposable, IExtensionInformation, IExtension
[GeneratorAttribute(typeof(DefaultGeneratorDesigner))]
[CLSCompliantAttribute(true)]
public ref class Generator abstract : IGenerator, 
    IDisposable, IExtensionInformation, IExtension
[<AbstractClass>]
[<GeneratorAttribute(typeof(DefaultGeneratorDesigner))>]
[<CLSCompliantAttribute(true)>]
type Generator =  
    class
        interface IGenerator
        interface IDisposable
        interface IExtensionInformation
        interface IExtension
    end
public abstract class Generator implements IGenerator, IDisposable, IExtensionInformation, IExtension

Generator 형식에서는 다음과 같은 멤버를 노출합니다.

생성자

  이름 설명
Protected 메서드 Generator Generator 클래스를 초기화하기 위해 파생 클래스의 생성자에서 호출됩니다.

위쪽

속성

  이름 설명
Public 속성 Collation 이 열의 데이터 정렬 또는 언어적으로 적절한 정렬을 가져오거나 설정합니다.
Public 속성 Column 열을 가져오거나 설정합니다.
Public 속성 ColumnName 열 이름을 가져오거나 설정합니다.
Public 속성 Constraints 열의 CHECK 제약 조건 정보를 가져오거나 설정합니다.
Public 속성 DefaultLocaleId 로캘 ID를 가져오거나 설정합니다.
Public 속성 DefaultValue 열의 기본값을 가져오거나 설정합니다.
Public 속성 ExtensionHandle 확장 핸들을 가져옵니다.
Public 속성 MaxLength 이 열의 값에 대한 최대 길이를 가져오거나 설정합니다.
Public 속성 Nullable 이 열을 nullNull 참조(Visual Basic의 경우 Nothing)로 설정할 수 있는지 여부를 나타내는 값을 가져오거나 설정합니다.
Public 속성 OutputKey 출력 값을 검색하는 데 사용되는 키를 가져오거나 설정합니다.
Public 속성 PercentageNull 사용자가 nullNull 참조(Visual Basic의 경우 Nothing)이기를 원하는 이 열의 생성 값 비율을 가져오거나 설정합니다.비율은 0에서 100 사이의 정수로 나타냅니다.
Public 속성 Precision 데이터의 전체 자릿수를 가져오거나 설정합니다.
Public 속성 RowsToInsert 생성할 행 수를 가져오거나 설정합니다.
Public 속성 Scale 데이터의 소수 자릿수를 가져오거나 설정합니다.
Public 속성 SchemaName 열이 속하는 스키마의 이름을 가져오거나 설정합니다.
Public 속성 Seed 시드를 가져오거나 설정합니다.시드를 사용하여 명확한 난수 데이터 생성 알고리즘을 초기화할 수 있습니다.
Public 속성 TableName 열이 속하는 테이블의 이름을 가져오거나 설정합니다.
Public 속성 TargetType 열의 대상 데이터 형식을 가져오거나 설정합니다.
Public 속성 Unique 생성되는 열이 UNIQUE 제약 조건이나 PRIMARY KEY 제약 조건의 일부인지 여부를 나타내는 값을 가져오거나 설정합니다.

위쪽

메서드

  이름 설명
Public 메서드 Dispose() Generator 에서 사용하는 리소스를 모두 해제합니다.
Protected 메서드 Dispose(Boolean) Generator 에서 사용하는 관리되지 않는 리소스를 해제하고 관리되는 리소스를 선택적으로 해제합니다.
Public 메서드 Equals 지정한 Object가 현재 Object와 같은지 여부를 확인합니다. (Object에서 상속됨)
Protected 메서드 Finalize 가비지 수집에서 회수하기 전에 개체에서 리소스를 해제하고 다른 정리 작업을 수행할 수 있게 합니다. (Object에서 상속됨)
Public 메서드 GenerateNextValues 데이터 생성 알고리즘에 따라 다음 값을 생성합니다.
Public 메서드 GetHashCode 특정 형식에 대한 해시 함수 역할을 합니다. (Object에서 상속됨)
Public 메서드 GetOutputValue OutputKey 를 사용하여 출력 값을 검색합니다.
Public 메서드 GetType 현재 인스턴스의 Type을 가져옵니다. (Object에서 상속됨)
Public 메서드 Initialize 데이터 생성기를 초기화합니다.
Protected 메서드 MemberwiseClone 현재 Object의 단순 복사본을 만듭니다. (Object에서 상속됨)
Protected 메서드 OnGenerateNextValues 데이터 생성 알고리즘에 따라 다음 값을 생성합니다.
Protected 메서드 OnGetOutputValue 하나 이상의 값으로 구성된 현재 결과 집합을 검색합니다.
Protected 메서드 OnInitialize 생성기를 초기화합니다.
Protected 메서드 OnNextValues 데이터 행의 다음 값 집합을 생성합니다.
Protected 메서드 OnSetInputValues 제공된 명명된 값 목록을 사용하여 데이터 생성기의 입력 속성을 설정합니다.
Protected 메서드 OnValidateInputs 데이터 생성기에 필요한 모든 입력을 설정했는지 확인합니다.
Public 메서드 SetExtensionHandle 지정된 확장 핸들을 사용하여 확장 핸들을 설정합니다.
Public 메서드 SetInputValues 데이터 생성기의 입력 값을 설정합니다.
Public 메서드 ToString 현재 개체를 나타내는 문자열을 반환합니다. (Object에서 상속됨)
Public 메서드 ValidateInputs 데이터 생성기에 필요한 모든 입력을 설정했는지 확인합니다.

위쪽

설명

표준 데이터 생성기가 적절하지 않은 경우 사용자 지정 데이터 생성기를 만들 수 있습니다. 사용자 지정 데이터 생성기를 만들려면 IGenerator를 구현하거나 Generator를 상속하는 클래스를 만들어야 합니다. 클래스를 GeneratorAttribute로 데코레이팅하면 클래스가 데이터 생성기로 식별됩니다.

사용자 지정 데이터 생성기에 대한 사용자 지정 디자이너를 만들 수도 있고, DefaultGeneratorDesigner를 사용할 수도 있습니다.

기본 클래스를 구현하면 OutputAttribute로 표시된 공용 속성에 기초한 출력 값이 구성됩니다. 입력 값은 InputAttribute를 사용하여 설정됩니다. 특성이 표시된 속성을 사용하면 강력한 형식의 입출력 값을 간편하게 선언할 수 있습니다.

예제

표준 데이터 생성기에서는 일부 CHECK 제약 조건에 맞는 데이터를 생성할 수 없습니다. 예를 들어 특정 날짜가 서로 다른 두 범위 중 하나에 포함되어야 하는 CHECK 제약 조건의 경우 표준 DateTime 생성기를 사용할 수 없습니다. 다음 예제에서는 이러한 제약 조건을 충족할 수 있는 사용자 지정 데이터 생성기를 만듭니다. 이 생성기에서는 서로 다른 두 범위를 입력으로 받아 두 범위 중 하나에 속하는 난수 날짜를 생성합니다. 자세한 내용은 연습: CHECK 제약 조건에 맞는 사용자 지정 데이터 생성기 만들기을 참조하십시오.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TeamSystem.Data.DataGenerator;

namespace GeneratorDateRangesCS
{
    public class GeneratorDateRangesCS : Generator
    {
        DateTime mRange1Min;
        DateTime mRange1Max;

        DateTime mRange2Min;
        DateTime mRange2Max;

        [Input]
        public DateTime Range1Min
        {
            set {mRange1Min = value;}
        }

        [Input]
        public DateTime Range1Max
        {
            set {mRange1Max = value;}
        }

        [Input]
        public DateTime Range2Min
        {
            set {mRange2Min = value;}
        }

        [Input]
        public DateTime Range2Max
        {
            set {mRange2Max = value;}
        }

        DateTime mRandomDate;

        [Output]
        public DateTime RandomDate
        {
            get {return mRandomDate;}
        }

        Random mRandom;
        Random mRandomRange;

        protected override void OnInitialize(GeneratorInit initInfo)
        {
            // Deterministic
            mRandom = new Random(this.Seed);
            mRandomRange = new Random(this.Seed);  //deterministic

            // Non-deterministic
            //mRandom = new Random();
            //mRandomRange = new Random();

            base.OnInitialize(initInfo);
        }

        protected override void OnGenerateNextValues()
        {
            DateTime min;
            DateTime max;

            // Generate a random date from either range 1 or range 2.
            // Randomly select either range 1 or range 2 by randomly 
            // generating an odd or an even random number.
            if (mRandomRange.Next() % 2 == 0)  //check for odd or even
            {
                min = mRange1Min;
                max = mRange1Max;
            }
            else
            {
                min = mRange2Min;
                max = mRange2Max;
            }

            // The formula for creating a random number in a specific
            // range is: of range + (size of range * random number 
            // between 0 and 1)

            //size of range
            TimeSpan range = max - min;

            // (Size of range * random number between 0 and 1)
            TimeSpan randomNumber = new TimeSpan(
                (long)(range.Ticks * mRandom.NextDouble()));

            // Start of range + (size of range * random number 
            // between 0 and 1)
            mRandomDate = min + randomNumber;
        }
    } // End of class
}     // End of namespace
Imports Microsoft.VisualStudio.TeamSystem.Data.DataGenerator

Public Class GeneratorDateRangesVB
    Inherits Generator

    Dim mRange1Min As Date
    Dim mRange1Max As Date

    Dim mRange2Min As Date
    Dim mRange2Max As Date

    <Input()> _
    Public WriteOnly Property Range1Min() As Date
        Set(ByVal value As Date)
            mRange1Min = value
        End Set
    End Property

    <Input()> _
    Public WriteOnly Property Range1Max() As Date
        Set(ByVal value As Date)
            mRange1Max = value
        End Set
    End Property

    <Input()> _
    Public WriteOnly Property Range2Min() As Date
        Set(ByVal value As Date)
            mRange2Min = value
        End Set
    End Property

    <Input()> _
    Public WriteOnly Property Range2Max() As Date
        Set(ByVal value As Date)
            mRange2Max = value
        End Set
    End Property

    Dim mRandomDate As Date

    <Output()> _
    Public ReadOnly Property RandomDate() As Date
        Get
            Return mRandomDate
        End Get
    End Property

    Dim mRandom As Random
    Dim mRandomRange As Random

    Protected Overrides Sub OnInitialize(ByVal initInfo _
        As GeneratorInit)

        mRandom = New Random(Me.Seed)       'deterministic
        mRandomRange = New Random(Me.Seed)  'deterministic

        'mRandom = New Random()              'non-deterministic
        'mRandomRange = New Random()         'non-deterministic

        MyBase.OnInitialize(initInfo)
    End Sub

    Protected Overrides Sub OnGenerateNextValues()
        Dim min As Date
        Dim max As Date

        ' Generate a random date from either range 1 or range 2.
        ' Randomly select either range 1 or range 2 by randomly 
        ' generating an odd or an even random number.
        '------------------------------------------------------------
        If mRandomRange.Next() Mod 2 = 0 Then  'check for odd or even
            min = mRange1Min
            max = mRange1Max
        Else
            min = mRange2Min
            max = mRange2Max
        End If

        ' The formula for creating a random number in a specific 
        ' range is: of range + (size of range * random number 
        ' between 0 and 1)

        ' Size of range
        Dim range As TimeSpan = max - min

        ' (Size of range * random number between 0 and 1)
        Dim randomNumber As TimeSpan = _
            New TimeSpan(CLng(range.Ticks * mRandom.NextDouble()))

        ' Start of range + (size of range * random number 
        ' between 0 and 1)
        mRandomDate = min + randomNumber
    End Sub
End Class

스레드로부터의 안전성

이 형식의 모든 공용 static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

참고 항목

참조

Microsoft.Data.Schema.Tools.DataGenerator 네임스페이스

GeneratorAttribute

GeneratorInit

IGenerator

기타 리소스

연습: CHECK 제약 조건에 맞는 사용자 지정 데이터 생성기 만들기

Creating Custom Data Generators

데이터 생성기 확장성 개요

Specifying Details of Data Generation for a Column