chore: initial git load of code space

This commit is contained in:
Thom Lamb
2026-05-12 08:52:33 -05:00
parent 9abada692f
commit 5e467bcc9c
384 changed files with 65960 additions and 2 deletions
@@ -0,0 +1,130 @@
using System.Collections;
using System.Text;
using Strata.SqlTools.SqlBreakdown.Interfaces;
namespace Strata.SqlTools.SqlBreakdown.Classes;
/// <summary>
/// Base class for SQL query breakdowns that provides common setup/finish clause handling and cloning.
/// </summary>
[Serializable]
public abstract class SqlBreakdownBase : ISqlBreakdown
{
/// <summary>
/// Initializes a new instance of the <see cref="SqlBreakdownBase"/> class.
/// </summary>
protected SqlBreakdownBase()
{
SetupClauses = new List<string>();
FinishClauses = new ArrayList();
}
/// <summary>
/// Gets or sets the setup clauses to execute before the main query.
/// </summary>
public List<string> SetupClauses { get; set; }
/// <summary>
/// Gets a value indicating whether setup clauses are being used.
/// </summary>
public bool IsUsingSetupClause => SetupClauses.Count > 0;
/// <summary>
/// Gets or sets the raw/original SQL statement before parsing and breakdown.
/// </summary>
/// <remarks>
/// This property stores the original SQL text that was parsed to create this breakdown.
/// It's useful for auditing, logging, and batch statement retrieval.
/// </remarks>
public string? RawSql { get; set; }
/// <summary>
/// Gets or sets the finish clauses to execute after the main query.
/// </summary>
public ArrayList FinishClauses { get; set; }
/// <summary>
/// Gets a value indicating whether finish clauses are being used.
/// </summary>
public bool IsUsingFinishClause => FinishClauses.Count > 0;
/// <summary>
/// Gets the SQL breakdown as a string. Must be implemented by derived classes.
/// </summary>
/// <returns>The SQL query string.</returns>
protected abstract string GetSqlBreakdown();
/// <summary>
/// Gets a LINQ to SQL query of the specified type based on this breakdown.
/// </summary>
/// <typeparam name="T">The entity type for the query.</typeparam>
/// <returns>An IQueryable of the specified type, or null if the breakdown cannot be converted to a LINQ query.</returns>
/// <remarks>
/// This method allows derived breakdown classes to reconstruct or generate LINQ queries
/// from the analyzed components (SELECT, WHERE, ORDER BY, etc.).
/// The default implementation returns null.
/// </remarks>
public virtual IQueryable<T>? GetQuery<T>() where T : class => null;
/// <summary>
/// Gets the complete SQL query including optional setup and finish clauses.
/// </summary>
/// <param name="includeSetupFinish">Whether to include setup and finish clauses.</param>
/// <returns>The complete SQL query string.</returns>
public string GetSql(bool includeSetupFinish = true)
{
var sb = new StringBuilder();
if (includeSetupFinish)
{
// Write out any setup clauses
sb.AppendLine();
foreach (string setup in SetupClauses)
{
sb.AppendLine(setup);
}
sb.AppendLine();
}
sb.Append(GetSqlBreakdown());
if (includeSetupFinish)
{
// Write out any finish clauses
sb.AppendLine();
sb.AppendLine();
foreach (string finish in FinishClauses)
{
sb.AppendLine(finish);
}
}
return sb.ToString();
}
/// <summary>
/// Returns the SQL query as a string.
/// </summary>
/// <returns>The SQL query string.</returns>
public override string ToString()
=> GetSql();
/// <summary>
/// Creates a deep clone of this object.
/// </summary>
/// <returns>A cloned instance.</returns>
public object Clone()
{
// Create a shallow copy
var clone = (SqlBreakdownBase)MemberwiseClone();
// Deep copy the SetupClauses list
clone.SetupClauses = new List<string>(SetupClauses);
// Deep copy the FinishClauses ArrayList
clone.FinishClauses = new ArrayList(FinishClauses);
return clone;
}
}