-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactored the code * moved oracle integration into core
- Loading branch information
1 parent
0ff3f82
commit eba72a9
Showing
14 changed files
with
334 additions
and
191 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
22 changes: 22 additions & 0 deletions
22
Elfo.Wardein.Core/Helpers/ExternalResources/DB/Oracle/Abstractions/IOracleService.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 System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Threading.Tasks; | ||
|
||
namespace Elfo.Wardein.Core.Helpers | ||
{ | ||
public interface IOracleService | ||
{ | ||
IEnumerable<T> Query<T>(IDbConnection connection, string query, | ||
IDictionary<string, object> parameters, TimeSpan? timeout = null); | ||
|
||
int Execute(IDbConnection connection, string command, | ||
IDictionary<string, object> parameters, TimeSpan? timeout = null); | ||
|
||
Task<IEnumerable<T>> QueryAsync<T>(IDbConnection connection, string query, | ||
IDictionary<string, object> parameters, TimeSpan? timeout = null); | ||
|
||
Task<int> ExecuteAsync(IDbConnection connection, string command, | ||
IDictionary<string, object> parameters, TimeSpan? timeout = null); | ||
} | ||
} |
47 changes: 35 additions & 12 deletions
47
...ions/Oracle.Integration/IOracleService.cs → ...esources/DB/Oracle/DapperOracleService.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
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
136 changes: 136 additions & 0 deletions
136
Elfo.Wardein.Core/Helpers/ExternalResources/DB/Oracle/OracleHelper.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,136 @@ | ||
using Oracle.ManagedDataAccess.Client; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Elfo.Wardein.Core.Helpers | ||
{ | ||
public class OracleHelper | ||
{ | ||
private readonly OracleConnectionConfiguration oracleConfiguration; | ||
|
||
public OracleHelper(OracleConnectionConfiguration oracleConfiguration) | ||
{ | ||
this.oracleConfiguration = oracleConfiguration; | ||
} | ||
|
||
public IEnumerable<T> Query<T>(string query, IDictionary<string, object> parameters = null) | ||
{ | ||
try | ||
{ | ||
var result = default(IEnumerable<T>); | ||
using (var connection = new OracleConnection(oracleConfiguration.ConnectionString)) | ||
{ | ||
connection.Open(); | ||
using (var transaction = connection.BeginTransaction()) | ||
{ | ||
connection.SetSessionInfoForTransaction(oracleConfiguration); | ||
|
||
var queryToExecute = string.IsNullOrWhiteSpace(query) ? oracleConfiguration.Query : query; | ||
var queryParameters = parameters ?? oracleConfiguration.QueryParameters; | ||
|
||
result = oracleConfiguration.OracleServiceProvider().Query<T>(connection, queryToExecute, | ||
queryParameters, oracleConfiguration.QueryTimeout); | ||
transaction.Commit(); | ||
} | ||
} | ||
return result; | ||
} | ||
catch (Exception exception) | ||
{ | ||
throw exception; | ||
} | ||
} | ||
|
||
public int Execute(string command, IDictionary<string, object> parameters = null) | ||
{ | ||
|
||
try | ||
{ | ||
int result = 0; | ||
|
||
using (var connection = new OracleConnection(oracleConfiguration.ConnectionString)) | ||
{ | ||
connection.Open(); | ||
|
||
using (var transaction = connection.BeginTransaction()) | ||
{ | ||
connection.SetSessionInfoForTransaction(oracleConfiguration); | ||
|
||
var commandToExecute = string.IsNullOrWhiteSpace(command) ? oracleConfiguration.Command : command; | ||
var commandParameters = parameters ?? oracleConfiguration.CommandParameters; | ||
|
||
result = oracleConfiguration.OracleServiceProvider().Execute(connection, commandToExecute, | ||
commandParameters, oracleConfiguration.CommandTimeout); | ||
transaction.Commit(); | ||
} | ||
} | ||
return result; | ||
} | ||
catch (Exception exception) | ||
{ | ||
throw exception; | ||
} | ||
} | ||
|
||
public async Task<IEnumerable<T>> QueryAsync<T>(string query, IDictionary<string, object> parameters = null) | ||
{ | ||
try | ||
{ | ||
var result = default(IEnumerable<T>); | ||
using (var connection = new OracleConnection(oracleConfiguration.ConnectionString)) | ||
{ | ||
connection.Open(); | ||
using (var transaction = connection.BeginTransaction()) | ||
{ | ||
connection.SetSessionInfoForTransaction(oracleConfiguration); | ||
|
||
var queryToExecute = string.IsNullOrWhiteSpace(query) ? oracleConfiguration.Query : query; | ||
var queryParameters = parameters ?? oracleConfiguration.QueryParameters; | ||
|
||
result = await oracleConfiguration.OracleServiceProvider().QueryAsync<T>(connection, queryToExecute, | ||
queryParameters, oracleConfiguration.QueryTimeout); | ||
transaction.Commit(); | ||
} | ||
} | ||
return result; | ||
} | ||
catch (Exception exception) | ||
{ | ||
throw exception; | ||
} | ||
} | ||
|
||
public async Task<int> ExecuteAsync(string command, IDictionary<string, object> parameters = null) | ||
{ | ||
|
||
try | ||
{ | ||
int result = 0; | ||
|
||
using (var connection = new OracleConnection(oracleConfiguration.ConnectionString)) | ||
{ | ||
connection.Open(); | ||
|
||
using (var transaction = connection.BeginTransaction()) | ||
{ | ||
connection.SetSessionInfoForTransaction(oracleConfiguration); | ||
|
||
var commandToExecute = string.IsNullOrWhiteSpace(command) ? oracleConfiguration.Command : command; | ||
var commandParameters = parameters ?? oracleConfiguration.CommandParameters; | ||
|
||
result = await oracleConfiguration.OracleServiceProvider().ExecuteAsync(connection, commandToExecute, | ||
commandParameters, oracleConfiguration.CommandTimeout); | ||
transaction.Commit(); | ||
} | ||
} | ||
return result; | ||
} | ||
catch (Exception exception) | ||
{ | ||
throw exception; | ||
} | ||
} | ||
} | ||
} |
File renamed without changes.
20 changes: 20 additions & 0 deletions
20
Elfo.Wardein.Core/Helpers/OracleConnectionExtensionMethods.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,20 @@ | ||
using Oracle.ManagedDataAccess.Client; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Elfo.Wardein.Core.Helpers | ||
{ | ||
public static class OracleConnectionExtensionMethods | ||
{ | ||
public static void SetSessionInfoForTransaction(this OracleConnection connection, OracleConnectionConfiguration oracleConfiguration) | ||
{ | ||
connection.ClientId = oracleConfiguration.ClientId; | ||
connection.ClientInfo = oracleConfiguration.ClientInfo; | ||
connection.ModuleName = oracleConfiguration.ModuleName; | ||
var sessionInfo = connection.GetSessionInfo(); | ||
sessionInfo.DateLanguage = oracleConfiguration.DateLanguage; | ||
connection.SetSessionInfo(sessionInfo); | ||
} | ||
} | ||
} |
Oops, something went wrong.