using FreeSql.Internal; using FreeSql.Internal.CommonProvider; using FreeSql.ClickHouse.Curd; using System; using System.Data.Common; using System.Linq.Expressions; using System.Threading; namespace FreeSql.ClickHouse { public class ClickHouseProvider : BaseDbProvider, IFreeSql { public override ISelect CreateSelectProvider(object dywhere) => new ClickHouseSelect(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere); public override IInsert CreateInsertProvider() => new ClickHouseInsert(this, this.InternalCommonUtils, this.InternalCommonExpression); public override IUpdate CreateUpdateProvider(object dywhere) => new ClickHouseUpdate(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere); public override IDelete CreateDeleteProvider(object dywhere) => new ClickHouseDelete(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere); public override IInsertOrUpdate CreateInsertOrUpdateProvider() { throw new NotImplementedException(); } public ClickHouseProvider(string masterConnectionString, string[] slaveConnectionString, Func connectionFactory = null) { this.InternalCommonUtils = new ClickHouseUtils(this); this.InternalCommonExpression = new ClickHouseExpression(this.InternalCommonUtils); this.Ado = new ClickHouseAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString, connectionFactory); this.Aop = new AopProvider(); this.DbFirst = new ClickHouseDbFirst(this, this.InternalCommonUtils, this.InternalCommonExpression); this.CodeFirst = new ClickHouseCodeFirst(this, this.InternalCommonUtils, this.InternalCommonExpression); } ~ClickHouseProvider() => this.Dispose(); int _disposeCounter; public override void Dispose() { if (Interlocked.Increment(ref _disposeCounter) != 1) return; (this.Ado as AdoProvider)?.Dispose(); } } }