SPRNET-1522 added cache key prefix for SimpleDelegatingSessionFactory cache access
This commit is contained in:
@@ -23,6 +23,11 @@ namespace Spring.Data.NHibernate
|
||||
/// </summary>
|
||||
public const string CONNECTION_STRING = "SimpleDelegatingSessionFactory.ConnectionString";
|
||||
|
||||
/// <summary>
|
||||
/// Cache region prefix config element name
|
||||
/// </summary>
|
||||
public const string CACHE_REGION_PREFIX_STRING = "SimpleDelegatingSessionFactory.CacheRegionPrefix";
|
||||
|
||||
private Configuration _configuration;
|
||||
|
||||
private string _defaultConnectionString;
|
||||
@@ -66,7 +71,7 @@ namespace Spring.Data.NHibernate
|
||||
string connectionString = LogicalThreadContext.GetData(CONNECTION_STRING) as string;
|
||||
|
||||
System.Diagnostics.Trace.WriteLine(String.Format("{0} = {1}", System.Threading.Thread.CurrentThread.GetHashCode(), connectionString));
|
||||
|
||||
|
||||
if (connectionString == null)
|
||||
{
|
||||
connectionString = _defaultConnectionString;
|
||||
@@ -78,6 +83,22 @@ namespace Spring.Data.NHibernate
|
||||
{
|
||||
System.Diagnostics.Trace.WriteLine(System.Threading.Thread.CurrentThread.GetHashCode().ToString() + " = (created) ");
|
||||
|
||||
string originalPrefix = string.Empty;
|
||||
|
||||
if (_configuration.Properties.ContainsKey(NhCfg.Environment.CacheRegionPrefix))
|
||||
{
|
||||
originalPrefix = _configuration.Properties[NhCfg.Environment.CacheRegionPrefix];
|
||||
}
|
||||
|
||||
string cacheRegionPrefix = LogicalThreadContext.GetData(CACHE_REGION_PREFIX_STRING) as string;
|
||||
|
||||
if (!string.IsNullOrEmpty(cacheRegionPrefix))
|
||||
{
|
||||
_configuration.Properties[NhCfg.Environment.CacheRegionPrefix] = originalPrefix + cacheRegionPrefix;
|
||||
System.Diagnostics.Trace.WriteLine(String.Format("{0} = (cache region prefix) {1}", System.Threading.Thread.CurrentThread.GetHashCode(), cacheRegionPrefix));
|
||||
|
||||
}
|
||||
|
||||
_configuration.Properties[NhCfg.Environment.ConnectionString] = connectionString;
|
||||
ISessionFactory sessionFactory = _configuration.BuildSessionFactory();
|
||||
|
||||
@@ -87,6 +108,10 @@ namespace Spring.Data.NHibernate
|
||||
dbProviderWrapper.DbProvider = (IDbProvider)ContextRegistry.GetContext().GetObject("DbProvider");
|
||||
}
|
||||
|
||||
//Reset the Cache Region Prefix to the original value
|
||||
// This is so other cache region prefixes are not appended together.
|
||||
_configuration.Properties[NhCfg.Environment.CacheRegionPrefix] = originalPrefix;
|
||||
|
||||
_targetSessionFactories[connectionString] = sessionFactory;
|
||||
}
|
||||
else
|
||||
@@ -95,7 +120,7 @@ namespace Spring.Data.NHibernate
|
||||
ISessionFactory factory = _targetSessionFactories[connectionString] as ISessionFactory;
|
||||
|
||||
System.Diagnostics.Trace.WriteLine(String.Format("{0} = {1}", System.Threading.Thread.CurrentThread.GetHashCode(), connectionString));
|
||||
|
||||
|
||||
return factory;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user