Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit fdd1129

Browse files
committed
Merge pull request #381 from BruceCowan-AI/FixOracleThreadingIssue
Fix dumb threading issue and dumb usage of OracleExecFilter other places...
2 parents 16728b6 + 369dd8e commit fdd1129

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/ServiceStack.OrmLite.Oracle/OracleExecFilter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System;
2-
using System.Collections.Generic;
2+
using System.Collections.Concurrent;
33
using System.Data;
44
using System.Reflection;
55
using System.Reflection.Emit;
@@ -18,7 +18,7 @@ public override IDbCommand CreateCommand(IDbConnection dbConn)
1818
return command;
1919
}
2020

21-
private static readonly Dictionary<Type, Action<IDbCommand, bool>> Cache = new Dictionary<Type, Action<IDbCommand, bool>>();
21+
private static readonly ConcurrentDictionary<Type, Action<IDbCommand, bool>> Cache = new ConcurrentDictionary<Type, Action<IDbCommand, bool>>();
2222
private static Action<IDbCommand, bool> GetBindByNameSetter(Type commandType)
2323
{
2424
if (commandType == null) return null;
@@ -41,7 +41,7 @@ private static Action<IDbCommand, bool> GetBindByNameSetter(Type commandType)
4141
il.Emit(OpCodes.Ret);
4242
action = (Action<IDbCommand, bool>)method.CreateDelegate(typeof(Action<IDbCommand, bool>));
4343
}
44-
Cache.Add(commandType, action);
44+
Cache.TryAdd(commandType, action);
4545
return action;
4646
}
4747

src/ServiceStack.OrmLite.Oracle/OracleOrmLiteDialectProvider.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ public class OracleOrmLiteDialectProvider : OrmLiteDialectProviderBase<OracleOrm
3131
protected const int MaxNameLength = 30;
3232
protected const int MaxStringColumnLength = 4000;
3333

34-
public static OracleOrmLiteDialectProvider Instance = new OracleOrmLiteDialectProvider();
34+
private static OracleOrmLiteDialectProvider _instance;
35+
public static OracleOrmLiteDialectProvider Instance
36+
{
37+
// Constructing extras if we happen to hit this concurrently on separate threads is harmless enough
38+
get { return _instance ?? (_instance = new OracleOrmLiteDialectProvider()); }
39+
}
3540

3641
internal long LastInsertId { get; set; }
3742
protected bool CompactGuid;
@@ -67,6 +72,8 @@ public OracleOrmLiteDialectProvider(bool compactGuid, bool quoteNames, string cl
6772
ParamString = ":";
6873

6974
NamingStrategy = new OracleNamingStrategy(MaxNameLength);
75+
// Beware, this is setting a static filter which can get used by other providers if multiple concurrent different
76+
// providers. That should be harmless as the filter will no-op fairly cheaply for non-Oracle situations.
7077
OrmLiteConfig.ExecFilter = new OracleExecFilter();
7178
}
7279

0 commit comments

Comments
 (0)