Skip to content

Commit 51740b5

Browse files
committed
Performance Optimization & class Name Changes
1 parent b0ac912 commit 51740b5

7 files changed

Lines changed: 372 additions & 205 deletions

File tree

Enum/CachePropertyType.cs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,55 @@
66

77
namespace DbSyncKit.DB.Enum
88
{
9+
/// <summary>
10+
/// Enumerates the types of cached properties in the <see cref="CacheManager"/>.
11+
/// </summary>
912
public enum CachePropertyType
1013
{
14+
/// <summary>
15+
/// Represents all properties.
16+
/// </summary>
1117
All,
18+
19+
/// <summary>
20+
/// Represents properties marked as excluded.
21+
/// </summary>
1222
Excluded,
23+
24+
/// <summary>
25+
/// Represents properties marked as key columns.
26+
/// </summary>
1327
Key,
14-
Identity
28+
29+
/// <summary>
30+
/// Represents properties marked as identity columns.
31+
/// </summary>
32+
Identity,
33+
34+
/// <summary>
35+
/// Represents the table name associated with a type.
36+
/// </summary>
37+
TableName,
38+
39+
/// <summary>
40+
/// Represents the table schema associated with a type.
41+
/// </summary>
42+
TableSchema,
43+
44+
/// <summary>
45+
/// Represents whether to generate an INSERT query with an identity column.
46+
/// </summary>
47+
GenerateWithID,
48+
49+
/// <summary>
50+
/// Represents whether to include identity insert in an INSERT query.
51+
/// </summary>
52+
IncludeIdentityInsert,
53+
54+
/// <summary>
55+
/// Represents properties that are comparable (neither key nor excluded).
56+
/// </summary>
57+
ComparableProperties
1558
}
59+
1660
}

Helper/QueryHelper.cs

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,14 @@ namespace DbSyncKit.DB.Helper
1111
/// </summary>
1212
public class QueryHelper
1313
{
14-
/// <summary>
15-
/// Replaces a specified placeholder in a StringBuilder with the provided replacement string.
16-
/// </summary>
17-
/// <param name="stringBuilder">The StringBuilder to modify.</param>
18-
/// <param name="placeholder">The placeholder to replace.</param>
19-
/// <param name="replacement">The string to replace the placeholder.</param>
20-
public void ReplacePlaceholder(ref StringBuilder stringBuilder, string placeholder, string replacement)
21-
{
22-
// Use Regex to replace all occurrences of the placeholder
23-
string pattern = Regex.Escape(placeholder);
24-
stringBuilder.Replace(pattern, replacement);
25-
}
26-
2714
/// <summary>
2815
/// Gets the table name of a specified type, considering the TableNameAttribute if present.
2916
/// </summary>
3017
/// <typeparam name="T">The type for which to get the table name. Must implement <see cref="IDataContractComparer"/>.</typeparam>
3118
/// <returns>The table name.</returns>
3219
public string GetTableName<T>() where T : IDataContractComparer
3320
{
34-
TableNameAttribute? tableNameAttribute = (TableNameAttribute?)Attribute.GetCustomAttribute(typeof(T), typeof(TableNameAttribute));
35-
36-
if (tableNameAttribute != null)
37-
return tableNameAttribute.TableName;
38-
39-
return typeof(T).Name;
21+
return CacheManager.GetTableName(typeof(T));
4022
}
4123

4224
/// <summary>
@@ -46,12 +28,7 @@ public string GetTableName<T>() where T : IDataContractComparer
4628
/// <returns>The table schema name or null if not specified.</returns>
4729
public string? GetTableSchema<T>() where T : IDataContractComparer
4830
{
49-
TableSchemaAttribute? tableSchemaAttribute = (TableSchemaAttribute?)Attribute.GetCustomAttribute(typeof(T), typeof(TableSchemaAttribute));
50-
51-
if (tableSchemaAttribute != null)
52-
return tableSchemaAttribute.SchemaName;
53-
54-
return null;
31+
return CacheManager.GetTableSchema(typeof(T));
5532
}
5633

5734
/// <summary>
@@ -61,12 +38,7 @@ public string GetTableName<T>() where T : IDataContractComparer
6138
/// <returns>True if the INSERT query should include ID, otherwise false.</returns>
6239
public bool GetInsertWithID<T>() where T : IDataContractComparer
6340
{
64-
GenerateInsertWithIDAttribute? tableSchemaAttribute = (GenerateInsertWithIDAttribute?)Attribute.GetCustomAttribute(typeof(T), typeof(GenerateInsertWithIDAttribute));
65-
66-
if (tableSchemaAttribute != null)
67-
return tableSchemaAttribute.GenerateWithID;
68-
69-
return false;
41+
return CacheManager.GetInsertWithID(typeof(T));
7042
}
7143

7244
/// <summary>
@@ -78,12 +50,7 @@ public bool GetInsertWithID<T>() where T : IDataContractComparer
7850
/// <returns><c>true</c> if identity insert statements should be included; otherwise, <c>false</c>.</returns>
7951
public bool GetIncludeIdentityInsert<T>() where T : IDataContractComparer
8052
{
81-
GenerateInsertWithIDAttribute? attribute = (GenerateInsertWithIDAttribute?)Attribute.GetCustomAttribute(typeof(T), typeof(GenerateInsertWithIDAttribute));
82-
83-
if (attribute != null)
84-
return attribute.IncludeIdentityInsert;
85-
86-
return false;
53+
return CacheManager.GetIncludeIdentityInsert(typeof(T));
8754
}
8855

8956
/// <summary>
@@ -94,7 +61,7 @@ public bool GetIncludeIdentityInsert<T>() where T : IDataContractComparer
9461
/// <seealso cref="IDataContractComparer"/>
9562
public List<string> GetKeyColumns<T>() where T : IDataContractComparer
9663
{
97-
return TypePropertyCacheManager.GetKeyColumns(typeof(T));
64+
return CacheManager.GetKeyColumns(typeof(T));
9865
}
9966

10067
/// <summary>
@@ -105,7 +72,7 @@ public List<string> GetKeyColumns<T>() where T : IDataContractComparer
10572
/// <seealso cref="IDataContractComparer"/>
10673
public List<string> GetExcludedProperties<T>() where T : IDataContractComparer
10774
{
108-
return TypePropertyCacheManager.GetExcludedProperties(typeof(T));
75+
return CacheManager.GetExcludedProperties(typeof(T));
10976
}
11077

11178
/// <summary>
@@ -116,7 +83,7 @@ public List<string> GetExcludedProperties<T>() where T : IDataContractComparer
11683
/// <seealso cref="IDataContractComparer"/>
11784
public List<string> GetAllColumns<T>() where T : IDataContractComparer
11885
{
119-
return TypePropertyCacheManager.GetAllColumns(typeof(T));
86+
return CacheManager.GetAllColumns(typeof(T));
12087
}
12188

12289
/// <summary>
@@ -130,7 +97,7 @@ public List<string> GetAllColumns<T>() where T : IDataContractComparer
13097
/// <seealso cref="IDataContractComparer"/>
13198
public List<string> GetIdentityColumns<T>() where T : IDataContractComparer
13299
{
133-
return TypePropertyCacheManager.GetIdentityColumns(typeof(T));
100+
return CacheManager.GetIdentityColumns(typeof(T));
134101
}
135102

136103
}

Interface/IQueryGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/// <summary>
44
/// Defines methods for generating SQL queries and handling query-related operations.
55
/// </summary>
6-
public interface IQueryGenerator
6+
public interface IQueryGenerator : IDisposable
77
{
88
/// <summary>
99
/// Generates a SELECT query for retrieving data from a database table.

0 commit comments

Comments
 (0)