forked from stuartcarnie/nhibernate-test
-
Notifications
You must be signed in to change notification settings - Fork 19
/
TestDialect.cs
171 lines (138 loc) · 5.57 KB
/
TestDialect.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
using System;
using NHibernate.Id;
using NHibernate.SqlTypes;
namespace NHibernate.Test
{
/// <summary>
/// Like NHibernate's Dialect class, but for differences only important during testing.
/// Defaults to true for all support. Users of different dialects can turn support
/// off if the unit tests fail.
/// </summary>
public class TestDialect
{
public static TestDialect GetTestDialect(Dialect.Dialect dialect)
{
var testDialectTypeName = "NHibernate.Test.TestDialects." + dialect.GetType().Name.Replace("Dialect", "TestDialect");
var testDialectType = System.Type.GetType(testDialectTypeName);
if (testDialectType != null)
return (TestDialect) Activator.CreateInstance(testDialectType, dialect);
return new TestDialect(dialect);
}
readonly Dialect.Dialect _dialect;
public TestDialect(Dialect.Dialect dialect)
{
_dialect = dialect;
}
/// <summary>
/// Has a native generator strategy resolving to identity.
/// </summary>
public bool HasIdentityNativeGenerator
=> _dialect.NativeIdentifierGeneratorClass == typeof(IdentityGenerator);
public virtual bool SupportsOperatorAll => true;
public virtual bool SupportsOperatorSome => true;
public virtual bool SupportsLocate => true;
public virtual bool SupportsFullJoin => true;
/// <summary>
/// Does the dialect lack a true handling of decimal?
/// </summary>
public virtual bool HasBrokenDecimalType => false;
public virtual bool SupportsNullCharactersInUtfStrings => true;
/// <summary>
/// Some databases do not support SELECT FOR UPDATE
/// </summary>
public virtual bool SupportsSelectForUpdate => true;
/// <summary>
/// Some databases do not support SELECT FOR UPDATE with paging
/// </summary>
public virtual bool SupportsSelectForUpdateWithPaging => SupportsSelectForUpdate;
/// <summary>
/// Some databases do not support SELECT FOR UPDATE in conjunction with outer joins
/// </summary>
public virtual bool SupportsSelectForUpdateOnOuterJoin => SupportsSelectForUpdate;
public virtual bool SupportsHavingWithoutGroupBy => true;
public virtual bool SupportsComplexExpressionInGroupBy => true;
public virtual bool SupportsCountDistinct => true;
public virtual bool SupportsOrderByAggregate => true;
public virtual bool SupportsOrderByColumnNumber => true;
public virtual bool SupportsDuplicatedColumnAliases => true;
/// <summary>
/// Supports inserting in a table without any column specified in the insert.
/// </summary>
public virtual bool SupportsEmptyInserts => true;
/// <summary>
/// Either supports inserting in a table without any column specified in the insert, or has a native
/// generator strategy resolving to something else than identity.
/// </summary>
/// <remarks>This property is useful for cases where empty inserts happens only when the entities
/// generator is <c>native</c> while the dialect uses <c>identity</c> for this generator.</remarks>
public bool SupportsEmptyInsertsOrHasNonIdentityNativeGenerator
=> SupportsEmptyInserts || !HasIdentityNativeGenerator;
/// <summary>
/// Supports condition not bound to any data, like "where @p1 = @p2".
/// </summary>
public virtual bool SupportsNonDataBoundCondition => true;
public bool SupportsSqlType(SqlType sqlType)
{
try
{
_dialect.GetTypeName(sqlType);
return true;
}
catch
{
return false;
}
}
/// <summary>
/// Supports the modulo operator on decimal types
/// </summary>
public virtual bool SupportsModuloOnDecimal => true;
/// <summary>
/// Supports aggregating sub-selects in order by clause
/// </summary>
public virtual bool SupportsAggregatingScalarSubSelectsInOrderBy => _dialect.SupportsScalarSubSelects;
/// <summary>
/// Supports order by and limits/top in correlated sub-queries
/// </summary>
public virtual bool SupportsOrderByAndLimitInSubQueries => true;
/// <summary>
/// Supports selecting a double literal.
/// </summary>
public virtual bool SupportsSelectingDoubleLiteral => true;
/// <summary>
/// Supports foreign keys on composite keys including a boolean column.
/// </summary>
public virtual bool SupportsFKOnCompositeKeyWithBoolean => true;
/// <summary>
/// Supports tests involving concurrency.
/// </summary>
public virtual bool SupportsConcurrencyTests => true;
/// <summary>
/// Supports batching together inserts/updates/Delets among which some depends (auto foreign key) on others
/// in the batch.
/// </summary>
public virtual bool SupportsBatchingDependentDML => true;
/// <summary>
/// Some test editions of databases may have a simultaneous connections limits.
/// </summary>
public virtual int? MaxNumberOfConnections => null;
/// <summary>
/// Even quoted, some databases do not support square bracket in identifiers.
/// </summary>
public virtual bool SupportsSquareBracketInIdentifiers => true;
/// <summary>
/// Some databases fail when a connection is enlisted during the first phase of a two phase commit.
/// </summary>
public virtual bool SupportsUsingConnectionOnSystemTransactionPrepare => true;
/// <summary>
/// Some databases (provider?) fails to compute adequate column types for queries which columns
/// computing include a parameter value.
/// </summary>
/// <remarks>
/// This property is not set to true for Firebird although it seems to be affected too. But its driver
/// currently has a hack for casting all parameters in select and where clauses in order to explicit
/// their type in the query.
/// </remarks>
public virtual bool HasBrokenTypeInferenceOnSelectedParameters => false;
}
}