C# Class DataMigration.SqlDataSource

The SqlDataSource class can use Sql data from a table or query, and present it to the system as an IParser-based data source. It could be used for getting data from SQL Server into Redis, for example. Caveats: It assumes there is an identity column on the table or at least some sort of id or other column that is monotonically increasing. It may well work with data sources where there are 'holes' in the sequence of ('ids'), but this has not been tested. Take a look at DataMigrationPlan.xml, which shows the beginnings of an example of usage for this class.
Inheritance: IParser
ファイルを表示 Open project: scoutmedia/DataMigration

Public Methods

Method Description
Dispose ( ) : void

There are no native resources held between calls by this IParser implementation, hence, Dispose() does nothing.

NextRow ( ) : IList

Returns the next row of data, and advances the CurrentRow. This implementation will just return the cached row of data, until it runs out of cached rows, then it will execute another query to get another batch of rows from Sql Server.

Open ( string filePath ) : void

Open the file the specified Path. The caller is responsible for calling Dispose once Open() has been called. This implementation will check to see that all the properties have been set in the plan so it can connect to SQL, and execute its queries. It will then get the min and max ids for the set of rows by executing the queries specified in the plan. Then it will use those values to form the main query to query for the first batch of rows.

Private Methods

Method Description
GetConnectString ( ) : void

Looks for a property in the plan, called 'connectionKey', and uses that key to find the connection string from the App.Config.

GetIntegerFromSql ( string sqlCommandText, string connectionString ) : int

A helper function that returns a scalar integer from Sql Server.

GetMinAndMaxIds ( ) : void

Uses the minIdQuery and maxIdQuery set in the Plan properties to determine the Id lower and upper bounds to be used in calculating how to query for batches of rows.

GetRequiredProperty ( string key ) : string

Helper function that looks in the properties set by the Plan for this parser. This implementation uses these properties extensively.

QueryForBatchOfRows ( ) : void

Queries for a single batch of rows. This is called whenever the consumer needs a row which hasn't been cached yet. This will clear out the cached rows, and execute the query again, using new new currentStart and currentEnd values. The effect of this method is to repopulate the batchOfRows List.

ValidateProperties ( ) : void

Gets the connection string for Sql Server access, and makes sure the query format string is available, as well as the batch size for queries.

Method Details

Dispose() public method

There are no native resources held between calls by this IParser implementation, hence, Dispose() does nothing.
public Dispose ( ) : void
return void

NextRow() public method

Returns the next row of data, and advances the CurrentRow. This implementation will just return the cached row of data, until it runs out of cached rows, then it will execute another query to get another batch of rows from Sql Server.
public NextRow ( ) : IList
return IList

Open() public method

Open the file the specified Path. The caller is responsible for calling Dispose once Open() has been called. This implementation will check to see that all the properties have been set in the plan so it can connect to SQL, and execute its queries. It will then get the min and max ids for the set of rows by executing the queries specified in the plan. Then it will use those values to form the main query to query for the first batch of rows.
public Open ( string filePath ) : void
filePath string In this implementation, the filePath argument is unused. ///
return void