Skip to content

Commit

Permalink
367:SqlCreate处理Oracle日期条件的转换问题。(2016-09-13)
Browse files Browse the repository at this point in the history
368:SqlCreate增加对GUID类型的检测(2016-09-20)
369:OrmBase、SimpleOrmBase延迟加载初始化(2016-09-20)
370:MAction在Insert时,对Oracle,Mysql等放置(获取最大值)事务(2016-09-20)
371:MAction在Insert时的InsertOp默认选项变更为:ID,原来为(Fill)(2016-09-20)
372:JsonHelper.ToJson增加对List<MDataTable>和List<DataTable>的支持(2016-09-20)
  • Loading branch information
cyq1162 committed Sep 20, 2016
1 parent c1a3ea9 commit ea331c1
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 114 deletions.
4 changes: 2 additions & 2 deletions Action/ActionEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public enum InsertOp
/// </summary>
None,
/// <summary>
/// 使用此项:插入数据后会返回ID。
/// 使用此项:插入数据后会返回ID[默认选项]
/// </summary>
ID,
/// <summary>
/// 使用此项:插入数据后,会根据返回ID进行查询后填充数据行,[默认选项]
/// 使用此项:插入数据后,会根据返回ID进行查询后填充数据行
/// </summary>
Fill,
}
Expand Down
22 changes: 17 additions & 5 deletions Action/MAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public partial class MAction : IDisposable



private InsertOp _option = InsertOp.Fill;
private InsertOp _option = InsertOp.ID;

private NoSqlAction _noSqlAction = null;
private MDataRow _Data;//表示一行
Expand Down Expand Up @@ -512,10 +512,18 @@ private bool InsertOrUpdate(string sqlCommandText)
}
break;
default:
ID = dalHelper.ExeNonQuery(sqlCommandText, false);
if (ID != null && Convert.ToInt32(ID) > 0 && _option != InsertOp.None)
bool isTrans = dalHelper.isOpenTrans;
int groupID = DataType.GetGroup(_Data.PrimaryCell.Struct.SqlType);
bool isNum = groupID == 1 && _Data.PrimaryCell.Struct.Scale <= 0;
if (!isTrans && (isNum || _Data.PrimaryCell.Struct.IsAutoIncrement)) // 数字自增加
{
if (DataType.GetGroup(_Data.PrimaryCell.Struct.SqlType) == 1)
dalHelper.isOpenTrans = true;//开启事务。
dalHelper.tranLevel = IsolationLevel.ReadCommitted;//默认事务级别已是这个,还是设置一下,避免外部调整对此的影响。
}
ID = dalHelper.ExeNonQuery(sqlCommandText, false);//返回的是受影响的行数
if (_option != InsertOp.None && ID != null && Convert.ToInt32(ID) > 0)
{
if (isNum)
{
ClearParameters();
ID = dalHelper.ExeScalar(_sqlCreate.GetMaxID(), false);
Expand All @@ -527,6 +535,10 @@ private bool InsertOrUpdate(string sqlCommandText)
}

}
if (!isTrans)
{
dalHelper.EndTransaction();
}
break;
}
if ((ID != null && Convert.ToString(ID) != "-2") || (dalHelper.recordsAffected > -2 && _option == InsertOp.None))
Expand Down Expand Up @@ -1435,7 +1447,7 @@ public bool RollBack()
#region IDisposable 成员
public void Dispose()
{
Dispose(false);
Dispose(false);
}
/// <summary>
/// 释放资源
Expand Down
8 changes: 8 additions & 0 deletions Action/NoSqlAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ public void Reset(ref MDataRow row, string fileName, string filePath, DalType da
_FileName = fileName;
_FileFullName = filePath + _FileName;
_DalType = dalType;
_Table = null;
}
public bool Delete(object where)
{
Expand Down Expand Up @@ -327,6 +328,9 @@ public bool Insert(bool isOpenTrans)
case 4:
cell.Value = Guid.NewGuid();
break;
case 0:
cell.Value = Guid.NewGuid().ToString();
break;
default:
return (bool)Error.Throw("first column value can't be null");
}
Expand Down Expand Up @@ -440,6 +444,10 @@ private bool IsCanDoInsertCheck(int start)
Error.Throw("Column [" + _Row[i].ColumnName + "] 's value can't be null or empty ! (tip:column property:iscannull=false)");
}
}
if (!isCanDo && start == 1) // 允许插入空的主键(非自增)。
{
return !_Row[0].IsNullOrEmpty && _Row[0].Struct.IsPrimaryKey && !_Row[0].Struct.IsAutoIncrement;
}
return isCanDo;
}
#endregion
Expand Down
54 changes: 29 additions & 25 deletions DAL/OracleDal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ protected override DbProviderFactory GetFactory(string providerName)
return base.GetFactory(providerName);
}
}
/// <summary>
/// 值-1未初始化;0使用OracleClient;1使用DataAccess;2使用ManagedDataAccess
/// </summary>
internal static int isUseOdpNet = -1;
private static readonly object lockObj = new object();
/// <summary>
/// 是否使用Oracle的ODP.NET组件。
/// </summary>
Expand All @@ -180,35 +184,35 @@ private bool IsUseOdpNet
{
if (isUseOdpNet == -1)
{
string path = string.Empty;
try
{
Assembly ass = System.Reflection.Assembly.GetExecutingAssembly();
path = System.IO.Path.GetDirectoryName(ass.CodeBase).Replace(AppConst.FilePre, string.Empty);
ass = null;
}
catch
{

}
if (System.IO.File.Exists(path + "\\Oracle.DataAccess.dll")) ////Oracle 11
lock (lockObj)
{
ManagedName = "";
isUseOdpNet = 1;
}
else if (System.IO.File.Exists(path + "\\Oracle." + ManagedName + "DataAccess.dll"))//Oracle 12
{
if (AppConfig.GetConn(base.conn).IndexOf("host", StringComparison.OrdinalIgnoreCase) == -1)
if (isUseOdpNet == -1)
{
Error.Throw("you need to use the connectionString like this : Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT = 1521)))(CONNECT_DATA =(SID = orcl)));User ID=sa;password=123456");
if (AppConfig.GetConn(base.conn).IndexOf("host", StringComparison.OrdinalIgnoreCase) == -1)
{
isUseOdpNet = 0;
}
else
{
Assembly ass = System.Reflection.Assembly.GetExecutingAssembly();
string path = System.IO.Path.GetDirectoryName(ass.CodeBase).Replace(AppConst.FilePre, string.Empty);
ass = null;
if (System.IO.File.Exists(path + "\\Oracle.DataAccess.dll")) ////Oracle 11
{
ManagedName = "";
isUseOdpNet = 1;
}
else if (System.IO.File.Exists(path + "\\Oracle." + ManagedName + "DataAccess.dll"))//Oracle 12
{
isUseOdpNet = 2;
}
else
{
isUseOdpNet = 0;
}
}
}
isUseOdpNet = 2;
}
else
{
isUseOdpNet = 0;
}

}
return isUseOdpNet > 0;
}
Expand Down
71 changes: 44 additions & 27 deletions Orm/SimpleOrmBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal bool AllowWriteLog
{
set
{
action.dalHelper.isAllowInterWriteLog = value;
Action.dalHelper.isAllowInterWriteLog = value;
}
}
/// <summary>
Expand All @@ -69,12 +69,16 @@ public static FieldSource FieldSource

Object entity;//实体对象
Type typeInfo;//实体对象类型
MAction action;
private MAction _Action;
internal MAction Action
{
get
{
return action;
if (_Action == null)
{
SetDelayInit(_entityInstance, _tableName, _conn, _op);//延迟加载
}
return _Action;
}
}
/// <summary>
Expand All @@ -90,7 +94,7 @@ public SimpleOrmBase()
/// <param name="op"></param>
public void SetAopState(AopOp op)
{
action.SetAopState(op);
Action.SetAopState(op);
}
/// <summary>
/// 初始化状态[继承此基类的实体在构造函数中需调用此方法]
Expand Down Expand Up @@ -119,8 +123,21 @@ protected void SetInit(Object entityInstance, string tableName, string conn)
{
SetInit(entityInstance, tableName, conn, AopOp.OpenAll);
}

private object _entityInstance;
private string _tableName;
private string _conn;
private AopOp _op;
protected void SetInit(Object entityInstance, string tableName, string conn, AopOp op)
{
_entityInstance = entityInstance;
_tableName = tableName;
_conn = conn;
_op = op;
}
/// <summary>
/// 将原有的初始化改造成延时加载。
/// </summary>
private void SetDelayInit(Object entityInstance, string tableName, string conn, AopOp op)
{
conn = string.IsNullOrEmpty(conn) ? AppConfig.DB.DefaultConn : conn;
entity = entityInstance;
Expand Down Expand Up @@ -184,16 +201,16 @@ protected void SetInit(Object entityInstance, string tableName, string conn, Aop
Columns = CacheManage.LocalInstance.Get(key) as MDataColumn;
}

action = new MAction(Columns.ToRow(tableName), conn);
_Action = new MAction(Columns.ToRow(tableName), conn);
if (typeInfo.Name == "SysLogs")
{
action.SetAopState(Aop.AopOp.CloseAll);
_Action.SetAopState(Aop.AopOp.CloseAll);
}
else
{
action.SetAopState(op);
_Action.SetAopState(op);
}
action.EndTransation();
_Action.EndTransation();
}
catch (Exception err)
{
Expand All @@ -214,9 +231,9 @@ internal void SetInit2(Object entityInstance, string tableName, string conn)
}
internal void Set(object key, object value)
{
if (action != null)
if (Action != null)
{
action.Set(key, value);
Action.Set(key, value);
}
}
#region 基础增删改查 成员
Expand Down Expand Up @@ -268,11 +285,11 @@ internal bool Insert(bool autoSetValue, InsertOp option, bool insertID)
{
if (autoSetValue)
{
action.UI.GetAll(!insertID);
Action.UI.GetAll(!insertID);
}
GetValueFromEntity();
action.AllowInsertID = insertID;
bool result = action.Insert(false, option);
Action.AllowInsertID = insertID;
bool result = Action.Insert(false, option);
if (autoSetValue || option != InsertOp.None)
{
SetValueToEntity();
Expand Down Expand Up @@ -306,10 +323,10 @@ internal bool Update(object where, bool autoSetValue)
{
if (autoSetValue)
{
action.UI.GetAll(false);
Action.UI.GetAll(false);
}
GetValueFromEntity();
bool result = action.Update(where);
bool result = Action.Update(where);
if (autoSetValue)
{
SetValueToEntity();
Expand All @@ -333,7 +350,7 @@ public bool Delete()
public bool Delete(object where)
{
GetValueFromEntity();
return action.Delete(where);
return Action.Delete(where);
}
#endregion

Expand All @@ -351,7 +368,7 @@ public bool Fill()
/// </summary>
public bool Fill(object where)
{
bool result = action.Fill(where);
bool result = Action.Fill(where);
if (result)
{
SetValueToEntity();
Expand Down Expand Up @@ -407,25 +424,25 @@ public List<T> Select<T>(int pageIndex, int pageSize, string where)
/// <param name="count">返回的记录总数</param>
public List<T> Select<T>(int pageIndex, int pageSize, string where, out int count)
{
return action.Select(pageIndex, pageSize, where, out count).ToList<T>();
return Action.Select(pageIndex, pageSize, where, out count).ToList<T>();
}
internal MDataTable Select(int pageIndex, int pageSize, string where, out int count)
{
return action.Select(pageIndex, pageSize, where, out count);
return Action.Select(pageIndex, pageSize, where, out count);
}
/// <summary>
/// 获取记录总数
/// </summary>
public int GetCount(object where)
{
return action.GetCount(where);
return Action.GetCount(where);
}
/// <summary>
/// 查询是否存在指定的条件的数据
/// </summary>
public bool Exists(object where)
{
return action.Exists(where);
return Action.Exists(where);
}

#endregion
Expand All @@ -442,7 +459,7 @@ internal void SetValueToEntity(string propName)
PropertyInfo pi = typeInfo.GetProperty(propName);
if (pi != null)
{
MDataCell cell = action.Data[propName];
MDataCell cell = Action.Data[propName];
if (cell != null && !cell.IsNull)
{
try
Expand All @@ -459,14 +476,14 @@ internal void SetValueToEntity(string propName)
}
else
{
action.Data.SetToEntity(entity);
Action.Data.SetToEntity(entity);
}
}
private void GetValueFromEntity()
{
if (!IsUseAop)
{
action.Data.LoadFrom(entity, BreakOp.Null);
Action.Data.LoadFrom(entity, BreakOp.Null);
}
}
#region IDisposable 成员
Expand All @@ -475,9 +492,9 @@ private void GetValueFromEntity()
/// </summary>
public void Dispose()
{
if (action != null)
if (Action != null)
{
action.Dispose();
Action.Dispose();
}
}

Expand Down
6 changes: 3 additions & 3 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[assembly: AssemblyTitle("CYQ.Data 数据层(ORM)框架 V5 版本")]
[assembly: AssemblyDescription("论坛:http://www.cyqdata.com/cyqdata")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("秋式软件 (2016-09-12)")]
[assembly: AssemblyCompany("秋式软件 (2016-09-20)")]
[assembly: AssemblyProduct("CYQ.Data 数据层(ORM)框架 V5 版本")]
[assembly: AssemblyCopyright("版权所有 (C) 秋式软件 2010-2020")]
[assembly: AssemblyTrademark("CYQ.Data")]
Expand All @@ -31,5 +31,5 @@
//
// 可以指定所有这些值,也可以使用“修订号”和“内部版本号”的默认值,
// 方法是按如下所示使用“*”:
[assembly: AssemblyVersion("5.6.5.4")]
[assembly: AssemblyFileVersion("5.6.5.4")]
[assembly: AssemblyVersion("5.6.5.5")]
[assembly: AssemblyFileVersion("5.6.5.5")]
Loading

0 comments on commit ea331c1

Please sign in to comment.