Skip to content

Commit

Permalink
removed IDataContract Interface dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
RohitM-IN committed Feb 3, 2024
1 parent 78c2425 commit 7e65118
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/DatabaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public DatabaseManager(T databaseProvider)
/// <param name="query">The SQL query to execute.</param>
/// <param name="tableName">The name of the table associated with the query.</param>
/// <returns>A list of results of type <typeparamref name="TItem"/>.</returns>
public List<TItem> ExecuteQuery<TItem>(string query, string tableName) where TItem : IDataContract
public List<TItem> ExecuteQuery<TItem>(string query, string tableName)
{
List<TItem> result = new List<TItem>();

Expand Down
3 changes: 0 additions & 3 deletions src/Extensions/DataRowExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ public static class DataRowExtensions
/// <param name="row">The DataRow from which to retrieve the value.</param>
/// <param name="columnName">The name of the column.</param>
/// <returns>The value of the specified column, converted to the specified type.</returns>
/// <remarks>
/// This extension method is intended for use with classes that inherit from <see cref="IDataContract"/>.
/// </remarks>
public static T GetValue<T>(this DataRow row, string columnName)
{
// Check if the DataRow is null
Expand Down
45 changes: 19 additions & 26 deletions src/Helper/QueryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@ public class QueryHelper
/// <summary>
/// Gets the table name of a specified type, considering the TableNameAttribute if present.
/// </summary>
/// <typeparam name="T">The type for which to get the table name. Must implement <see cref="IDataContract"/>.</typeparam>
/// <typeparam name="T">The type for which to get the table name.</typeparam>
/// <returns>The table name.</returns>
public string GetTableName<T>() where T : IDataContract
public string GetTableName<T>()
{
return CacheManager.GetTableName(typeof(T));
}

/// <summary>
/// Gets the table schema of a specified type, considering the TableSchemaAttribute if present.
/// </summary>
/// <typeparam name="T">The type for which to get the table schema. Must implement <see cref="IDataContract"/>.</typeparam>
/// <typeparam name="T">The type for which to get the table schema.</typeparam>
/// <returns>The table schema name or null if not specified.</returns>
public string? GetTableSchema<T>() where T : IDataContract
public string? GetTableSchema<T>()
{
return CacheManager.GetTableSchema(typeof(T));
}

/// <summary>
/// Gets whether the type specifies to generate an INSERT query with ID, considering the GenerateInsertWithIDAttribute if present.
/// </summary>
/// <typeparam name="T">The type for which to determine the generation of INSERT query with ID. Must implement <see cref="IDataContract"/>.</typeparam>
/// <typeparam name="T">The type for which to determine the generation of INSERT query with ID.</typeparam>
/// <returns>True if the INSERT query should include ID, otherwise false.</returns>
public bool GetInsertWithID<T>() where T : IDataContract
public bool GetInsertWithID<T>()
{
return CacheManager.GetInsertWithID(typeof(T));
}
Expand All @@ -44,80 +44,73 @@ public bool GetInsertWithID<T>() where T : IDataContract
/// during insert query generation, considering the GenerateInsertWithIDAttribute if present.
/// </summary>
/// <typeparam name="T">The type for which to determine the inclusion of identity insert statements.
/// Must implement <see cref="IDataContract"/>.</typeparam>
///</typeparam>
/// <returns><c>true</c> if identity insert statements should be included; otherwise, <c>false</c>.</returns>
public bool GetIncludeIdentityInsert<T>() where T : IDataContract
public bool GetIncludeIdentityInsert<T>()
{
return CacheManager.GetIncludeIdentityInsert(typeof(T));
}

/// <summary>
/// Gets the names of properties marked as key columns for a specified type.
/// </summary>
/// <typeparam name="T">The type for which to get the key columns. Must implement <see cref="IDataContract"/>.</typeparam>
/// <typeparam name="T">The type for which to get the key columns.</typeparam>
/// <returns>A list of key column names.</returns>
/// <seealso cref="IDataContract"/>
public List<string> GetKeyColumns<T>() where T : IDataContract
public List<string> GetKeyColumns<T>()
{
return CacheManager.GetKeyColumns(typeof(T));
}

/// <summary>
/// Gets the names of properties marked as excluded properties for a specified type.
/// </summary>
/// <typeparam name="T">The type for which to get the excluded properties. Must implement <see cref="IDataContract"/>.</typeparam>
/// <typeparam name="T">The type for which to get the excluded properties.</typeparam>
/// <returns>A list of excluded property names.</returns>
/// <seealso cref="IDataContract"/>
public List<string> GetExcludedColumns<T>() where T : IDataContract
public List<string> GetExcludedColumns<T>()
{
return CacheManager.GetExcludedColumns(typeof(T));
}

/// <summary>
/// Gets the names of all properties for a specified type.
/// </summary>
/// <typeparam name="T">The type for which to get all properties. Must implement <see cref="IDataContract"/>.</typeparam>
/// <typeparam name="T">The type for which to get all properties.</typeparam>
/// <returns>A list of all property names.</returns>
/// <seealso cref="IDataContract"/>
public List<string> GetAllColumns<T>() where T : IDataContract
public List<string> GetAllColumns<T>()
{
return CacheManager.GetAllColumns(typeof(T));
}

/// <summary>
/// Retrieves a list of identity columns for a specified data contract type <typeparamref name="T"/>.
/// </summary>
/// <typeparam name="T">The type implementing the IDataContract interface.</typeparam>
/// <returns>A list containing the names of identity columns for the specified data contract type <typeparamref name="T"/>.</returns>
/// <remarks>
/// This method uses reflection to analyze the properties of the specified type <typeparamref name="T"/> and retrieves properties marked with a [Key] attribute, indicating identity columns.
/// </remarks>
/// <seealso cref="IDataContract"/>
public List<string> GetIdentityColumns<T>() where T : IDataContract
public List<string> GetIdentityColumns<T>()
{
return CacheManager.GetIdentityColumns(typeof(T));
}

/// <summary>
/// Retrieves an array of <see cref="PropertyInfo"/> objects representing the properties that are used for data comparison
/// in objects of type <typeparamref name="T"/>. These properties are determined based on the implementation of the
/// <see cref="IDataContract"/> interface.
/// in objects of type <typeparamref name="T"/>.
/// </summary>
/// <typeparam name="T">The type of objects for which to retrieve comparable properties.</typeparam>
/// <returns>An array of <see cref="PropertyInfo"/> objects representing the comparable properties of type <typeparamref name="T"/>.</returns>
public PropertyInfo[] GetComparableProperties<T>() where T: IDataContract
public PropertyInfo[] GetComparableProperties<T>()
{
return CacheManager.GetComparableProperties(typeof(T));
}

/// <summary>
/// Retrieves an array of <see cref="PropertyInfo"/> objects representing the properties that are used as key properties
/// for uniquely identifying objects of type <typeparamref name="T"/>. These key properties are determined based on the
/// implementation of the <see cref="IDataContract"/> interface.
/// for uniquely identifying objects of type <typeparamref name="T"/>.
/// </summary>
/// <typeparam name="T">The type of objects for which to retrieve key properties.</typeparam>
/// <returns>An array of <see cref="PropertyInfo"/> objects representing the key properties of type <typeparamref name="T"/>.</returns>
public PropertyInfo[] GetKeyProperties<T>() where T : IDataContract
public PropertyInfo[] GetKeyProperties<T>()
{
return CacheManager.GetKeyProperties(typeof(T));
}
Expand Down
12 changes: 0 additions & 12 deletions src/Interface/IDataContract.cs

This file was deleted.

10 changes: 5 additions & 5 deletions src/Interface/IQueryGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface IQueryGenerator : IDisposable
/// <param name="ListOfColumns">The list of columns to be selected.</param>
/// <param name="schemaName">The schema name of the database table.</param>
/// <returns>A string representing the generated SELECT query.</returns>
string GenerateSelectQuery<T>(string tableName, List<string> ListOfColumns, string schemaName) where T : IDataContract;
string GenerateSelectQuery<T>(string tableName, List<string> ListOfColumns, string schemaName);

/// <summary>
/// Generates an UPDATE query for updating data in a database table.
Expand All @@ -24,7 +24,7 @@ public interface IQueryGenerator : IDisposable
/// <param name="excludedColumns">The list of columns to be excluded from the update.</param>
/// <param name="editedProperties">A dictionary representing the properties and their new values to be updated.</param>
/// <returns>A string representing the generated UPDATE query.</returns>
string GenerateUpdateQuery<T>(T DataContract, List<string> keyColumns, List<string> excludedColumns, (string propName, object propValue)[] editedProperties) where T : IDataContract;
string GenerateUpdateQuery<T>(T DataContract, List<string> keyColumns, List<string> excludedColumns, (string propName, object propValue)[] editedProperties);

/// <summary>
/// Generates a DELETE query for deleting data from a database table.
Expand All @@ -33,7 +33,7 @@ public interface IQueryGenerator : IDisposable
/// <param name="entity">The entity representing the data to be deleted.</param>
/// <param name="keyColumns">The list of key columns used for deletion.</param>
/// <returns>A string representing the generated DELETE query.</returns>
string GenerateDeleteQuery<T>(T entity, List<string> keyColumns) where T : IDataContract;
string GenerateDeleteQuery<T>(T entity, List<string> keyColumns);

/// <summary>
/// Generates an INSERT query for inserting data into a database table.
Expand All @@ -43,7 +43,7 @@ public interface IQueryGenerator : IDisposable
/// <param name="keyColumns">The list of key columns used for insertion.</param>
/// <param name="excludedColumns">The list of columns to be excluded from the insertion.</param>
/// <returns>A string representing the generated INSERT query.</returns>
string GenerateInsertQuery<T>(T entity, List<string> keyColumns, List<string> excludedColumns) where T : IDataContract;
string GenerateInsertQuery<T>(T entity, List<string> keyColumns, List<string> excludedColumns);

/// <summary>
/// Generates a SQL comment.
Expand All @@ -59,7 +59,7 @@ public interface IQueryGenerator : IDisposable
/// <param name="entity">The entity for which the condition is generated.</param>
/// <param name="keyColumns">The list of key columns used to create the condition.</param>
/// <returns>A string representing the generated condition for a SQL WHERE clause.</returns>
List<string> GetCondition<T>(T entity, List<string> keyColumns) where T : IDataContract;
List<string> GetCondition<T>(T entity, List<string> keyColumns);

/// <summary>
/// Escapes special characters in the input to make it SQL-safe.
Expand Down
10 changes: 5 additions & 5 deletions src/QueryGenerationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ public QueryGenerationManager(IQueryGenerator querryGenerator)

#region Public Methods
/// <inheritdoc />
public string GenerateSelectQuery<T>(string tableName, List<string> listOfColumns, string schemaName) where T : IDataContract
public string GenerateSelectQuery<T>(string tableName, List<string> listOfColumns, string schemaName)
{
return _querryGenerator.GenerateSelectQuery<T>(tableName, listOfColumns, schemaName);
}

/// <inheritdoc />
public string GenerateUpdateQuery<T>(T DataContract, List<string> keyColumns, List<string> excludedColumns, (string propName, object propValue)[] editedProperties) where T : IDataContract
public string GenerateUpdateQuery<T>(T DataContract, List<string> keyColumns, List<string> excludedColumns, (string propName, object propValue)[] editedProperties)
{
return _querryGenerator.GenerateUpdateQuery<T>(DataContract, keyColumns, excludedColumns, editedProperties);
}

/// <inheritdoc />
public string GenerateDeleteQuery<T>(T entity, List<string> keyColumns) where T : IDataContract
public string GenerateDeleteQuery<T>(T entity, List<string> keyColumns)
{
return _querryGenerator.GenerateDeleteQuery<T>(entity, keyColumns);
}

/// <inheritdoc />
public string GenerateInsertQuery<T>(T entity, List<string> keyColumns, List<string> excludedColumns) where T : IDataContract
public string GenerateInsertQuery<T>(T entity, List<string> keyColumns, List<string> excludedColumns)
{
return _querryGenerator.GenerateInsertQuery<T>(entity, keyColumns, excludedColumns);
}
Expand All @@ -54,7 +54,7 @@ public string GenerateComment(string comment)
}

/// <inheritdoc />
public List<string> GetCondition<T>(T entity, List<string> keyColumns) where T : IDataContract
public List<string> GetCondition<T>(T entity, List<string> keyColumns)
{
return _querryGenerator.GetCondition<T>(entity, keyColumns);
}
Expand Down

0 comments on commit 7e65118

Please sign in to comment.