源代码改用vs默认格式化

This commit is contained in:
28810
2019-06-27 09:40:35 +08:00
parent 873364c7ee
commit f8c3608fda
309 changed files with 73814 additions and 67594 deletions

View File

@ -2,12 +2,14 @@
using System.Data;
using System.Data.Common;
namespace FreeSql {
public interface IUnitOfWork : IDisposable {
namespace FreeSql
{
public interface IUnitOfWork : IDisposable
{
DbTransaction GetOrBeginTransaction(bool isCreate = true);
DbTransaction GetOrBeginTransaction(bool isCreate = true);
IsolationLevel? IsolationLevel { get; set; }
IsolationLevel? IsolationLevel { get; set; }
/// <summary>
/// 是否启用工作单元
@ -16,7 +18,7 @@ namespace FreeSql {
void Commit();
void Rollback();
void Rollback();
/// <summary>
/// 禁用工作单元

View File

@ -3,22 +3,26 @@ using System;
using System.Data;
using System.Data.Common;
namespace FreeSql {
class UnitOfWork : IUnitOfWork {
namespace FreeSql
{
class UnitOfWork : IUnitOfWork
{
protected IFreeSql _fsql;
protected Object<DbConnection> _conn;
protected DbTransaction _tran;
protected IFreeSql _fsql;
protected Object<DbConnection> _conn;
protected DbTransaction _tran;
public UnitOfWork(IFreeSql fsql) {
_fsql = fsql;
}
public UnitOfWork(IFreeSql fsql)
{
_fsql = fsql;
}
void ReturnObject() {
_fsql.Ado.MasterPool.Return(_conn);
_tran = null;
_conn = null;
}
void ReturnObject()
{
_fsql.Ado.MasterPool.Return(_conn);
_tran = null;
_conn = null;
}
/// <summary>
@ -49,55 +53,74 @@ namespace FreeSql {
public IsolationLevel? IsolationLevel { get; set; }
public DbTransaction GetOrBeginTransaction(bool isCreate = true) {
public DbTransaction GetOrBeginTransaction(bool isCreate = true)
{
if (_tran != null) return _tran;
if (isCreate == false) return null;
if (_tran != null) return _tran;
if (isCreate == false) return null;
if (!Enable) return null;
if (_conn != null) _fsql.Ado.MasterPool.Return(_conn);
if (_conn != null) _fsql.Ado.MasterPool.Return(_conn);
_conn = _fsql.Ado.MasterPool.Get();
try {
_tran = IsolationLevel == null ?
_conn.Value.BeginTransaction() :
_conn.Value.BeginTransaction(IsolationLevel.Value);
} catch {
ReturnObject();
throw;
}
return _tran;
}
_conn = _fsql.Ado.MasterPool.Get();
try
{
_tran = IsolationLevel == null ?
_conn.Value.BeginTransaction() :
_conn.Value.BeginTransaction(IsolationLevel.Value);
}
catch
{
ReturnObject();
throw;
}
return _tran;
}
public void Commit() {
if (_tran != null) {
try {
_tran.Commit();
} finally {
ReturnObject();
}
}
}
public void Rollback() {
if (_tran != null) {
try {
_tran.Rollback();
} finally {
ReturnObject();
}
}
}
~UnitOfWork() {
this.Dispose();
}
bool _isdisposed = false;
public void Dispose() {
if (_isdisposed) return;
try {
this.Rollback();
} finally {
_isdisposed = true;
GC.SuppressFinalize(this);
}
}
}
public void Commit()
{
if (_tran != null)
{
try
{
_tran.Commit();
}
finally
{
ReturnObject();
}
}
}
public void Rollback()
{
if (_tran != null)
{
try
{
_tran.Rollback();
}
finally
{
ReturnObject();
}
}
}
~UnitOfWork()
{
this.Dispose();
}
bool _isdisposed = false;
public void Dispose()
{
if (_isdisposed) return;
try
{
this.Rollback();
}
finally
{
_isdisposed = true;
GC.SuppressFinalize(this);
}
}
}
}