Search Results for

    Show / Hide Table of Contents

    Class AdbExecuteScalarWorker<TResult>

    A worker that executes a query on an SQL database and returns a single result value in the ScalarResult property.

    The query result (which for value types is boxed in an object) is cast to the TResult type, and if that fails it is first converted (with ChangeType(Object, Type)) and then cast. This handles e.g. the query returning a long but the worker expecting an int.

    Also see SQL Database Access.

    Inheritance
    Object
    WorkerParent
    WorkerBase
    WorkerBase<AdbExecuteScalarWorker<TResult>>
    AdbExecuteScalarWorker<TResult>
    Implements
    IDisposeOnFinished
    Inherited Members
    WorkerBase<AdbExecuteScalarWorker<TResult>>.AddCompletedCallback(Func<AdbExecuteScalarWorker<TResult>, OutcomeStatus, Task<OutcomeStatus>>)
    WorkerBase<AdbExecuteScalarWorker<TResult>>.AddRanCallback(Func<AdbExecuteScalarWorker<TResult>, OutcomeStatus, WorkerParentChildrenState, Task<OutcomeStatus>>)
    WorkerBase<AdbExecuteScalarWorker<TResult>>.AddStartingCallback(Func<AdbExecuteScalarWorker<TResult>, Task<ProgressStatus>>)
    WorkerBase.AddCompletedCallback(Func<WorkerBase, OutcomeStatus, Task<OutcomeStatus>>)
    WorkerBase.AddRanCallback(Func<WorkerBase, OutcomeStatus, WorkerParentChildrenState, Task<OutcomeStatus>>)
    WorkerBase.AddStartingCallback(Func<WorkerBase, Task<ProgressStatus>>)
    WorkerBase.DefaultIsStartable()
    WorkerBase.ErroredPortErrorsWorkerProtected
    WorkerBase.ErrorOutputs
    WorkerBase.EscalateError
    WorkerBase.Inputs
    WorkerBase.IsStartable
    WorkerBase.Outputs
    WorkerBase.Parent
    WorkerBase.SucceededSequence<TLastWorker>(WorkerBase, WorkerBase, WorkerBase, WorkerBase, WorkerBase, TLastWorker)
    WorkerBase.SucceededSequence<TLastWorker>(WorkerBase, WorkerBase, WorkerBase, WorkerBase, TLastWorker)
    WorkerBase.SucceededSequence<TLastWorker>(WorkerBase, WorkerBase, WorkerBase, TLastWorker)
    WorkerBase.SucceededSequence<TLastWorker>(WorkerBase, WorkerBase, TLastWorker)
    WorkerBase.SucceededSequence<TLastWorker>(WorkerBase, TLastWorker)
    WorkerBase.SucceededSequence<TLastWorker>(TLastWorker)
    WorkerParent.AddChildCompletedCallback(Action<WorkerBase>)
    WorkerParent.AddStartingChildrenCallback(Func<WorkerParent, Task<ProgressStatus>>)
    WorkerParent.Children
    WorkerParent.DisposeOnFinished<TDisposable>(TDisposable)
    WorkerParent.GetDownstreamFactory<TInput>()
    WorkerParent.HasChildren
    WorkerParent.IsCanceled
    WorkerParent.IsCompleted
    WorkerParent.IsCreated
    WorkerParent.IsError
    WorkerParent.IsFailed
    WorkerParent.IsFatal
    WorkerParent.IsRunning
    WorkerParent.IsSucceeded
    WorkerParent.KeepChildrenLevels
    WorkerParent.Locator
    WorkerParent.LogFactory
    WorkerParent.Logger
    WorkerParent.MaxRunningChildren
    WorkerParent.Name
    WorkerParent.RemoveChildren()
    WorkerParent.RescheduleChildren()
    WorkerParent.RunChildrenAsync(Boolean)
    WorkerParent.RunChildrenAsync()
    WorkerParent.Status
    WorkerParent.Item[String]
    WorkerParent.ToString()
    WorkerParent.WorkerSystem
    WorkerParent.DebugCommands
    WorkerParent.AggregateErrorOutputRows
    WorkerParent.AggregateOutputRows
    WorkerParent.AggregateWorkersCompleted
    WorkerParent.InstantCompleted
    WorkerParent.InstantCreated
    WorkerParent.InstantStarted
    WorkerParent.RunningDuration
    Namespace: actionETL.Adb
    Assembly: actionETL.dll
    Syntax
    public class AdbExecuteScalarWorker<TResult> : WorkerBase<AdbExecuteScalarWorker<TResult>>, IDisposeOnFinished
    Type Parameters
    Name Description
    TResult

    The type of the result value.

    Constructors

    AdbExecuteScalarWorker(WorkerParent, String, AdbCommandBuilder)

    Initializes a new instance of the AdbExecuteScalarWorker<TResult> worker. It executes a query on an SQL database and returns a single result value in the ScalarResult property.

    Declaration
    public AdbExecuteScalarWorker(WorkerParent workerParent, string workerName, AdbCommandBuilder commandBuilder)
    Parameters
    Type Name Description
    WorkerParent workerParent

    The parent worker or worker system that the new child worker will be added to. Cannot be null.

    String workerName

    Name of the worker.

    Set to a prefix plus a trailing "/" (e.g. "MyPrefix-/") to generate a unique name from the prefix plus an increasing number starting at 1.

    While less useful, set to null, whitespace or "/" to generate a unique name from the worker type plus an increasing number starting at 1.

    The name cannot otherwise contain "/", and cannot start with double underscore "__".

    AdbCommandBuilder commandBuilder

    A builder for the database command. Can be null, in which case CommandBuilder must be set before the worker starts running.

    Exceptions
    Type Condition
    ArgumentException

    workerName:

    • Workers with the same parent must have unique names.
    • Worker and worker system names cannot contain '/' or start with double underscore '__'.
    ArgumentNullException

    workerParent - All workers must have a parent. The top level workers have the worker system as parent.

    InvalidOperationException
    • Cannot add child worker to parent which has completed. Are you adding it to the correct parent?
    • Cannot add worker to parent, since its children have been started. Are you adding it to the correct parent?

    AdbExecuteScalarWorker(WorkerParent, String, IAdbConnectionBuilder, String)

    Initializes a new instance of the AdbExecuteScalarWorker<TResult> worker, with CommandType set to Text. It executes a query on an SQL database and returns a single result value in the ScalarResult property.

    Declaration
    public AdbExecuteScalarWorker(WorkerParent workerParent, string workerName, IAdbConnectionBuilder connectionBuilder, string queryText)
    Parameters
    Type Name Description
    WorkerParent workerParent

    The parent worker or worker system that the new child worker will be added to. Cannot be null.

    String workerName

    Name of the worker.

    Set to a prefix plus a trailing "/" (e.g. "MyPrefix-/") to generate a unique name from the prefix plus an increasing number starting at 1.

    While less useful, set to null, whitespace or "/" to generate a unique name from the worker type plus an increasing number starting at 1.

    The name cannot otherwise contain "/", and cannot start with double underscore "__".

    IAdbConnectionBuilder connectionBuilder

    The connection builder, must not be null.

    String queryText

    The query text, must not be null.

    Exceptions
    Type Condition
    ArgumentNullException

    connectionBuilder or queryText must not be null.

    ArgumentException

    workerName:

    • Workers with the same parent must have unique names.
    • Worker and worker system names cannot contain '/' or start with double underscore '__'.
    ArgumentNullException

    workerParent - All workers must have a parent. The top level workers have the worker system as parent.

    InvalidOperationException
    • Cannot add child worker to parent which has completed. Are you adding it to the correct parent?
    • Cannot add worker to parent, since its children have been started. Are you adding it to the correct parent?

    AdbExecuteScalarWorker(WorkerParent, String, IAdbConnectionBuilder, String, CommandType)

    Initializes a new instance of the AdbExecuteScalarWorker<TResult> worker. It executes a query on an SQL database and returns a single result value in the ScalarResult property.

    Declaration
    public AdbExecuteScalarWorker(WorkerParent workerParent, string workerName, IAdbConnectionBuilder connectionBuilder, string queryText, CommandType commandType)
    Parameters
    Type Name Description
    WorkerParent workerParent

    The parent worker or worker system that the new child worker will be added to. Cannot be null.

    String workerName

    Name of the worker.

    Set to a prefix plus a trailing "/" (e.g. "MyPrefix-/") to generate a unique name from the prefix plus an increasing number starting at 1.

    While less useful, set to null, whitespace or "/" to generate a unique name from the worker type plus an increasing number starting at 1.

    The name cannot otherwise contain "/", and cannot start with double underscore "__".

    IAdbConnectionBuilder connectionBuilder

    The connection builder, must not be null.

    String queryText

    The query text, must not be null.

    CommandType commandType
    Exceptions
    Type Condition
    ArgumentNullException

    connectionBuilder or queryText must not be null. Type of the command.

    ArgumentException

    workerName:

    • Workers with the same parent must have unique names.
    • Worker and worker system names cannot contain '/' or start with double underscore '__'.
    ArgumentNullException

    workerParent - All workers must have a parent. The top level workers have the worker system as parent.

    InvalidOperationException
    • Cannot add child worker to parent which has completed. Are you adding it to the correct parent?
    • Cannot add worker to parent, since its children have been started. Are you adding it to the correct parent?

    AdbExecuteScalarWorker(WorkerParent, String, Func<Boolean>, AdbCommandBuilder)

    Initializes a new instance of the AdbExecuteScalarWorker<TResult> worker. It executes a query on an SQL database and returns a single result value in the ScalarResult property.

    Declaration
    public AdbExecuteScalarWorker(WorkerParent workerParent, string workerName, Func<bool> isStartableFunc, AdbCommandBuilder commandBuilder)
    Parameters
    Type Name Description
    WorkerParent workerParent

    The parent worker or worker system that the new child worker will be added to. Cannot be null.

    String workerName

    Name of the worker.

    Set to a prefix plus a trailing "/" (e.g. "MyPrefix-/") to generate a unique name from the prefix plus an increasing number starting at 1.

    While less useful, set to null, whitespace or "/" to generate a unique name from the worker type plus an increasing number starting at 1.

    The name cannot otherwise contain "/", and cannot start with double underscore "__".

    Func<Boolean> isStartableFunc

    Function to calculate the worker start constraint; it should return true for startable and false for not startable. Defaults to startable if null.

    AdbCommandBuilder commandBuilder

    A builder for the database command. Can be null, in which case CommandBuilder must be set before the worker starts running.

    Exceptions
    Type Condition
    ArgumentException

    workerName:

    • Workers with the same parent must have unique names.
    • Worker and worker system names cannot contain '/' or start with double underscore '__'.
    ArgumentNullException

    workerParent - All workers must have a parent. The top level workers have the worker system as parent.

    InvalidOperationException
    • Cannot add child worker to parent which has completed. Are you adding it to the correct parent?
    • Cannot add worker to parent, since its children have been started. Are you adding it to the correct parent?

    AdbExecuteScalarWorker(WorkerParent, String, Func<Boolean>, IAdbConnectionBuilder, String)

    Initializes a new instance of the AdbExecuteScalarWorker<TResult> worker, with CommandType set to Text. It executes a query on an SQL database and returns a single result value in the ScalarResult property.

    Declaration
    public AdbExecuteScalarWorker(WorkerParent workerParent, string workerName, Func<bool> isStartableFunc, IAdbConnectionBuilder connectionBuilder, string queryText)
    Parameters
    Type Name Description
    WorkerParent workerParent

    The parent worker or worker system that the new child worker will be added to. Cannot be null.

    String workerName

    Name of the worker.

    Set to a prefix plus a trailing "/" (e.g. "MyPrefix-/") to generate a unique name from the prefix plus an increasing number starting at 1.

    While less useful, set to null, whitespace or "/" to generate a unique name from the worker type plus an increasing number starting at 1.

    The name cannot otherwise contain "/", and cannot start with double underscore "__".

    Func<Boolean> isStartableFunc

    Function to calculate the worker start constraint; it should return true for startable and false for not startable. Defaults to startable if null.

    IAdbConnectionBuilder connectionBuilder

    The connection builder, must not be null.

    String queryText

    The query text, must not be null.

    Exceptions
    Type Condition
    ArgumentNullException

    connectionBuilder or queryText must not be null.

    ArgumentException

    workerName:

    • Workers with the same parent must have unique names.
    • Worker and worker system names cannot contain '/' or start with double underscore '__'.
    ArgumentNullException

    workerParent - All workers must have a parent. The top level workers have the worker system as parent.

    InvalidOperationException
    • Cannot add child worker to parent which has completed. Are you adding it to the correct parent?
    • Cannot add worker to parent, since its children have been started. Are you adding it to the correct parent?

    AdbExecuteScalarWorker(WorkerParent, String, Func<Boolean>, IAdbConnectionBuilder, String, CommandType)

    Initializes a new instance of the AdbExecuteScalarWorker<TResult> worker. It executes a query on an SQL database and returns a single result value in the ScalarResult property.

    Declaration
    public AdbExecuteScalarWorker(WorkerParent workerParent, string workerName, Func<bool> isStartableFunc, IAdbConnectionBuilder connectionBuilder, string queryText, CommandType commandType)
    Parameters
    Type Name Description
    WorkerParent workerParent

    The parent worker or worker system that the new child worker will be added to. Cannot be null.

    String workerName

    Name of the worker.

    Set to a prefix plus a trailing "/" (e.g. "MyPrefix-/") to generate a unique name from the prefix plus an increasing number starting at 1.

    While less useful, set to null, whitespace or "/" to generate a unique name from the worker type plus an increasing number starting at 1.

    The name cannot otherwise contain "/", and cannot start with double underscore "__".

    Func<Boolean> isStartableFunc

    Function to calculate the worker start constraint; it should return true for startable and false for not startable. Defaults to startable if null.

    IAdbConnectionBuilder connectionBuilder

    The connection builder, must not be null.

    String queryText

    The query text, must not be null.

    CommandType commandType

    Type of the command.

    Exceptions
    Type Condition
    ArgumentNullException

    connectionBuilder or queryText must not be null.

    ArgumentException

    workerName:

    • Workers with the same parent must have unique names.
    • Worker and worker system names cannot contain '/' or start with double underscore '__'.
    ArgumentNullException

    workerParent - All workers must have a parent. The top level workers have the worker system as parent.

    InvalidOperationException
    • Cannot add child worker to parent which has completed. Are you adding it to the correct parent?
    • Cannot add worker to parent, since its children have been started. Are you adding it to the correct parent?

    Properties

    CommandBuilder

    Gets or sets the builder for the database command. Can only be set before the worker starts running.

    Note: This property is thread-safe.

    Declaration
    public AdbCommandBuilder CommandBuilder { get; set; }
    Property Value
    Type Description
    AdbCommandBuilder
    Exceptions
    Type Condition
    InvalidOperationException

    Cannot set the value after the worker has started running.

    ScalarResult

    Gets the result value of the query, taken from the first column of the first row of the result set. It is only available after the worker has completed successfully.

    The query result (which for value types is boxed in an object) is cast to the TResult type, and if that fails it is first converted (with ChangeType(Object, Type)) and then cast. This handles e.g. the query returning a long but the worker expecting an int.

    Note that some providers put a size limit on the result value, e.g. for the Microsoft.Data.SqlClient provider the limit is 2033 characters.

    Note: This property is thread-safe.

    Declaration
    public TResult ScalarResult { get; }
    Property Value
    Type Description
    TResult
    Exceptions
    Type Condition
    InvalidOperationException
    • Value only available after the worker has completed successfully.
    • Value not set.

    Methods

    RunAsync()

    This method can be overridden to add custom functionality to the derived worker that runs before and after the row processing. In this case, the base class base.RunAsync() must be called for the worker to function correctly.

    Typically, this worker is used without overriding this method.

    Declaration
    protected override Task<OutcomeStatus> RunAsync()
    Returns
    Type Description
    Task<OutcomeStatus>

    A Task describing the success or failure of the worker. An asynchronous async implementation would e.g. return OutcomeStatus.Succeeded on success, while a synchronous implementation would return OutcomeStatus.SucceededTask.

    Overrides
    WorkerParent.RunAsync()

    Implements

    IDisposeOnFinished
    In This Article
    Back to top Copyright © 2020 Envobi Ltd