Namespace actionETL.Adb
The Adb infrastructure (in actionETL.Adb and its child namespaces) is used in ETL applications for accessing databases via SQL, both on-premises, and in the cloud. This includes both relational SQL databases, NoSQL databases, and many other querying systems, accessible via dedicated providers or via the Adb ODBC Provider.
Adb consists of wrappers around the standard .NET database routines residing in System.Data and similar namespaces, adding ETL functionality such as:
- Get which database tables and columns are available
- Support for provider-specific data types, which are very useful for avoiding conversion issues
- Enhanced automated mapping between .NET CLR types and database types
- Encapsulating database connections, to support both short-term connections that are opened and closed as needed inside a worker, and connections that are kept open until explicitly closed by the library user, e.g. for using a single transaction or temporary table across multiple workers
- Execute predefined table commands, e.g. delete all rows, truncate, drop, exists
- Provide additional information about the database, which assists with writing
provider-independent code, so that a worker (such as
AdbInsertTarget) can support all Adb database providers.- Note: This aspect is mainly used when developing your own custom Adb workers
Also see SQL Database Access.
Classes
AdbColumnSchema
Information about a database column. Note that several members are optional and might not be populated for a particular database provider and connection. Created by GetTableColumnsAsync(IAdbTableIdentifier) and associated overloads.
AdbCommand
An Adb command with an SQL statement or stored procedure and parameters to execute
against a data source, similar to a DbCommand, with extra information
and functionality. It is created by the AdbCommandBuilder Create()
method or by AdbConnection CreateCommand(String) overloads.
Information about the data source and the provider can be found via the Connection property.
The command must be disposed after use. See Disposing Disposables for details.
AdbCommandBuilder
An Adb command builder for an SQL statement or stored procedure and parameters to execute against a data source, similar to a DbCommand, with extra information and functionality. It creates one AdbCommand instance, as well as AdbParameter instances via the Parameters property.
Command builder instances can be created by AdbProvider factory methods,
which will automatically generate an associated AdbConnectionBuilder instance.
Use this approach when you don't need a direct reference to the associated
AdbConnectionBuilder.
Alternatively, create an AdbConnectionBuilder (or
AdbKeepOpenConnectionBuilder) instance first, and use that to in turn create
AdbCommandBuilder instances.
Each AdbCommandBuilder instance has a database provider and connection string that
cannot be changed after the instance is created. It can in turn create a single
AdbCommand database command. Note that the AdbCommandBuilder
instance cannot be used after having created the AdbCommand.
The command builder instance members are used for configuring the command, and for finally creating an AdbCommand instance.
AdbConnection
An Adb database connection, similar to a DbConnection, including creating database commands, with extra information and functionality. It is created by an AdbConnectionBuilder instance.
This class opens and closes connections in the same way as the underlying .NET
DbConnection, and is the normal type of connection to use for database
access. AdbKeepOpenConnection is available
for the (rare) cases when a connection should stay open across multiple workers.
Note: The AdbConnection instance is not thread-safe, and must only be used
in a single place (in a single worker) at any one time.
Note: Database specific drivers, e.g. SqlClient and MySqlClient, sets properties like DatabaseName from the ConnectionString, before the connection is open, and sets them again with values from the database server after the connection is open. Universal drivers like ODBC do not set these properties from the connection string, and only sets them after the connection is open.
The connection can be opened and closed multiple times as needed, and it must
be disposed after use. Disposal should almost always be done by whoever created the
connection, typically via
DisposeOnFinished<TDisposable>(TDisposable)
or UsingActionWorker<TDisposable> if used across multiple method calls,
or by a using statement if created and disposed in a single method and thread, without
being passed to any other workers.
See Disposing Disposables for details.
AdbConnectionBuilder
An Adb connection builder that creates one AdbConnection
instance, as well as AdbCommandBuilder instances referencing the
connection builder and the AdbConnection it creates.
The Adb connection builder instance is created via factory methods on AdbProvider and AdbConnectionString.
Each connection builder instance has a database provider and connection string, which cannot be changed after it's created. It can in turn create a single AdbConnection database connection, for use with a single worker.
This class opens and closes connections in the same way as the underlying .NET DbConnection, and is
the normal type of connection to use for database access. AdbKeepOpenConnection is available
for the (rare) cases when a connection should stay open across multiple workers.
AdbConnectionBuilderBase
An Adb connection builder base class for creating one AdbConnection, as well as AdbCommandBuilder instances. Each connection builder has an Adb provider and a connection string, that cannot be changed after they are created.
A connection builder can only create a single connection. Use multiple instances, or a AdbConnectionString to handle multiple connections. See AdbConnectionBuilder and AdbKeepOpenConnectionBuilder for further details.
AdbConnectionString
A class that contains a read-only connection string plus its provider.
The AdbConnectionString instance can create AdbConnectionBuilder,
AdbKeepOpenConnectionBuilder, and AdbCommandBuilder instances.
Use an AdbConnectionString instance when you (or a worker) need to create
multiple connection and command builders, all using the same provider and connection string.
When only needing a single connection or command builder, use the factory methods on
AdbProvider instead.
AdbDataReaderSource<TOutput>
A dataflow worker which executes an SQL query on a database, and sends the result set rows to a downstream worker.
Each source column data type must either be the same as the target column data type, or be
implicitly castable
to the target column data type, or be an enum or nullable enum whose
underlying type is implicitly castable to the target column integral data type.
The latter case allows a source column enum to be stored in a target integer column.
Also see SQL Database Access.
AdbDataSourceInformation
A class that provides and helps process the information about a data source behind a connection, such as what character to use for quoting, how to specify parameter markers etc.
The information is mainly taken from the "DataSourceInformation" schema collection, and is used to write provider-independent database code. Each Adb provider supplies this information by implementing IAdbDataSourceInformationService.
Also see Information, TableInformation and AdbProvider.
AdbExecuteNonQueryTarget<TInputError>
A dataflow worker with one Input port, that uses ExecuteNonQuery()
to execute an SQL query for each incoming row.
It also has an ErrorOutput port that receives any rows that throw an exception
when creating and executing their queries.
Note: Use the factory methods in AdbExecuteNonQueryTargetFactory to create instances of this class.
It uses CreateSetParametersFromRowAction<T>(AdbParameterCollection) to set parameter values from incoming rows. The worker does not give access to the query return value or any output parameters.
Also see SQL Database Access.
Note: This worker does participate in any transaction currently active on the connection.
AdbExecuteNonQueryTargetFactory
Factory methods that create an
AdbExecuteNonQueryTarget<TInputError>
dataflow worker, which executes an SQL query for each incoming row.
It also has an ErrorOutput port that receives any rows that throw an exception
when creating and executing their queries.
The Input port is linked to (if available) the upstream
output or error output port specified by the factory.
Get the factory from Link when the upstream port is known ahead of time (which is usually the case). Otherwise get it from GetDownstreamFactory<TInput>(), and link the transform or target explicitly using LinkTo(InputPort<TOutput>) or LinkFrom(OutputPortBase<TInput>).
Also see SQL Database Access.
Note: This worker does participate in any transaction currently active on the connection.
AdbExecuteNonQueryWorker
A worker that executes a query in an SQL database without returning any result set (i.e. INSERT, UPDATE, DELETE and DML statements). The RecordsAffected property is however set when the query finishes.
Also see SQL Database Access, as well as AdbTableNonQueryWorker and AdbExecuteScalarWorker<TResult>.
Note: This worker does participate in any transaction currently active on the connection.
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.
AdbGenericDataSourceInformationService
Base class that provides information about a data source behind a connection, such as what character to use for quoting, how to specify parameter markers etc. The information is mainly taken from the "DataSourceInformation" schema collection, and is used to write provider-independent database code.
This class can be used directly (if the settings works with your data source)
when creating AdbProvider instances,
use Get() to retrieve the required delegate.
It supports positional parameters, and named parameters using @ or :.
Commonly, this class is inherited by provider-specific classes, which typically
overwrites some values.
Also see Information and AdbProvider.
This class is immutable. This avoids threading issues, since an instance is often accessed by multiple threads. Any user custom provider services should also be immutable for the same reason.
AdbGenericTableInformationService
An optional service that manipulates table identifiers and provides information about table-like objects, such as which ones exists and what their type is (table, view, etc), and which columns are present. This assists with writing provider-independent database code, and is available as TableInformation. Also see HasTableInformationService, AdbTableCommand, AdbDataSourceInformation, AdbConnection and AdbProvider.
Derive from this class (or from one of its descendant classes) to customize the information for either a new .NET provider, or to tweak an existing one.
This class is immutable. This avoids threading issues, since an instance is often accessed by multiple threads. Any user custom provider services should also be immutable for the same reason.
AdbInsertTarget<TInputError>
A dataflow worker with one Input port, that inserts all incoming rows into a SQL table or view. It also has an ErrorOutput port that receives any row batches that throw an exception when creating and executing their queries.
Note that this worker requires an AdbProvider that supports both IAdbTableInformationService and IAdbInsertStatementService, see Database Support for details. You can also use IsSupported(AdbProvider) at runtime to determine whether a given provider is supported with this worker.
Note: Use the factory methods in AdbInsertTargetFactory to create instances of this class.
Rows will be inserted in batches and transactions according to how the provider IAdbInsertStatementService has been configured. The out-of-box providers typically use multi-row batches and also wrap the batches into periodic transactions. To change the defaults, either use SetRowLimits(Int32, Int64) on this worker, or use AConfig configurations with the InsertStatementValuesPerBatch and InsertStatementValuesPerTransaction string keys, or create a new provider instance with e.g. With(String, IAdbInsertStatementService).
Using any transactions will automatically set
ErrorOutput.MaxRowsBeforeError
to 0 (i.e. fail on the first batch error).
Note however that creating transactions is automatically disabled when the ErrorOutput port has been linked to a downstream worker, since otherwise rows could end up processed several different ways (rows successfully inserted, incorrect and correct rows sent to downstream worker, and rows rolled back) which would be difficult to program against.
This worker does participate in any pre-existing transaction currently active on the connection. Using both a transaction and linking the ErrorOutput port to a downstream worker is however incompatible, and would fail the worker.
Note that with multiple rows per batch or transaction, any insert error will reject all the rows in the batch or transaction. Only the failed batch insert will be sent to ErrorOutput, even if transactions are used and some or all previous batches are rolled back.
The following exceptions can occur when the worker runs:
| ArgumentNullException | ConnectionBuilder |
| ArgumentException | CompositeTableName |
| InvalidOperationException |
- No column name matches found. - Cannot both use transactions and link the ErrorOutput port. |
AdbInsertTargetFactory
Factory methods that create an AdbInsertTarget<TInputError> dataflow worker with one Input port, that inserts all incoming rows into a SQL table or view. It also has an ErrorOutput port that receives any row batches that throw an exception when creating and executing their queries.
Note that this worker requires an AdbProvider that supports both IAdbTableInformationService and IAdbInsertStatementService, see Database Support for details. You can also use IsSupported(AdbProvider) at runtime to determine whether a given provider is supported with this worker.
Rows will be inserted in batches and transactions according to how the provider IAdbInsertStatementService has been configured. The out-of-box providers typically use multi-row batches and also wrap the batches into periodic transactions. To change the defaults, either use SetRowLimits(Int32, Int64) on this worker, or use AConfig configurations with the InsertStatementValuesPerBatch and InsertStatementValuesPerTransaction string keys, or create a new provider instance with e.g. With(String, IAdbInsertStatementService).
Using any transactions will automatically set
ErrorOutput.MaxRowsBeforeError
to 0 (i.e. fail on the first batch error).
Note however that creating transactions is automatically disabled when the ErrorOutput port has been linked to a downstream worker, since otherwise rows could end up processed several different ways (rows successfully inserted, incorrect and correct rows sent to downstream worker, and rows rolled back) which would be difficult to program against.
This worker does participate in any pre-existing transaction currently active on the connection. Using both a transaction and linking the ErrorOutput port to a downstream worker is however incompatible, and would fail the worker.
Note that with multiple rows per batch or transaction, any insert error will reject all the rows in the batch or transaction. Only the failed batch insert will be sent to ErrorOutput, even if transactions are used and some or all previous batches are rolled back.
The Input port is linked to (if available) the upstream
output or error output port specified by the factory.
Get the factory from Link when the upstream port is known ahead of time (which is usually the case). Otherwise get it from GetDownstreamFactory<TInput>(), and link the transform or target explicitly using LinkTo(InputPort<TOutput>) or LinkFrom(OutputPortBase<TInput>).
The following exceptions can occur when the worker runs:
| ArgumentNullException | ConnectionBuilder |
| ArgumentException | CompositeTableName |
| InvalidOperationException |
- No column name matches found. - Cannot both use transactions and link the ErrorOutput port. |
AdbKeepOpenConnection
An Adb "KeepOpen" database connection that allows a connection to stay open across multiple workers. It is similar to a DbConnection, including creating database commands, with extra information and functionality. It is created by an AdbKeepOpenConnectionBuilder instance.
The key feature of "KeepOpen" connections is that they keep the underlying .NET
DbConnection open even after a worker calls Close()
and Dispose(). This allows using a single transaction or specific temporary table(s)
across multiple workers, which can be very useful. When this functionality
is not needed, a standard AdbConnection should be used instead.
Note: This connection must be disposed after use. This will however not close the underlying .NET connection - that only happens when the AdbKeepOpenConnectionBuilder instance that created this connection is disposed. See Disposing Disposables for details.
Note that typically this class is not used directly, instead IAdbConnection is used, and then only when implementing Adb workers (as opposed to using pre-existing ones).
AdbKeepOpenConnectionBuilder
An Adb connection builder that creates one AdbKeepOpenConnection
instance, as well as AdbCommandBuilder instances referencing the
connection builder and the AdbKeepOpenConnection it creates.
The Adb connection builder instance is created via factory methods on AdbProvider and AdbConnectionString.
The key feature of "KeepOpen" connections is that they keep the underlying .NET
DbConnection open even after a worker calls Close()
and Dispose(). This allows using a single transaction or specific temporary table(s)
across multiple workers, which can be very useful. When this functionality
is not needed, a standard AdbConnectionBuilder should be used instead.
Note: This builder (unlike AdbConnectionBuilder) must be disposed after use - it is only then that the underlying .NET connection will be closed and disposed.
AdbParameter
A database parameter used by AdbCommand for passing values to and from a database. Used by both control flow (e.g. AdbExecuteNonQueryWorker) and dataflow (e.g. AdbInsertTarget<TInputError>) workers.
Parameters are often created with a AdbParameterCollection method, and
optionally further modified by chaining calls to methods on this AdbParameter class.
Parameters have a database type setting, which affects how values are copied or converted
between the database and .NET. It can be set to a provider-independent type such as
System.Data.DbType Int32, or a provider-specific one such as
System.Data.SqlDbType UniqueIdentifier, or if left unset,
the provider will guess the database type (Note: on a per row basis in a dataflow!)
Wherever possible, do set the database type explicitly with one of the SetType()
or SetDbValue() methods, since relying on the provider guessing the type can lead to
conversion issues, and can in some cases reduce performance.
Use one of the SetMappedType(Type) overloads if the .NET type is only known
at run time.
Note: GetValue() and SetValue() methods convert between DBNull
and .NET null values automatically, and are often the best choice. They are different
from the DbValue and ProviderValue properties, which do not
automatically convert between DBNull and .NET null values.
Also see the Stored Procedure Example, which demonstrates how to use this class.
AdbParameterCollection
Supports creating, adding and inspecting the parameters of an AdbCommand database command.
Using the Add* methods on this class is the main way to create parameters, which can
then be further modified by calling methods and modifying properties on the returned
AdbParameter instance.
In particular, do set the parameter database type explicitly wherever possible, since relying on the provider to guess the database type can lead to conversion issues, and can in some cases reduce performance. See AdbParameter for details.
Note: parameter names in the collection must at a minimum be (case sensitive) unique. Some providers have additional requirements, e.g. case insensitive unique.
Also see the Stored Procedure Example, which demonstrates how to use this class.
AdbProvider
An immutable class that wraps an ADO.NET database provider and assists with writing provider independent code, mapping between .NET CLR types and database types, and creating AdbConnectionString, AdbConnectionBuilder, AdbKeepOpenConnectionBuilder, and AdbCommandBuilder instances.
The user normally uses one of the out of box providers, e.g. AdbSqlClientProvider or AdbOdbcProvider, see SQL Database Access.
Note that it is best practice to select which provider to use in only one place in the application, to make it easy to switch to a different provider instance, especially since settings such as how to quote identifiers is specified by creating the appropriate provider instance.
Each AdbProvider instance contains a set of services that implements the provider
functionality. You can create a new modified provider instance from an existing one by using
its With*() methods to replace one of its services.
Custom services can be derived from existing ones, or created from scratch.
Alternatively, create a custom provider by using the AdbProvider
constructor, specifying all the services.
Also note that IAdbInsertStatementService, IAdbTableCommandService and IAdbTableInformationService services are optional, and any workers that rely on a service that a particular provider does not supply are unsupported. See the documentation for the individual services for details.
This class is immutable, which avoids threading issues, since the provider instance is often accessed by multiple threads. Individual services are either immutable (IAdbInsertStatementService, IAdbTypeMapper and IAdbTypeService), or are created on a per connection basis (IAdbDataSourceInformationService, IAdbTableCommandService and IAdbTableInformationService). Any user custom provider services must follow the same approach.
AdbSchemaInformation
An immutable class that describes the meta-data schema collection of a .NET database provider. It is used when retrieving a schema collection with GetSchema(String) or its overloads.
See Retrieving Database Schema Information for further details.
AdbSql92InsertStatementService
An optional immutable provider service for creating a database insert statement using SQL-92 syntax, and a matching delegate for populating its database parameters from a dataflow row. It supports both single row per statement for per row error feedback, and multiple rows per batch (or statement) for improved performance. The latter uses the following syntax, with named or positional parameters:
INSERT INTO TableName (column-a, [column-b, ...])
VALUES (@r0_c0, [@r0_c1, ...]),
(@r1_c0, [@r1_c1, ...]);
The implemented interface is used by AdbInsertTarget<TInputError>. Of the four ways to set the batch and transaction sizes, linking ErrorOutput to a downstream worker automatically disables creating transaction and has the highest precedence, then SetRowLimits(Int32, Int64), then AConfig configurations with the InsertStatementValuesPerBatch and InsertStatementValuesPerTransaction string keys, and finally the values in instances of this insert service has the lowest precedence.
You can create a modified service by inheriting from this class with a custom constructor or overriding Create<TRow>(ALog, AdbCommand, String, IList<AdbColumnSchema>, FromTypeColumnMappings, Int32).
As an alternative to using this service, note that some providers also support Bulk Insert.
AdbSqlClientInsertStatementService
An immutable provider service for creating a database insert statement for SqlClient SQL Server, and a matching delegate for populating its database parameters from a dataflow row. It supports both single row per statement for per row error feedback, and multiple rows per batch (or statement) for improved performance. The latter uses the following syntax, with named or positional parameters:
INSERT INTO TableName (column-a, [column-b, ...])
VALUES (@r0_c0, [@r0_c1, ...]),
(@r1_c0, [@r1_c1, ...]);
This service optimizes inserts by enabling SqlCommand.EnableOptimizedParameterBinding.
The implemented interface is used by AdbInsertTarget<TInputError>. Of the four ways to set the batch and transaction sizes, linking ErrorOutput to a downstream worker automatically disables creating transaction and has the highest precedence, then SetRowLimits(Int32, Int64), then AConfig configurations with the InsertStatementValuesPerBatch and InsertStatementValuesPerTransaction string keys, and finally the values in instances of this insert service has the lowest precedence.
Note that MaxRowsPerBatch will be equal to
1000.
You can create a modified service by inheriting from this class with a custom constructor or overriding Create<TRow>(ALog, AdbCommand, String, IList<AdbColumnSchema>, FromTypeColumnMappings, Int32).
As an alternative to using this service, note that some providers also support Bulk Insert.
AdbTableCommand
An optional service that executes predefined commands (table truncate, drop, delete rows, exists) on table-like objects. This simplifies executing these commands and assists with writing provider-independent database code, and is available as TableCommand. Also see HasTableCommandService, AdbTableInformation, AdbDataSourceInformation and AdbConnection.
AdbTableCommandServiceBase
A base class with default implementations for some of the methods in IAdbTableCommandService, an optional service which executes predefined table commands (truncate, drop, delete all rows). This class is normally not used directly by the user, but instead via TableCommand. You can however derive from this class to customize the information for either the same .NET provider, or for a different but similar .NET provider, if some of these default implementations work correctly on your database. Otherwise create a new implementation from scratch.
Also see HasTableCommandService, AdbTableInformation, AdbDataSourceInformation, AdbConnection and AdbProvider.
AdbTableIdentifier
An immutable class that identifies a table-like database object by naming some
or all of its identifier parts, e.g. catalog or database name, schema or owner name, and table name.
Depending on the provider, this can include both system and user regular tables,
temporary tables, views, table-valued functions, etc.
It provides the identifier parts in three different forms: Original with whatever quoting the caller provided, Quoted with each part fully quoted, and Unquoted without any quoting. Use what's appropriate for the task, e.g. Quoted when adding and combining identifier parts into a new identifier.
It is created by CreateTableIdentifier(String), and is e.g. passed to workers to specify which database table to act on, or created by workers that need access to the individual parts of the table composite name.
Note that some providers do not support all identifier parts;
unsupported parts will be set to null, but unused parts will be set to
an empty string. While the SqlClient provider puts the database and schema in the
CatalogName and SchemaName properties respectively,
the MySqlClient provider puts the database in the SchemaName property.
Furthermore, all possible identifier parts might not have been supplied when creating
the identifier. In both cases, these will be set to null.
AdbTableInformation
An optional service that manipulates table identifiers and provides information about table-like objects, such as which ones exists and what their type is (table, view, etc), and which columns are present. This assists with writing provider-independent database code, and is available as TableInformation, if the provider supports it. Also see HasTableInformationService, AdbTableCommand, AdbDataSourceInformation and AdbConnection.
AdbTableNonQueryWorker
A worker that executes a query on a table-like object (e.g. table, view, or table-valued function) in an SQL database, e.g. truncate, drop, check if exists, delete all rows, etc.
Requires the Adb provider to support IAdbTableCommandService when performing a DeleteRows, DropTable, DropView, IfExistsDropTable, IfExistsDropView, or TruncateTable command.
Requires the Adb provider to support IAdbTableInformationService when performing an IfExistsError or IfNotExistsError command.
Note that universal (e.g. ODBC) providers generally don't support at least IAdbTableCommandService out of box, see SQL Database Access for details, as well as HasTableCommandService and HasTableInformationService.
Also see AdbExecuteNonQueryWorker and AdbExecuteScalarWorker<TResult>.
Note: For DeleteRows this worker does participate in any transaction currently active on the connection.
AdbTransaction
An Adb local database transaction, which works in the same way as the underlying .NET DbTransaction, with extra information and functionality. It is created by calling one of the BeginTransaction() overloads.
Note: The AdbTransaction instance is not thread-safe, and must only be used
in a single place (in a single worker) at any one time.
The instance must be disposed after use.
Disposal should almost always be done by whoever created the
connection, typically via
DisposeOnFinished<TDisposable>(TDisposable)
or UsingActionWorker<TDisposable> if used across multiple method calls,
or by a using statement if created and disposed in a single method and thread, without
being passed to any other workers.
See Disposing Disposables for details.
AdbTransaction with full error handling is somewhat involved.
Please use AdbTransactionActionWorker where possible, which is simpler
since it comes pre-configured to run database commands and any child workers within an
AdbTransaction.
AdbTransactionActionWorker
A worker which creates and opens an AdbKeepOpenConnection and a single local AdbTransaction, runs a user supplied delegate that performs database commands inside the transaction, commits or rolls back the transaction on success or failure, and finally disposes the transaction and connection. The delegate typically creates Adb child database workers that automatically participates in the transaction, which will be rolled back if any of these child workers (or the callback) fails.
This construct is very useful for running multiple database commands and database workers inside a single transaction, and have them collectively either committed or rolled back, while correctly handling any exceptions that might occur.
As with any transaction, keep the duration of the work short, where possible moving work outside the transaction (i.e. outside this worker), and avoiding delays inside it. Furthermore, do ensure that the volume of modified data does not exceed the database server's capacity to handle it, as it will accumulate until the final commit or roll-back.
AddStartingCallback(Func<WorkerBase, Task<ProgressStatus>>) can be used. Note however, that the connection and transaction are only created and opened if and when the worker is run.
See AdbTransactionActionWorker Example for how to use this worker.
AdbTypeMapper
Stores mappings between .NET types and database types, and allows setting the database
type of database parameters from these mappings. Many mappings to provider-independent
DbType database types are common across database providers, while other mappings
are specific to each provider.
To create a new type mapper, inherit from this class and set mappings in the constructor.
When the database type is known at compile time, the user or worker should set it explicitly. The mappings are instead used when the database type is only known at runtime, by automatically setting it with SetMappedType(AdbParameter, Type, AdbColumnSchema, ParameterDirection).
Note that the .NET type name is specified as the compact display name returned by DisplayName(Type).
Also see predefined type mappings.
This class is immutable. This avoids threading issues, since an instance is often accessed by multiple threads. Any user custom provider services should also be immutable for the same reason.
ConnectionStringSettingsCollectionExtensions
Note: .NET Framework only.
Utility extension methods for getting database provider details from a ConnectionStringSettingsCollection instance, typically loaded from an "app.config" or "web.config" file. Also see ConfigurationManager.
Interfaces
IAdbConnection
An Adb database connection, similar to a IDbConnection, including creating database commands, with extra information and functionality.
Note: The AdbConnection instance is not thread-safe, and must only be used
in a single place (in a single worker) at any one time.
Note: Database specific drivers, e.g. SqlClient and MySqlClient, sets properties like DatabaseName from the ConnectionString, before the connection is open, and sets them again with values from the database server after the connection is open. Generic drivers like ODBC do not set these properties from the connection string, and only sets them after the connection is open.
The connection can be opened and closed multiple times as needed, and it must
be disposed after use. Disposal should almost always be done by whoever created the
connection, typically via
DisposeOnFinished<TDisposable>(TDisposable)
or UsingActionWorker<TDisposable> if used across multiple method calls,
or by a using statement if created and disposed in a single method and thread, without
being passed to any other workers.
See Disposing Disposables for details.
IAdbConnectionBuilder
An Adb connection builder interface that creates one AdbConnection (or its derived class AdbKeepOpenConnection) instance, as well as AdbCommandBuilder instances referencing the connection builder and the Adb connection it creates.
The Adb connection builder instance is created via factory methods on AdbProvider and AdbConnectionString.
Do design database workers to take AdbConnectionString,
IAdbConnectionBuilder, and AdbCommandBuilder instances as parameters, which allows
them to support connections with different AdbConnectionMode. Conversely,
avoid passing AdbConnection, AdbKeepOpenConnection, AdbCommand,
or connection (text) strings to workers.
IAdbDataSourceInformationService
Provides information about a data source behind a connection, such as what character to use for quoting, how to specify parameter markers etc. The information is mainly taken from the "DataSourceInformation" schema collection, and is used to write provider-independent database code.
Implementations of this interface must be immutable. This avoids threading issues, since an instance is often accessed by multiple threads. Any user custom provider services should also be immutable for the same reason.
IAdbInsertStatementService
An optional immutable provider service for creating a database insert statement using SQL-92 syntax, and a matching delegate for populating its database parameters from a dataflow row. It supports both single row per statement for per row error feedback, and multiple rows per batch (or statement) for improved performance. The latter uses the following syntax, with named or positional parameters:
INSERT INTO TableName (column-a, [column-b, ...])
VALUES (@r0_c0, [@r0_c1, ...]),
(@r1_c0, [@r1_c1, ...]);
The implemented interface is used by AdbInsertTarget<TInputError>. Of the four ways to set the batch and transaction sizes, linking ErrorOutput to a downstream worker automatically disables creating transaction and has the highest precedence, then SetRowLimits(Int32, Int64), then AConfig configurations with the InsertStatementValuesPerBatch and InsertStatementValuesPerTransaction string keys, and finally the values in instances of this insert service has the lowest precedence.
You can create a modified service by inheriting from this class with a custom constructor or overriding Create<TRow>(ALog, AdbCommand, String, IList<AdbColumnSchema>, FromTypeColumnMappings, Int32).
As an alternative to using this service, note that some providers also support Bulk Insert.
IAdbTableCommandService
An optional service that executes predefined commands (table truncate, drop, delete rows, exists) on table-like objects. This simplifies executing these commands and assists with writing provider-independent database code, and is available as TableCommand. Also see HasTableCommandService, AdbTableInformation, AdbDataSourceInformation, AdbConnection and AdbProvider.
Implement this interface to customize the information for either a new .NET provider, or to tweak an existing one.
IAdbTableIdentifier
An identifier for a table-like database object by naming some or all of its identifier parts, e.g. catalog or database name, schema or owner name, and table name. Depending on the provider, this can include both system and user regular tables, temporary tables, views, table-valued functions, etc.
It provides the identifier parts in three different forms: Original with whatever quoting the caller provided, Quoted with each part fully quoted, and Unquoted without any quoting. Use what's appropriate for the task, e.g. Quoted when adding and combining identifier parts into a new identifier.
It is created by CreateTableIdentifier(String), and is e.g. passed to workers to specify which database table to act on, or created by workers that need access to the individual parts of the table composite name.
Note that some providers do not support all identifier parts;
unsupported parts will be set to null, but unused parts will be set to
an empty string. While the SqlClient provider puts the database and schema in the
CatalogName and SchemaName properties respectively,
the MySqlClient provider puts the database in the SchemaName property.
Furthermore, all possible identifier parts might not have been supplied when creating
the identifier. In both cases, these will be set to null.
IAdbTableInformationService
An optional service that manipulates table identifiers and provides information about table-like objects, such as which ones exists and what their type is (table, view, etc), and which columns are present. This assists with writing provider-independent database code, and is available as TableInformation. Also see HasTableInformationService, AdbTableCommand, AdbDataSourceInformation, AdbConnection and AdbProvider.
Implement this interface to customize the information for either a new .NET provider, or to tweak an existing one.
IAdbTransaction
An Adb database transaction, which works in the same way as the underlying .NET DbTransaction,
with extra information and functionality. It is created by calling one of the
BeginTransaction() overloads.
Note that the AdbTransaction instance is not thread-safe, and must only be used
in a single place (in a single worker) at any one time. It must be disposed after use.
Disposal should almost always be done by whoever created the
connection, typically via
DisposeOnFinished<TDisposable>(TDisposable)
or UsingActionWorker<TDisposable> if used across multiple method calls,
or by a using statement if created and disposed in a single method and thread, without
being passed to any other workers.
See Disposing Disposables for details.
AdbTransaction with full error handling is somewhat involved.
Please use AdbTransactionActionWorker where possible, which is simpler
since it comes pre-configured to run database commands and child workers within a transaction.
IAdbTypeMapper
Stores mappings between .NET types and database types, and allows setting the database
type of database parameters from these mappings. Many mappings to provider-independent
DbType database types are common across database providers, while other mappings
are specific to each provider.
When the database type is known at compile time, the user or worker should set it explicitly. The mappings are instead used when the database type is only known at runtime, by automatically setting it with SetMappedType(AdbParameter, Type, AdbColumnSchema, ParameterDirection).
Note that the .NET type name is specified as the compact display name returned by DisplayName(Type).
Also see predefined type mappings.
IAdbTypeService
Gets and sets types and values on database parameters for an AdbProvider.
Enums
AdbConnectionMode
Specifies how an AdbConnectionBuilderBase instance creates, opens, and closes connections.
AdbTableNonQueryOperation
Specifies which (provider-specific) command to create and execute on a table-like object, e.g. a table, view, or table-valued function. Commands are truncate, drop, check if exists, delete rows, etc. Used by AdbTableNonQueryWorker.
AdbTableType
The type of a table-like database object, and whether it exists. Returned by GetTableTypeAsync(String), which can be accessed via TableInformation.