Adding a way to configure the isolation level

This commit is contained in:
Sebastien Ros
2013-12-10 18:14:42 -08:00
parent 0890650d78
commit 6758b72938
5 changed files with 68 additions and 2 deletions

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="autofac" type="Autofac.Configuration.SectionHandler, Autofac.Configuration"/>
</configSections>
<autofac defaultAssembly="Orchard.Framework">
<!--
To create tenant specific configurations, copy this file to ~/Congig/Sites.{tenant}.config
where {tenant} is the technical name of the targetted tenant
-->
<components>
<!--
Uncomment to use ReadUncommitted as the default isolation level. Please not that
Sql Server Ce doesn't support ReadUncommitted.
-->
<!--
<component instance-scope="per-lifetime-scope"
type="Orchard.Data.SessionLocator, Orchard.Framework"
service="Orchard.Data.ISessionLocator">
<properties>
<property name="IsolationLevel" value="ReadUncommitted" />
</properties>
</component>
-->
</components>
</autofac>
</configuration>

View File

@@ -209,6 +209,7 @@
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="Config\Sites.config" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="autofac" type="Autofac.Configuration.SectionHandler, Autofac.Configuration"/>
</configSections>
<autofac defaultAssembly="Orchard.Framework">
<!--
To create tenant specific configurations, copy this file to ~/Congig/Sites.{tenant}.config
where {tenant} is the technical name of the targetted tenant
-->
<components>
<!--
Uncomment to use ReadUncommitted as the default isolation level. Please not that
Sql Server Ce doesn't support ReadUncommitted.
-->
<!--
<component instance-scope="per-lifetime-scope"
type="Orchard.Data.SessionLocator, Orchard.Framework"
service="Orchard.Data.ISessionLocator">
<properties>
<property name="IsolationLevel" value="ReadUncommitted" />
</properties>
</component>
-->
</components>
</autofac>
</configuration>

View File

@@ -157,6 +157,7 @@
<Content Include="Config\Host.config" />
</ItemGroup>
<ItemGroup>
<Content Include="Config\Sites.config" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>

View File

@@ -24,9 +24,11 @@ namespace Orchard.Data {
_sessionFactoryHolder = sessionFactoryHolder;
_interceptors = interceptors;
Logger = NullLogger.Instance;
IsolationLevel = IsolationLevel.ReadCommitted;
}
public ILogger Logger { get; set; }
public IsolationLevel IsolationLevel { get; set; }
public ISession For(Type entityType) {
Logger.Debug("Acquiring session for {0}", entityType);
@@ -41,12 +43,12 @@ namespace Orchard.Data {
if (_transaction == null) {
Logger.Debug("Creating transaction on Demand");
_transaction = _session.BeginTransaction(IsolationLevel.ReadCommitted);
_transaction = _session.BeginTransaction(IsolationLevel);
}
}
public void RequireNew() {
RequireNew(IsolationLevel.ReadCommitted);
RequireNew(IsolationLevel);
}
public void RequireNew(IsolationLevel level) {