/
SqlDialect_Oracle.cs
89 lines (75 loc) · 3.58 KB
/
SqlDialect_Oracle.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
namespace NServiceBus
{
using System;
using System.Data;
using System.Data.Common;
using System.Reflection;
using System.Text;
public abstract partial class SqlDialect
{
/// <summary>
/// Oracle
/// </summary>
public partial class Oracle : SqlDialect
{
volatile PropertyInfo parametersByNameProperty;
internal override void SetJsonParameterValue(DbParameter parameter, object value)
{
SetParameterValue(parameter, value);
}
internal override void SetParameterValue(DbParameter parameter, object value)
{
if (value is Guid)
{
parameter.Value = value.ToString();
return;
}
if (value is Version)
{
parameter.DbType = DbType.String;
parameter.Value = value.ToString();
return;
}
parameter.Value = value;
}
internal override CommandWrapper CreateCommand(DbConnection connection)
{
var command = connection.CreateCommand();
if (parametersByNameProperty == null)
{
var type = command.GetType();
parametersByNameProperty = type.GetProperty("BindByName") ??
// someone might be using DevArt Oracle provider which uses PassParametersByName
type.GetProperty("PassParametersByName");
if (parametersByNameProperty == null)
{
throw new Exception($"Could not extract property 'BindByName' nor 'PassParametersByName' from '{type.AssemblyQualifiedName}'. The property is required to make sure the parameters passed to the commands can be passed by name and do not depend on the order they are added to the command.");
}
}
parametersByNameProperty.SetValue(command, true);
return new CommandWrapper(command, this);
}
internal override void ValidateTablePrefix(string tablePrefix)
{
if (tablePrefix.Length > 25)
{
throw new Exception($"Table prefix '{tablePrefix}' contains more than 25 characters, which is not supported by SQL persistence using Oracle. Shorten the endpoint name or specify a custom tablePrefix using endpointConfiguration.{nameof(SqlPersistenceConfig.TablePrefix)}(tablePrefix).");
}
if (Encoding.UTF8.GetBytes(tablePrefix).Length != tablePrefix.Length)
{
throw new Exception($"Table prefix '{tablePrefix}' contains non-ASCII characters, which is not supported by SQL persistence using Oracle. Change the endpoint name or specify a custom tablePrefix using endpointConfiguration.{nameof(SqlPersistenceConfig.TablePrefix)}(tablePrefix).");
}
}
internal override CommandBehavior ModifyBehavior(DbConnection connection, CommandBehavior baseBehavior)
{
return baseBehavior;
}
internal override object GetCustomDialectDiagnosticsInfo()
{
return new { CustomSchema = string.IsNullOrEmpty(Schema) };
}
internal string Schema { get; set; }
string SchemaPrefix => Schema != null ? $"\"{Schema.ToUpper()}\"." : "";
}
}
}