using CYQ.Data.Cache; using CYQ.Data.Tool; using System; using System.Collections.Generic; using System.Data.Common; using System.IO; using System.Reflection; using System.Text; namespace CYQ.Data { internal partial class DB2Dal : DalBase { private DistributedCache _Cache = DistributedCache.Local;//Cache操作 public DB2Dal(ConnObject co) : base(co) { } private static string DllName { get { if (AppConfig.IsNetCore) { return "IBM.Data.DB2.Core"; } return "IBM.Data.DB2"; } } private static string NameSpace { get { return DllName; } } internal static Assembly GetAssembly() { string key = "DB2Client_Assembly"; object ass = DistributedCache.Local.Get(key); if (ass == null) { try { ass = Assembly.Load(DllName); DistributedCache.Local.Set(key, ass, 10080); } catch (Exception err) { string errMsg = err.Message; if (!File.Exists(AppConst.AssemblyPath + DllName + ".dll")) { errMsg = "Can't find the " + DllName + ".dll more info : " + errMsg; } Error.Throw(errMsg); } } return ass as Assembly; } protected override DbProviderFactory GetFactory() { //return DbProviderFactories.GetFactory(DllName); string key = "DB2Client_Factory"; object factory = _Cache.Get(key); if (factory == null) { Assembly ass = GetAssembly(); Type t = ass.GetType(DllName + ".DB2Factory"); if (t != null) { FieldInfo fi = t.GetField("Instance", BindingFlags.Public | BindingFlags.Static); if (fi != null) { factory = fi.GetValue(null); } } //factory = ass.CreateInstance(DllName + ".DB2Factory.Instance"); if (factory == null) { throw new System.Exception("Can't Create DB2Factory in " + DllName + ".dll"); } else { _Cache.Set(key, factory, 10080); } } return factory as DbProviderFactory; } protected override bool IsExistsDbName(string dbName) { return DBTool.TestConn(GetConnString(dbName)); } public override string DataBaseName { get { string conn = _con.ConnectionString; int i = conn.IndexOf("database=", StringComparison.OrdinalIgnoreCase); int end = conn.IndexOf(';', i); if (end == -1) { return conn.Substring(i + 9); } else { return conn.Substring(i + 9, end - i - 9); } } } public override char Pre { get { return '@'; } } } internal partial class DB2Dal { protected override string GetUVPSql(string type) { if (type == "U") { return "select name as TableName,remarks as Description from sysibm.systables where type = 'T' and creator<>'SYSIBM' order by name"; } else if (type == "V") { return "select name as TableName,remarks as Description from sysibm.systables where type = 'V' and creator<>'SYSCAT' order by name"; } return ""; } } }