using System.Data;
using JdeScoping.DataSync.Etl.Contracts;
namespace JdeScoping.DataSync.Etl.Transformers;
///
/// Base class for data transformers that modify data during the ETL process.
/// Derived classes can override specific methods to customize transformation behavior.
///
public abstract class DataTransformerBase : IDataTransformer
{
///
public abstract string TransformerName { get; }
///
public IDataReader Transform(IDataReader source)
{
ArgumentNullException.ThrowIfNull(source);
OnInitialize(source);
return new TransformingDataReader(source, this);
}
///
/// Called when the transformer is initialized with a source reader.
/// Override to perform initialization logic.
///
/// The source data reader.
protected virtual void OnInitialize(IDataReader source) { }
///
/// Gets the field count from the source reader.
/// Override to add or remove fields.
///
public virtual int GetFieldCount(IDataReader source) => source.FieldCount;
///
/// Gets the name of a field at the specified ordinal.
/// Override to rename fields.
///
public virtual string GetName(int ordinal, IDataReader source) => source.GetName(ordinal);
///
/// Gets the type of a field at the specified ordinal.
/// Override to change field types.
///
public virtual Type GetFieldType(int ordinal, IDataReader source) => source.GetFieldType(ordinal);
///
/// Gets the value of a field at the specified ordinal.
/// Override to transform values.
///
public virtual object GetValue(int ordinal, IDataReader source) => source.GetValue(ordinal);
///
/// Gets the ordinal of a field by name.
/// Override to support renamed fields.
///
public virtual int GetOrdinal(string name, IDataReader source) => source.GetOrdinal(name);
///
/// Checks if a field value is DBNull.
/// Override to handle null transformations.
///
public virtual bool IsDBNull(int ordinal, IDataReader source) => source.IsDBNull(ordinal);
///
/// Maps a transformed ordinal to the source ordinal.
/// Override to support column reordering or computed columns.
///
/// The ordinal in the transformed output.
/// The source data reader.
/// The corresponding source ordinal, or -1 for computed columns.
public virtual int MapOrdinal(int transformedOrdinal, IDataReader source) => transformedOrdinal;
}