forked from Trendyol/Transporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trendyol#14 Postgresql adapter added
- Loading branch information
1 parent
564d9ae
commit ede143b
Showing
36 changed files
with
1,285 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
Transporter.PostgreSQLAdapter/Adapters/PostgreSqlInterimAdapter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Configuration; | ||
using Transporter.Core.Adapters.Base.Interfaces; | ||
using Transporter.Core.Adapters.Interim.Interfaces; | ||
using Transporter.Core.Configs.Base.Interfaces; | ||
using Transporter.Core.Utils; | ||
using Transporter.PostgreSQLAdapter.Configs.Interim.Interfaces; | ||
using Transporter.PostgreSQLAdapter.Services.Interim.Interfaces; | ||
using Transporter.PostgreSQLAdapter.Utils; | ||
|
||
namespace Transporter.PostgreSQLAdapter.Adapters | ||
{ | ||
public class PostgreSqlInterimAdapter : IInterimAdapter | ||
{ | ||
private readonly IConfiguration _configuration; | ||
private readonly IInterimService _interimService; | ||
private IPostgreSqlInterimSettings _settings; | ||
public PostgreSqlInterimAdapter(IConfiguration configuration, IInterimService interimService) | ||
{ | ||
_configuration = configuration; | ||
_interimService = interimService; | ||
} | ||
|
||
public object Clone() | ||
{ | ||
var result = MemberwiseClone() as IAdapter; | ||
return result; | ||
} | ||
|
||
public bool CanHandle(ITransferJobSettings transferJobSettings) | ||
{ | ||
var options = GetOptions(transferJobSettings); | ||
return string.Equals(options.Type, PostgreSqlAdapterConstants.OptionsType, | ||
StringComparison.InvariantCultureIgnoreCase); | ||
} | ||
|
||
public bool CanHandle(IPollingJobSettings jobSetting) | ||
{ | ||
var type = GetTypeBySettings(jobSetting); | ||
return string.Equals(type, PostgreSqlAdapterConstants.OptionsType, StringComparison.InvariantCultureIgnoreCase); | ||
} | ||
|
||
public void SetOptions(ITransferJobSettings transferJobSettings) | ||
{ | ||
_settings = GetOptions(transferJobSettings); | ||
} | ||
|
||
public void SetOptions(IPollingJobSettings jobSettings) | ||
{ | ||
_settings = GetOptions(jobSettings); | ||
} | ||
|
||
public async Task<IEnumerable<dynamic>> GetAsync() | ||
{ | ||
return await _interimService.GetInterimDataAsync(_settings); | ||
} | ||
|
||
public async Task DeleteAsync(IEnumerable<dynamic> ids) | ||
{ | ||
await _interimService.DeleteAsync(_settings, ids); | ||
} | ||
|
||
private IPostgreSqlInterimSettings GetOptions(ITransferJobSettings transferJobSettings) | ||
{ | ||
var jobOptionsList = _configuration | ||
.GetSection(Constants.TransferJobSettings).Get<List<PostgreSqlTransferJobSettings>>(); | ||
var options = jobOptionsList.First(x => x.Name == transferJobSettings.Name); | ||
return (IPostgreSqlInterimSettings)options.Interim; | ||
} | ||
|
||
private IPostgreSqlInterimSettings GetOptions(IPollingJobSettings jobSettings) | ||
{ | ||
var jobOptionsList = _configuration | ||
.GetSection(Constants.PollingJobSettings).Get<List<PostgreSqlTransferJobSettings>>(); | ||
var options = jobOptionsList.First(x => x.Name == jobSettings.Name); | ||
return (IPostgreSqlInterimSettings)options.Interim; | ||
} | ||
|
||
private string GetTypeBySettings(IPollingJobSettings jobSettings) | ||
{ | ||
var jobOptionsList = _configuration | ||
.GetSection(Constants.PollingJobSettings).Get<List<PostgreSqlTransferJobSettings>>(); | ||
var options = jobOptionsList.First(x => x.Name == jobSettings.Name); | ||
return options.Interim?.Type; | ||
} | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
Transporter.PostgreSQLAdapter/Adapters/PostgreSqlSourceAdapter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Configuration; | ||
using Transporter.Core.Adapters.Base.Interfaces; | ||
using Transporter.Core.Adapters.Source.Interfaces; | ||
using Transporter.Core.Configs.Base.Interfaces; | ||
using Transporter.Core.Utils; | ||
using Transporter.PostgreSQLAdapter; | ||
using Transporter.PostgreSQLAdapter.Configs.Source.Interfaces; | ||
using Transporter.PostgreSQLAdapter.Services.Source.Interfaces; | ||
using Transporter.PostgreSQLAdapter.Utils; | ||
|
||
namespace Transporter.PostgreSqlAdapter.Adapters | ||
{ | ||
public class PostgreSqlSourceAdapter : ISourceAdapter | ||
{ | ||
private readonly IConfiguration _configuration; | ||
private readonly ISourceService _sourceService; | ||
private IPostgreSqlSourceSettings _settings; | ||
|
||
public PostgreSqlSourceAdapter(ISourceService sourceService, IConfiguration configuration) | ||
{ | ||
_sourceService = sourceService; | ||
_configuration = configuration; | ||
} | ||
|
||
public bool CanHandle(ITransferJobSettings transferJobSettings) | ||
{ | ||
var options = GetOptions(transferJobSettings); | ||
return string.Equals(options.Type, PostgreSqlAdapterConstants.OptionsType, | ||
StringComparison.InvariantCultureIgnoreCase); | ||
} | ||
|
||
public bool CanHandle(IPollingJobSettings jobSetting) | ||
{ | ||
var type = GetTypeBySettings(jobSetting); | ||
return string.Equals(type, PostgreSqlAdapterConstants.OptionsType, StringComparison.InvariantCultureIgnoreCase); | ||
} | ||
|
||
public void SetOptions(ITransferJobSettings transferJobSettings) | ||
{ | ||
_settings = GetOptions(transferJobSettings); | ||
} | ||
|
||
public void SetOptions(IPollingJobSettings jobSettings) | ||
{ | ||
_settings = GetOptions(jobSettings); | ||
} | ||
|
||
public async Task<IEnumerable<dynamic>> GetAsync(IEnumerable<dynamic> ids) | ||
{ | ||
return await _sourceService.GetSourceDataAsync(_settings, ids); | ||
} | ||
|
||
public async Task DeleteAsync(IEnumerable<dynamic> ids) | ||
{ | ||
await _sourceService.DeleteDataByListOfIdsAsync(_settings, ids); | ||
} | ||
|
||
public string GetDataSourceName() | ||
{ | ||
return $"{_settings.Options.Schema}.{_settings.Options.Table}"; | ||
} | ||
|
||
public async Task<IEnumerable<dynamic>> GetIdsAsync() | ||
{ | ||
return await _sourceService.GetIdDataAsync(_settings); | ||
} | ||
|
||
public virtual object Clone() | ||
{ | ||
var result = MemberwiseClone() as IAdapter; | ||
return result; | ||
} | ||
|
||
private IPostgreSqlSourceSettings GetOptions(ITransferJobSettings transferJobSettings) | ||
{ | ||
var jobOptionsList = _configuration | ||
.GetSection(Constants.TransferJobSettings).Get<List<PostgreSqlTransferJobSettings>>(); | ||
var options = jobOptionsList.First(x => x.Name == transferJobSettings.Name); | ||
return (IPostgreSqlSourceSettings)options.Source; | ||
} | ||
|
||
private IPostgreSqlSourceSettings GetOptions(IPollingJobSettings jobSettings) | ||
{ | ||
var jobOptionsList = _configuration | ||
.GetSection(Constants.PollingJobSettings).Get<List<PostgreSqlTransferJobSettings>>(); | ||
var options = jobOptionsList.First(x => x.Name == jobSettings.Name); | ||
return (IPostgreSqlSourceSettings)options.Source; | ||
} | ||
|
||
private string GetTypeBySettings(IPollingJobSettings jobSettings) | ||
{ | ||
var jobOptionsList = _configuration | ||
.GetSection(Constants.PollingJobSettings).Get<List<PostgreSqlTransferJobSettings>>(); | ||
var options = jobOptionsList.First(x => x.Name == jobSettings.Name); | ||
return options.Source?.Type; | ||
} | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
Transporter.PostgreSQLAdapter/Adapters/PostgreSqlTargetAdapter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Configuration; | ||
using Transporter.Core.Adapters.Base.Interfaces; | ||
using Transporter.Core.Adapters.Target.Interfaces; | ||
using Transporter.Core.Configs.Base.Interfaces; | ||
using Transporter.Core.Utils; | ||
using Transporter.PostgreSQLAdapter; | ||
using Transporter.PostgreSQLAdapter.Configs.Target.Interfaces; | ||
using Transporter.PostgreSQLAdapter.Services.Target.Interfaces; | ||
using Transporter.PostgreSQLAdapter.Utils; | ||
|
||
namespace Transporter.PostgreSqlAdapter.Adapters | ||
{ | ||
public class PostgreSqlTargetAdapter : ITargetAdapter | ||
{ | ||
private readonly IConfiguration _configuration; | ||
private readonly ITargetService _targetService; | ||
private IPostgreSqlTargetSettings _settings; | ||
|
||
public PostgreSqlTargetAdapter(ITargetService targetService, IConfiguration configuration) | ||
{ | ||
_targetService = targetService; | ||
_configuration = configuration; | ||
} | ||
|
||
public bool CanHandle(ITransferJobSettings transferJobSettings) | ||
{ | ||
var options = GetOptions(transferJobSettings); | ||
return string.Equals(options.Type, PostgreSqlAdapterConstants.OptionsType, | ||
StringComparison.InvariantCultureIgnoreCase); | ||
} | ||
|
||
public bool CanHandle(IPollingJobSettings jobSetting) | ||
{ | ||
var type = GetTypeBySettings(jobSetting); | ||
return string.Equals(type, PostgreSqlAdapterConstants.OptionsType, StringComparison.InvariantCultureIgnoreCase); | ||
} | ||
|
||
public void SetOptions(ITransferJobSettings transferJobSettings) | ||
{ | ||
_settings = GetOptions(transferJobSettings); | ||
} | ||
|
||
public void SetOptions(IPollingJobSettings jobSettings) | ||
{ | ||
_settings = GetOptions(jobSettings); | ||
} | ||
|
||
public async Task SetAsync(string data) | ||
{ | ||
await _targetService.SetTargetDataAsync(_settings, data); | ||
} | ||
|
||
public async Task SetInterimTableAsync(string data, string dataSourceName) | ||
{ | ||
await _targetService.SetTargetTemporaryDataAsync(_settings, data, dataSourceName); | ||
} | ||
|
||
public virtual object Clone() | ||
{ | ||
var result = MemberwiseClone() as IAdapter; | ||
return result; | ||
} | ||
|
||
private IPostgreSqlTargetSettings GetOptions(IPollingJobSettings jobSettings) | ||
{ | ||
var jobOptionsList = _configuration | ||
.GetSection(Constants.PollingJobSettings).Get<List<PostgreSqlTransferJobSettings>>(); | ||
var options = jobOptionsList.First(x => x.Name == jobSettings.Name); | ||
return (IPostgreSqlTargetSettings)options.Target; | ||
} | ||
|
||
private IPostgreSqlTargetSettings GetOptions(ITransferJobSettings transferJobSettings) | ||
{ | ||
var jobOptionsList = _configuration | ||
.GetSection(Constants.TransferJobSettings).Get<List<PostgreSqlTransferJobSettings>>(); | ||
var options = jobOptionsList.First(x => x.Name == transferJobSettings.Name); | ||
return (IPostgreSqlTargetSettings)options.Target; | ||
} | ||
|
||
private string GetTypeBySettings(IPollingJobSettings jobSettings) | ||
{ | ||
var jobOptionsList = _configuration | ||
.GetSection(Constants.PollingJobSettings).Get<List<PostgreSqlTransferJobSettings>>(); | ||
var options = jobOptionsList.First(x => x.Name == jobSettings.Name); | ||
return options.Target?.Type; | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Transporter.PostgreSQLAdapter/Configs/Interim/Implementations/PostgreSqlInterimOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Transporter.PostgreSQLAdapter.Configs.Interim.Interfaces; | ||
|
||
namespace Transporter.PostgreSQLAdapter.Configs.Interim.Implementations | ||
{ | ||
public class PostgreSqlInterimOptions : IPostgreSqlInterimOptions | ||
{ | ||
public string Table { get; set; } | ||
public string Schema { get; set; } | ||
public string ConnectionString { get; set; } | ||
public long BatchQuantity { get; set; } | ||
public string DataSourceName { get; set; } | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
Transporter.PostgreSQLAdapter/Configs/Interim/Implementations/PostgreSqlInterimSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Transporter.PostgreSQLAdapter.Configs.Interim.Interfaces; | ||
|
||
namespace Transporter.PostgreSQLAdapter.Configs.Interim.Implementations | ||
{ | ||
public class PostgreSqlInterimSettings : IPostgreSqlInterimSettings | ||
{ | ||
public PostgreSqlInterimSettings() | ||
{ | ||
Options = new PostgreSqlInterimOptions(); | ||
} | ||
|
||
public IPostgreSqlInterimOptions Options { get; set; } | ||
public string Type { get; set; } | ||
|
||
public override string ToString() | ||
{ | ||
return $"Type : {Type} Options : {Options}"; | ||
} | ||
|
||
public string Host { get; set; } | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Transporter.PostgreSQLAdapter/Configs/Interim/Interfaces/IPostgreSqlInterimOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Transporter.PostgreSQLAdapter.Configs.Interim.Interfaces | ||
{ | ||
public interface IPostgreSqlInterimOptions | ||
{ | ||
public string Table { get; set; } | ||
public string Schema { get; set; } | ||
public string ConnectionString { get; set; } | ||
public long BatchQuantity { get; set; } | ||
public string DataSourceName { get; set; } | ||
} | ||
} |
Oops, something went wrong.