using FreeSql.Internal.CommonProvider; using System; using System.Data.Common; using System.Threading; namespace FreeSql.Custom.PostgreSQL { public class CustomPostgreSQLProvider : BaseDbProvider, IFreeSql { public override ISelect CreateSelectProvider(object dywhere) => new CustomPostgreSQLSelect(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere); public override IInsert CreateInsertProvider() => new CustomPostgreSQLInsert(this, this.InternalCommonUtils, this.InternalCommonExpression); public override IUpdate CreateUpdateProvider(object dywhere) => new CustomPostgreSQLUpdate(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere); public override IDelete CreateDeleteProvider(object dywhere) => new CustomPostgreSQLDelete(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere); public override IInsertOrUpdate CreateInsertOrUpdateProvider() => new CustomPostgreSQLInsertOrUpdate(this, this.InternalCommonUtils, this.InternalCommonExpression); public CustomPostgreSQLProvider(string masterConnectionString, string[] slaveConnectionString, Func connectionFactory = null) { this.InternalCommonUtils = new CustomPostgreSQLUtils(this); this.InternalCommonExpression = new CustomPostgreSQLExpression(this.InternalCommonUtils); this.Ado = new CustomPostgreSQLAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString, connectionFactory); this.Aop = new AopProvider(); this.DbFirst = new CustomPostgreSQLDbFirst(this, this.InternalCommonUtils, this.InternalCommonExpression); this.CodeFirst = new CustomPostgreSQLCodeFirst(this, this.InternalCommonUtils, this.InternalCommonExpression); } ~CustomPostgreSQLProvider() => this.Dispose(); int _disposeCounter; public override void Dispose() { if (Interlocked.Increment(ref _disposeCounter) != 1) return; try { (this.Ado as AdoProvider)?.Dispose(); } finally { FreeSqlCustomAdapterGlobalExtensions._dicCustomAdater.TryRemove(Ado.Identifier, out var tryada); FreeSqlCustomAdapterGlobalExtensions._dicDbProviderFactory.TryRemove(Ado.Identifier, out var trydbpf); } } } }