Skip to content

Commit

Permalink
348:AutoCache的缓存时间,改成DefaultCacheTime配置的时间,(用户可以自己配置自动缓存时间)(2016-08-27)
Browse files Browse the repository at this point in the history
349:MProc的ExeMDataTableList方法增加对Oracle的批量语句的支持(2016-08-27)
350:优化Oracle拿表结构的语句(2016-08-27)
351:MDataTable的Merge方法修正(2016-08-27)
352:ThreadBreak的AddGlobalThread增加重载方法(2016-08-27)
353:CacheManage提供PreLoadDBSchemaToCache方法(2016-08-27)
  • Loading branch information
cyq1162 committed Aug 28, 2016
1 parent 42e1d40 commit 1c95cde
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Action/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace CYQ.Data
/// 常用配置文件项[Web(App).Config]的[appSettings|connectionStrings]项和属性名一致。
/// 除了可以从配置文件配置,也可以直接赋值。
/// </summary>
public static class AppConfig
public static partial class AppConfig
{
#region 基方法
private static MDictionary<string, string> configs = new MDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
Expand Down
29 changes: 23 additions & 6 deletions Action/MProc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public MDataTable ExeMDataTable()
}

/// <summary>
/// 执行的语句有多个结果集返回(库此方法不支持文本数据和AOP)
/// 执行的语句有多个结果集返回
/// </summary>
/// <returns></returns>
public List<MDataTable> ExeMDataTableList()
Expand All @@ -341,15 +341,32 @@ public List<MDataTable> ExeMDataTableList()
{
case DalType.Txt:
case DalType.Xml:
foreach (string sql in _procName.Split(';'))
case DalType.Oracle:
if (_isProc && dalHelper.dalType == DalType.Oracle)
{
_noSqlCommand.CommandText = sql;
dtList.Add(_noSqlCommand.ExeMDataTable());
goto isProc;
}
foreach (string sql in _procName.TrimEnd(';').Split(';'))
{
MDataTable dt = null;
if (dalHelper.dalType == DalType.Oracle)
{
dt = dalHelper.ExeDataReader(sql, false);
}
else
{
_noSqlCommand.CommandText = sql;
dt = _noSqlCommand.ExeMDataTable();
}
if (dt != null)
{
dtList.Add(dt);
}
}
break;
default:
isProc:
DbDataReader reader = dalHelper.ExeDataReader(_procName, _isProc);

if (reader != null)
{
do
Expand Down Expand Up @@ -584,7 +601,7 @@ public MProc SetAopState(AopOp op)
/// <param name="para"></param>
public MProc SetAopPara(object para)
{
_aop.Para.AopPara = para;
_aop.Para.AopPara = para;
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion Cache/AutoCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ internal static void SetCache(AopEnum action, AopInfo aopInfo)//End
{
return;//
}
double cacheTime = Math.Abs(12 - DateTime.Now.Hour) * 60 + DateTime.Now.Second;//缓存中午或到夜里1点
double cacheTime = AppConfig.Cache.DefaultCacheTime;// Math.Abs(12 - DateTime.Now.Hour) * 60 + DateTime.Now.Second;//缓存中午或到夜里1点
if (flag == 1 || aopInfo.PageIndex > 2) // 后面的页数,缓存时间可以短一些
{
cacheTime = 2;//未知道操作何表时,只缓存2分钟(比如存储过程等语句)
Expand Down
50 changes: 50 additions & 0 deletions Cache/CacheManage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,56 @@ public static string GetKey(CacheKeyType ckt, string tableName, string dbName, D
return string.Empty;
}
}
public abstract partial class CacheManage
{
/// <summary>
/// 通过该方法可以预先加载整个数据库的表结构缓存
/// </summary>
public static void PreLoadDBSchemaToCache()
{
PreLoadDBSchemaToCache(AppConfig.DB.DefaultConn, true);
}
private static readonly object obj = new object();
/// <summary>
/// 通过该方法可以预先加载整个数据库的表结构缓存
/// </summary>
/// <param name="conn">指定数据链接</param>
/// <param name="isUseThread">是否开启线程</param>
public static void PreLoadDBSchemaToCache(string conn, bool isUseThread)
{
if (TableSchema.tableCache == null || TableSchema.tableCache.Count == 0)
{
lock (obj)
{
if (TableSchema.tableCache == null || TableSchema.tableCache.Count == 0)
{
if (isUseThread)
{
ThreadBreak.AddGlobalThread(new System.Threading.ParameterizedThreadStart(LoadDBSchemaCache), conn);
}
else
{
LoadDBSchemaCache(conn);
}
}
}
}
}
private static void LoadDBSchemaCache(object connObj)
{
string conn = Convert.ToString(connObj);
Dictionary<string, string> dic = DBTool.GetTables(Convert.ToString(conn));
if (dic != null && dic.Count > 0)
{
DbBase helper = DalCreate.CreateDal(conn);
foreach (string key in dic.Keys)
{
TableSchema.GetColumns(key, ref helper);
}
helper.Dispose();
}
}
}
/// <summary>
/// 支持的Cache类型
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
//
// 可以指定所有这些值,也可以使用“修订号”和“内部版本号”的默认值,
// 方法是按如下所示使用“*”:
[assembly: AssemblyVersion("5.6.4.7")]
[assembly: AssemblyFileVersion("5.6.4.7")]
[assembly: AssemblyVersion("5.6.4.8")]
[assembly: AssemblyFileVersion("5.6.4.8")]
4 changes: 2 additions & 2 deletions SQL/SqlFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public static string GetIFieldSql(object whereObj)
/// <returns></returns>
public static string FormatDefaultValue(DalType dalType, object value, int flag, SqlDbType sqlDbType)
{
string defaultValue = Convert.ToString(value).TrimEnd('\n');//oracle���Դ�\n��β
string defaultValue = Convert.ToString(value).Trim().TrimEnd('\n');//oracle���Դ�\n��β
if (dalType != DalType.Access)
{
defaultValue = defaultValue.Replace("GenGUID()", string.Empty);
Expand Down Expand Up @@ -359,7 +359,7 @@ public static string FormatDefaultValue(DalType dalType, object value, int flag,
case DalType.MySql:
if (flag == 0)
{
defaultValue = defaultValue.Replace("b'0", "0").Replace("b'1", "1").Trim('\'');
defaultValue = defaultValue.Replace("b'0", "0").Replace("b'1", "1").Trim(' ', '\'');
}
else
{
Expand Down
35 changes: 27 additions & 8 deletions SQL/TableSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ namespace CYQ.Data.SQL
/// </summary>
internal partial class TableSchema
{
/// <summary>
/// ȫ�ֱ������棨ֻ��������ͱ�����������
/// </summary>
internal static Dictionary<string, Dictionary<string, string>> tableCache = new Dictionary<string, Dictionary<string, string>>(StringComparer.OrdinalIgnoreCase);
/// <summary>
/// ȫ�ֻ���ʵ����ı��ṹ�������Type��ȡ�Ľṹ��
/// </summary>
internal static MDictionary<string, MDataColumn> columnCache = new MDictionary<string, MDataColumn>(StringComparer.OrdinalIgnoreCase);
internal static string GetTableCacheKey(DbBase dbBase)
{
Expand Down Expand Up @@ -158,7 +164,7 @@ public static MDataColumn GetColumns(string tableName, ref DbBase dbHelper)
if (!helper.Version.StartsWith("08"))
{
//�Ȼ�ȡͬ��ʣ�����Ƿ���
string realTableName = Convert.ToString(helper.ExeScalar(string.Format(SynonymsName, SqlFormat.NotKeyword(tableName)), false));
string realTableName = Convert.ToString(helper.ExeScalar(string.Format(MSSQL_SynonymsName, SqlFormat.NotKeyword(tableName)), false));
if (!string.IsNullOrEmpty(realTableName))
{
string[] items = realTableName.Split('.');
Expand All @@ -178,6 +184,14 @@ public static MDataColumn GetColumns(string tableName, ref DbBase dbHelper)
}
else if (dalType == DalType.Oracle)
{
tableName = tableName.ToUpper();//Oracleת��д��
//�Ȼ�ȡͬ��ʣ�������Ƿ���
string realTableName = Convert.ToString(helper.ExeScalar(string.Format(Oracle_SynonymsName, SqlFormat.NotKeyword(tableName)), false));
if (!string.IsNullOrEmpty(realTableName))
{
tableName = realTableName;
}

sql = GetOracleColumns();
}
else if (dalType == DalType.Sybase)
Expand Down Expand Up @@ -830,7 +844,8 @@ internal partial class TableSchema
internal const string GetOracleMaxID = "select max({0}) from {1}";

#region ��ȡ���ݿ�������ֶ�
private const string SynonymsName = "SELECT TOP 1 base_object_name from sys.synonyms WHERE NAME = '{0}'";
private const string MSSQL_SynonymsName = "SELECT TOP 1 base_object_name from sys.synonyms WHERE NAME = '{0}'";
private const string Oracle_SynonymsName = "SELECT TABLE_NAME FROM USER_SYNONYMS WHERE SYNONYM_NAME='{0}' and rownum=1";
internal static string GetMSSQLColumns(bool for2000, string dbName)
{
// 2005��������ͬ���֧�֡� case s2.name WHEN 'timestamp' THEN 'variant' ELSE s2.name END as [SqlType],
Expand All @@ -852,6 +867,7 @@ s4.value as Description
}
internal static string GetOracleColumns()
{
//ͬ����ѱ���ȡ������ִ�У��ⲿ�Ա�����ת��д�������������Ż���
return @"select A.COLUMN_NAME as ColumnName,case DATA_TYPE when 'DATE' then 23 when 'CLOB' then 2147483647 when 'NCLOB' then 1073741823 else case when CHAR_COL_DECL_LENGTH is not null then CHAR_COL_DECL_LENGTH
else case when DATA_PRECISION is not null then DATA_PRECISION else DATA_LENGTH end end end as MaxSize,DATA_SCALE as Scale,
case NULLABLE when 'Y' then 1 else 0 end as IsNullable,
Expand All @@ -865,18 +881,21 @@ internal static string GetOracleColumns()
case when v.CONSTRAINT_TYPE='P' then 1 else 0 end as IsPrimaryKey,
case when v.CONSTRAINT_TYPE='U' then 1 else 0 end as IsUniqueKey,
case when v.CONSTRAINT_TYPE='R' then 1 else 0 end as IsForeignKey,
v.FKTableName,
case when length(r_constraint_name)>1
then (select table_name from user_constraints s where s.constraint_name=v.r_constraint_name)
else null
end as FKTableName ,
data_default as DefaultValue,
COMMENTS AS Description
from USER_TAB_COLS A left join user_col_comments B on A.Table_Name = B.Table_Name and A.Column_Name = B.Column_Name
left join
(select uc1.table_name,ucc.column_name, uc1.constraint_type,uc2.table_name as FKTableName from user_constraints uc1
left join user_constraints uc2 on uc1.r_constraint_name=uc2.constraint_name
left join user_cons_columns ucc on ucc.constraint_name=uc1.constraint_name
(select uc1.table_name,ucc.column_name, uc1.constraint_type,uc1.r_constraint_name from user_constraints uc1
left join (SELECT column_name,constraint_name FROM user_cons_columns WHERE TABLE_NAME=:TableName) ucc on ucc.constraint_name=uc1.constraint_name
where uc1.constraint_type in('P','U','R') ) v
on A.TABLE_NAME=v.table_name and A.COLUMN_NAME=v.column_name

where A.TABLE_NAME= nvl((SELECT TABLE_NAME FROM USER_SYNONYMS WHERE SYNONYM_NAME=UPPER(:TableName) and rownum=1),UPPER(:TableName)) order by COLUMN_ID";
where A.TABLE_NAME=:TableName order by COLUMN_ID";
// left join user_constraints uc2 on uc1.r_constraint_name=uc2.constraint_name
// where A.TABLE_NAME= nvl((SELECT TABLE_NAME FROM USER_SYNONYMS WHERE SYNONYM_NAME=UPPER(:TableName) and rownum=1),UPPER(:TableName)) order by COLUMN_ID";
}
internal static string GetMySqlColumns(string dbName)
{
Expand Down
5 changes: 3 additions & 2 deletions Table/MDataTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ public void Bind(object control)
/// �����ݱ��󶨵��б��ؼ�
/// </summary>
/// <param name="control">�б��ؼ�[����Repeater/DataList/GridView/DataGrid��]</param>
/// <param name="paraID">��ControlΪXHtmlAction����ʱ����Ҫָ���󶨵Ľڵ�ID</param>
/// <param name="nodeID">��ControlΪXHtmlAction����ʱ����Ҫָ���󶨵Ľڵ�ID</param>
public void Bind(object control, string nodeID)
{
MBindUI.Bind(control, this, nodeID);
Expand All @@ -598,7 +598,8 @@ public void Merge(MDataTable newTable)
{
for (int i = 0; i < newTable.Rows.Count; i++)
{
_Rows.Add(newTable.Rows[i]);
// _Rows.Add(newTable.Rows[i]);
NewRow(true).LoadFrom(newTable.Rows[i]);
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions Tool/ThreadBreak.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,11 @@ private static void ClearSchema()
/// <summary>
/// ����ȫ���߳�[ͨ�����߳��Ǹ���ѭ������ʱ��������]
/// </summary>
/// <param name="start"></param>
public static void AddGlobalThread(ParameterizedThreadStart start)
{
AddGlobalThread(start, null);
}
public static void AddGlobalThread(ParameterizedThreadStart start, object para)
{
if (globalThread.Count == 0)//��һ�μ��أ�������п��ܴ��ڵ��߳�Break��
{
Expand All @@ -153,7 +156,7 @@ public static void AddGlobalThread(ParameterizedThreadStart start)
globalThread.Add(start);
Thread thread = new Thread(start);
thread.IsBackground = true;
thread.Start(thread.ManagedThreadId);
thread.Start(para ?? thread.ManagedThreadId);
}
}
catch (Exception err)
Expand Down
8 changes: 7 additions & 1 deletion 更新记录.txt
Original file line number Diff line number Diff line change
Expand Up @@ -560,4 +560,10 @@
344��JsonHelper֧�ֶԶ����ƺ�Base64��ת��(2016-08-26)
345��DBTool.CreateTable��DBTool.DropTable��Ļ��洦��(2016-08-27)��
346��MAction��MProcȡ��SetAopOn��SetAopOff������ͳһΪ��SetAopState�������򻯷�����ͬʱ�ܴ��������״̬,�����ر��Զ����棩(2016-08-27)
347��MDataTable��Select������ǿ���Ը������ıȽϣ�(2016-08-27)
347��MDataTable��Select������ǿ���Ը������ıȽϣ�(2016-08-27)
348��AutoCache�Ļ���ʱ�䣬�ij�DefaultCacheTime���õ�ʱ�䣬���û������Լ������Զ�����ʱ�䣩(2016-08-27)
349��MProc��ExeMDataTableList�������Ӷ�Oracle����������֧��(2016-08-27)
350���Ż�Oracle�ñ��ṹ�����(2016-08-27)
351��MDataTable��Merge��������(2016-08-27)
352��ThreadBreak��AddGlobalThread�������ط���(2016-08-27)
353��CacheManage�ṩPreLoadDBSchemaToCache������2016-08-27)

0 comments on commit 1c95cde

Please sign in to comment.