Skip to content

Commit

Permalink
281:修正MemCache的Set方法的时间(因为时间毫秒,修正为分钟)(2016-07-10)
Browse files Browse the repository at this point in the history
282:增加智能缓存功能:默认开启,可从(AppConfig.Cache.IsAutoCache配置开关)(PS:本次代码改动较多)(2016-07-10)
283:DBTool取消两个获取系统内部缓存Key的方法,移到CacheManage类下(并增加AutoCache的Key的获取)(2016-07-10)
284:处理MySql批量插入时GUID为空赋值的情况(2016-07-10)
285: 处理MSSQL的Timestamp字段不允许更新的问题(2016-07-10)
  • Loading branch information
cyq1162 committed Jul 10, 2016
1 parent 4a7f43d commit 397f8d5
Show file tree
Hide file tree
Showing 26 changed files with 1,286 additions and 305 deletions.
25 changes: 24 additions & 1 deletion Action/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace CYQ.Data
public static class AppConfig
{
#region 基方法
private static MDictionary<string, string> configs = new MDictionary<string, string>();
private static MDictionary<string, string> configs = new MDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
/// <summary>
/// 设置Web.config或App.config的值。
/// </summary>
Expand Down Expand Up @@ -591,6 +591,29 @@ public static int DefaultCacheTime
SetApp("DefaultCacheTime", value.ToString());
}
}

private static int _IsAutoCache= -1;
/// <summary>
/// 是否智能缓存数据(默认开启)
/// </summary>
public static bool IsAutoCache
{
get
{
if (_IsAutoCache == -1)
{
_IsAutoCache = AppConfig.GetApp("IsAutoCache").ToLower() == "false" ? 0 : 1;//默认开启

}
return _IsAutoCache == 1;
}
set
{
_IsAutoCache = value ? 1 : 0;
}
}


/*
/// <summary>
/// Cache.CacheManage 内置线程-缓存的同步时间[(默认5)分钟同步一次]
Expand Down
8 changes: 4 additions & 4 deletions Action/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ internal static class Error
/// <param name="msg"></param>
internal static object Throw(string msg)
{
//#if DEBUG
// return "";
//#else
#if DEBUG
return "";
#else
throw new Exception("V" + AppConfig.Version + " " + msg);
//#endif
#endif
}
}
/// <summary>
Expand Down
281 changes: 147 additions & 134 deletions Action/MAction.cs

Large diffs are not rendered by default.

162 changes: 97 additions & 65 deletions Action/MProc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public static implicit operator MProc(MAction action)

internal DbBase dalHelper;
private NoSqlCommand _noSqlCommand;
private Aop.IAop _aop = Aop.Aop.Instance;//切入点
private AopInfo _aopInfo = new AopInfo();
private InterAop _aop = new InterAop();
// private AopInfo _aopInfo = new AopInfo();
private string _procName = string.Empty;
private bool _isProc = true;
private string _debugInfo = string.Empty;
Expand Down Expand Up @@ -216,11 +216,11 @@ private void SetDbBase(DbBase dbBase)
_noSqlCommand = new NoSqlCommand(_procName, dalHelper);
break;
}
Aop.IAop myAop = Aop.Aop.Instance.GetFromConfig();//试图从配置文件加载自定义Aop
if (myAop != null)
{
SetAop(myAop);
}
//Aop.IAop myAop = Aop.InterAop.Instance.GetFromConfig();//试图从配置文件加载自定义Aop
//if (myAop != null)
//{
// SetAop(myAop);
//}
}
/// <summary>
/// 表切存储过程,在操作完A存储过程后,如果需要操作B存储过程,不需要重新new一个MProc,可直接换用本函数切换
Expand Down Expand Up @@ -254,15 +254,14 @@ public void ResetProc(object procNameOrSql)
}
private AopResult SetAopResult(AopEnum action)
{
if (_aopInfo.IsCustomAop)
if (_aop.IsCustomAop)
{
_aopInfo.MProc = this;
_aopInfo.ProcName = _procName;
_aopInfo.IsProc = _isProc;
_aopInfo.DBParameters = dalHelper.Com.Parameters;
//_aopInfo.AopPara = aopPara;
_aopInfo.IsTransaction = dalHelper.isOpenTrans;
return _aop.Begin(action, _aopInfo);
_aop.Para.MProc = this;
_aop.Para.ProcName = _procName;
_aop.Para.IsProc = _isProc;
_aop.Para.DBParameters = dalHelper.Com.Parameters;
_aop.Para.IsTransaction = dalHelper.isOpenTrans;
return _aop.Begin(action);
}
return AopResult.Default;
}
Expand All @@ -276,7 +275,7 @@ public MDataTable ExeMDataTable()
AopResult aopResult = SetAopResult(AopEnum.ExeMDataTable);
if (aopResult == AopResult.Return)
{
return _aopInfo.Table;
return _aop.Para.Table;
}
else
{
Expand All @@ -286,21 +285,21 @@ public MDataTable ExeMDataTable()
{
case DalType.Txt:
case DalType.Xml:
_aopInfo.Table = _noSqlCommand.ExeMDataTable();
_aop.Para.Table = _noSqlCommand.ExeMDataTable();
break;
default:
_aopInfo.Table = dalHelper.ExeDataReader(_procName, _isProc);
_aopInfo.Table.Columns.dalType = DalType;
// dalHelper.ResetConn();//重置Slave
_aop.Para.Table = dalHelper.ExeDataReader(_procName, _isProc);
_aop.Para.Table.Columns.dalType = DalType;
// dalHelper.ResetConn();//重置Slave
break;
}
_aopInfo.Table.Conn = _conn;
_aop.Para.Table.Conn = _conn;
}
if (aopResult != AopResult.Default)
{
_aop.End(AopEnum.ExeMDataTable, _aopInfo);
_aop.End(AopEnum.ExeMDataTable);
}
return _aopInfo.Table;
return _aop.Para.Table;
}
}

Expand All @@ -311,21 +310,50 @@ public MDataTable ExeMDataTable()
public List<MDataTable> ExeMDataTableList()
{
CheckDisposed();
DbDataReader reader = dalHelper.ExeDataReader(_procName, _isProc);
List<MDataTable> dtList = new List<MDataTable>();
if (reader != null)
AopResult aopResult = SetAopResult(AopEnum.ExeMDataTableList);
if (aopResult == AopResult.Return)
{
return _aop.Para.TableList;
}
else
{
do
if (aopResult != AopResult.Break)
{
List<MDataTable> dtList = new List<MDataTable>();
switch (dalHelper.dalType)
{
case DalType.Txt:
case DalType.Xml:
foreach (string sql in _procName.Split(';'))
{
_noSqlCommand.CommandText = sql;
dtList.Add(_noSqlCommand.ExeMDataTable());
}
break;
default:
DbDataReader reader = dalHelper.ExeDataReader(_procName, _isProc);

if (reader != null)
{
do
{
dtList.Add(MDataTable.CreateFrom(reader));
}
while (reader.NextResult());
reader.Close();
reader.Dispose();
reader = null;
}
break;
}
_aop.Para.TableList = dtList;
}
if (aopResult != AopResult.Default)
{
dtList.Add(MDataTable.CreateFrom(reader));
_aop.End(AopEnum.ExeMDataTableList);
}
while (reader.NextResult());
reader.Close();
reader.Dispose();
reader = null;
return _aop.Para.TableList;
}
//dalHelper.ResetConn();//重置Slave
return dtList;
}

/// <summary>
Expand All @@ -338,7 +366,7 @@ public int ExeNonQuery()
AopResult aopResult = SetAopResult(AopEnum.ExeNonQuery);
if (aopResult == AopResult.Return)
{
return _aopInfo.RowCount;
return _aop.Para.RowCount;
}
else
{
Expand All @@ -348,18 +376,18 @@ public int ExeNonQuery()
{
case DalType.Txt:
case DalType.Xml:
_aopInfo.RowCount = _noSqlCommand.ExeNonQuery();
_aop.Para.RowCount = _noSqlCommand.ExeNonQuery();
break;
default:
_aopInfo.RowCount = dalHelper.ExeNonQuery(_procName, _isProc);
_aop.Para.RowCount = dalHelper.ExeNonQuery(_procName, _isProc);
break;
}
}
if (aopResult != AopResult.Default)
{
_aop.End(AopEnum.ExeNonQuery, _aopInfo);
_aop.End(AopEnum.ExeNonQuery);
}
return _aopInfo.RowCount;
return _aop.Para.RowCount;
}
}
/// <summary>
Expand All @@ -375,23 +403,23 @@ public T ExeScalar<T>()
{
case DalType.Txt:
case DalType.Xml:
_aopInfo.ExeResult = _noSqlCommand.ExeScalar();
_aop.Para.ExeResult = _noSqlCommand.ExeScalar();
break;
default:
_aopInfo.ExeResult = dalHelper.ExeScalar(_procName, _isProc);
_aop.Para.ExeResult = dalHelper.ExeScalar(_procName, _isProc);
break;
}
}
if (aopResult == AopResult.Continue || aopResult == AopResult.Break)
{
_aop.End(AopEnum.ExeScalar, _aopInfo);
_aop.End(AopEnum.ExeScalar);
}
if (_aopInfo.ExeResult == null || _aopInfo.ExeResult == DBNull.Value)
if (_aop.Para.ExeResult == null || _aop.Para.ExeResult == DBNull.Value)
{
return default(T);
}
Type t = typeof(T);
object value = _aopInfo.ExeResult;
object value = _aop.Para.ExeResult;
switch (t.Name)
{
case "Int32":
Expand Down Expand Up @@ -470,7 +498,7 @@ public MProc SetCustom(object paraName, ParaType paraType, object value)
/// </summary>
public void Clear()
{
dalHelper.ClearParameters();
dalHelper.ClearParameters();
}
/// <summary>
/// 存储过程的返回值
Expand Down Expand Up @@ -499,46 +527,50 @@ public object OutPutValue
/// <summary>
/// 临时备份Aop,用于切换后的还原。
/// </summary>
Aop.IAop _aopBak = null;
// Aop.IAop _aopBak = null;

/// <summary>
/// 取消AOP
/// </summary>
public MProc SetAopOff()
{
if (_aopInfo.IsCustomAop)
{
_aopBak = _aop;//设置好备份。
_aop = Aop.Aop.Instance;
_aopInfo.IsCustomAop = false;
} return this;
_aop.IsCustomAop = false;
//if (_aopInfo.IsCustomAop)
//{
// _aopBak = _aop;//设置好备份。
// _aop = Aop.InterAop.Instance;
// _aopInfo.IsCustomAop = false;
//}
return this;
}
/// <summary>
/// 恢复默认配置的Aop。
/// </summary>
public MProc SetAopOn()
{
if (!_aopInfo.IsCustomAop)
{
SetAop(_aopBak);
} return this;
_aop.IsCustomAop = true;
//if (!_aopInfo.IsCustomAop)
//{
// SetAop(_aopBak);
//}
return this;
}
/// <summary>
/// 设置Aop对象。
/// </summary>
private MProc SetAop(Aop.IAop aop)
{
_aop = aop;
_aopInfo.IsCustomAop = true;
return this;
}
//private MProc SetAop(Aop.IAop aop)
//{
// _aop = aop;
// _aopInfo.IsCustomAop = true;
// return this;
//}
/// <summary>
/// 需要传递额外的参数供Aop使用时可设置。
/// </summary>
/// <param name="para"></param>
public MProc SetAopPara(object para)
{
_aopInfo.AopPara = para; return this;
_aop.Para.AopPara = para; return this;
}

void helper_OnExceptionEvent(string errorMsg)
Expand All @@ -564,7 +596,7 @@ public MProc SetTransLevel(IsolationLevel level)
/// </summary>
public void BeginTransation()
{
dalHelper.isOpenTrans = true;
dalHelper.isOpenTrans = true;
}
/// <summary>
/// 提交结束事务[默认调用Close/Disponse时会自动调用]
Expand All @@ -585,7 +617,7 @@ public bool RollBack()
{
if (dalHelper != null && dalHelper.isOpenTrans)
{
return dalHelper.RollBack();
return dalHelper.RollBack();
}
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions Action/NoSqlAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ internal static void ResetStaticVar()
/// <summary>
/// 是否需要更新:0未更新;1仅插入[往后面插数据];2更新删除或插入[重新保存]
/// </summary>
private static MDictionary<string, int> _needToSaveState = new MDictionary<string, int>();//需要更新[全局的可以有效处理并发]
private static MDictionary<string, object> _lockNextIDObj = new MDictionary<string, object>();//自增加ID锁
private static MDictionary<string, object> _lockWriteTxtObj = new MDictionary<string, object>();//文件写入锁
private static MDictionary<string, int> _maxID = new MDictionary<string, int>();//当前表的最大ID
private static MDictionary<string, int> _needToSaveState = new MDictionary<string, int>(StringComparer.OrdinalIgnoreCase);//需要更新[全局的可以有效处理并发]
private static MDictionary<string, object> _lockNextIDObj = new MDictionary<string, object>(StringComparer.OrdinalIgnoreCase);//自增加ID锁
private static MDictionary<string, object> _lockWriteTxtObj = new MDictionary<string, object>(StringComparer.OrdinalIgnoreCase);//文件写入锁
private static MDictionary<string, int> _maxID = new MDictionary<string, int>(StringComparer.OrdinalIgnoreCase);//当前表的最大ID
private List<MDataRow> _insertRows = new List<MDataRow>();//新插入的集合,仅是引用MDataTable的索引
/// <summary>
/// 最后的写入时间
Expand Down
4 changes: 4 additions & 0 deletions Aop/AopEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public enum AopEnum
/// </summary>
GetCount,
/// <summary>
/// MProc查询返回List<MDataTable>方法 [参数为顺序为:AopEnum.ExeMDataTableList, out result, procName, isProc, DbParameterCollection, aopInfo]
/// </summary>
ExeMDataTableList,
/// <summary>
/// MProc查询返回MDataTable方法 [参数为顺序为:AopEnum.ExeMDataTable, out result, procName, isProc, DbParameterCollection, aopInfo]
/// </summary>
ExeMDataTable,
Expand Down
Loading

0 comments on commit 397f8d5

Please sign in to comment.