1. Inside Zhou
  2. Inside.Util

Commits

Inside Zhou  committed d9e6452

OracleDataHelper中Lock、Obsolete状态设置、清除错误;完善OracleDataHelper,让其开箱可用,非必要情况调用方不必继承该类。

  • Participants
  • Parent commits e8006b0
  • Branches default

Comments (0)

Files changed (3)

File Inside.Util.Test/OracleDataHelperTest.cs

View file
  • Ignore whitespace
 		///</summary>
 		[TestMethod()]
 		public void ClearStateTest() {
-			OracleDataHelper target = new OracleDataHelper();
+			OracleDataHelper target = new OracleDataHelper(null, null);
 			dynamic obj = new DyObj();
 
 			obj.state = 0x1 | 0x2 | 0x4;
 		///</summary>
 		[TestMethod()]
 		public void SetStateTest() {
-			OracleDataHelper target = new OracleDataHelper();
+			OracleDataHelper target = new OracleDataHelper(null, null);
 			dynamic obj = new DyObj();
 
 			target.SetState(0x1 | 0x2 | 0x4, obj);
 		///</summary>
 		[TestMethod()]
 		public void HasStateTest() {
-			OracleDataHelper target = new OracleDataHelper();
+			OracleDataHelper target = new OracleDataHelper(null, null);
 			dynamic obj = new DyObj();
 			obj.state = 0x1 | 0x2 | 0x4;
 			Assert.IsTrue(target.HasState(obj, 0x1));

File Inside.Util/Properties/AssemblyInfo.cs

View file
  • Ignore whitespace
 
 /* 第一位数字表示大规模变化或特性、功能发展到一定程度量变成为质变或项目某个基础的潜规则发生变化,例如运行环境变动、项目组织结构变动等。
  * 第二位数字表示特性、功能增加,当第一位数字变化时,重置为0。
- * 第三位数字表示破坏兼容性的修改但不涉及特性、功能的增加,当第二位数字变化时,重置为0。
- * 第四位数字表示不破坏兼容性的修改,如bugfix,细节优化等,当第三位数字变化时,重置为0。
+ * 第三位数字表示破坏兼容性的修改但不涉及特性、功能的增加。
+ * 第四位数字表示不破坏兼容性的修改,如bugfix,细节优化等。
  * 除非有特殊声明,否则前三位数字变化表示均不保证向后兼容。
  */
-[assembly: AssemblyVersion("2.0.2.2")]
+[assembly: AssemblyVersion("2.0.3.2")]

File Inside.Util/Sql/OracleDataHelper.cs

View file
  • Ignore whitespace
 
 namespace Inside.Util.Sql {
 	/// <remark>
-	/// 潜规则1、主键名必须为oid,且是字符串类型。
+	/// 潜规则1、主键名必须为oid,且是字符串类型,长度限制为32字节
 	/// 潜规则2、必须有表示状态的列,名为state,且是Number类型。
+	/// 潜规则3、若不继承改变状态读写的相关方法,使用的状态值必须能表示可读、可写,且值必须与RowState中的一样。
 	/// </remark>
 	public class OracleDataHelper {
 		public static DateTime CurrentTimestamp(SqlHelper sql) {
 			}
 		}
 
-		public virtual SqlHelper SqlHelper { get; set; }
+		public string RelationName;
 
-		public virtual string RelationName { get; protected set; }
-		protected InputPlan InputPlan;
-		protected dynamic CanReadState = RowState.可读;
-		protected dynamic CanWriteState = RowState.可写;
+		public virtual SqlHelper SqlHelper { get; protected set; }
+		protected virtual InputPlan InputPlan {
+			get {
+				return InputPlan.CreateInstance(this.RelationName, this.SqlHelper);
+			}
+		}
+
+		public OracleDataHelper(string relationName, SqlHelper sql) {
+			this.SqlHelper = sql;
+			this.RelationName = relationName;
+		}
 
 		public virtual QueryPlan GetRawData(SqlHelper sql = null) {
 			sql = sql ?? this.SqlHelper;
 			}
 		}
 
-		public virtual string RelationCacheName {
+		public string RelationCacheName {
 			get {
 				return this.RelationName + "_cache";
 			}
 		}
 
-		public virtual string RelationArchiveName {
+		public string RelationArchiveName {
 			get {
 				return this.RelationName + "_arv";
 			}
 		}
 
-		public virtual string RelationLogName {
+		public string RelationLogName {
 			get {
 				return this.RelationName + "_log";
 			}
 		}
 
-		protected virtual void GenerateCacheTable(SqlHelper sql) {
+		public virtual void GenerateCacheTable(SqlHelper sql) {
 			GenerateCacheTable(this.RelationCacheName, this.RelationName, sql);
 		}
 
 			sql.Init("call {0}_rs(:archiveTime)".Fmt(this.RelationName)).AddParameter("archiveTime", archiveTime).ExecuteNonQueryAuto();
 		}
 
-		protected virtual void GenerateArchiveTable(SqlHelper sql) {
+		public virtual void GenerateArchiveTable(SqlHelper sql) {
 			GenerateArchiveTable(this.RelationArchiveName, this.RelationLogName, this.RelationName, sql);
 		}
 
 		public virtual void Lock(SqlHelper sql, params string[] oids) {
 			sql = sql ?? this.SqlHelper;
 
-			var objects = new List<DyObj>();
-			foreach(var oid in oids) {
-				var obj = new DyObj();
-				obj["oid"] = oid;
-				objects.Add(obj);
+			if(oids.Length > 0) {
+				var objects = this.Get(sql, null).Filter("oid", ConditionType.In, oids).Execute().ToArray();
+				this.SetLockState(objects.ToArray());
+				this.Update(sql, objects.ToArray());
 			}
-
-			this.SetLockState(objects.ToArray());
-			this.Update(sql, objects.ToArray());
 		}
 
 		public virtual void Lock(SqlHelper sql, params DyObj[] objects) {
 		}
 
 		public virtual bool IsLocked(DyObj obj) {
-			return !this.HasState(obj, this.CanWriteState);
+			return !this.HasState(obj, RowState.可写);
 		}
 
 		public virtual void Unlock(SqlHelper sql, params string[] oids) {
 			sql = sql ?? this.SqlHelper;
 
-			var objects = new List<DyObj>();
-			foreach(var oid in oids) {
-				var obj = new DyObj();
-				obj["oid"] = oid;
-				objects.Add(obj);
+			if(oids.Length > 0) {
+				var objects = this.Get(sql, null).Filter("oid", ConditionType.In, oids).Execute().ToArray();
+				this.SetUnlockState(objects.ToArray());
+				this.Update(sql, objects.ToArray());
 			}
-
-			this.SetUnlockState(objects.ToArray());
-			this.Update(sql, objects.ToArray());
 		}
 
 		public virtual void Unlock(SqlHelper sql, params DyObj[] objects) {
 		public virtual void Obsolete(SqlHelper sql, params string[] oids) {
 			sql = sql ?? this.SqlHelper;
 
-			var objects = new List<DyObj>();
-			foreach(var oid in oids) {
-				var obj = new DyObj();
-				obj["oid"] = oid;
-				objects.Add(obj);
+			if(oids.Length > 0) {
+				var objects = this.Get(sql, null).Filter("oid", ConditionType.In, oids).Execute().ToArray();
+				this.SetObsoleteState(objects.ToArray());
+				this.Update(sql, objects.ToArray());
 			}
-
-			this.SetObsoleteState(objects.ToArray());
-			this.Update(sql, objects.ToArray());
 		}
 
 		public virtual void Obsolete(SqlHelper sql, params DyObj[] objects) {
 			this.Update(sql, objects);
 		}
 
-		public void SetLockState(params DyObj[] objects) {
-			this.SetState(this.CanWriteState, objects);
+		public virtual void SetLockState(params DyObj[] objects) {
+			this.SetState(RowState.可写, objects);
 		}
 
-		public void SetUnlockState(params DyObj[] objects) {
-			this.SetState(this.CanWriteState, objects);
+		public virtual void SetUnlockState(params DyObj[] objects) {
+			this.SetState(RowState.可写, objects);
 		}
 
-		public void SetObsoleteState(params DyObj[] objects) {
-			this.ClearState(this.CanReadState, objects);
-			this.ClearState(this.CanWriteState, objects);
+		public virtual void SetObsoleteState(params DyObj[] objects) {
+			this.ClearState(RowState.可读, objects);
+			this.ClearState(RowState.可写, objects);
 		}
 
-		public void SetActiveState(params DyObj[] objects) {
-			this.SetState(this.CanReadState, objects);
-			this.SetState(this.CanWriteState, objects);
+		public virtual void SetActiveState(params DyObj[] objects) {
+			this.SetState(RowState.可读, objects);
+			this.SetState(RowState.可写, objects);
 		}
 
-		public void Delete(SqlHelper sql = null, params DyObj[] objects) {
+		public virtual void Delete(SqlHelper sql = null, params DyObj[] objects) {
 			sql = sql ?? this.SqlHelper;
 
 			using(var trans = sql.BeginTrans()) {
 			}
 		}
 
-		public void Delete(string cacheOID, SqlHelper sql = null, params DyObj[] objects) {
+		public virtual void Delete(string cacheOID, SqlHelper sql = null, params DyObj[] objects) {
 			sql = sql ?? this.SqlHelper;
 
 			if(string.IsNullOrEmpty(cacheOID)) {
 			}
 		}
 
-		public bool HasState<T>(DyObj obj, T state) {
+		public virtual bool HasState<T>(DyObj obj, T state) {
 			if(!(state is Enum) && Type.GetTypeCode(state.GetType()) != TypeCode.Int32) {
 				throw new ArgumentException("必须是枚举或Int32类型", "state");
 			}
 			return (objState & Convert.ToInt32(state)) == Convert.ToInt32(state);
 		}
 
-		public void ClearState<T>(T state, params DyObj[] objects) {
+		public virtual void ClearState<T>(T state, params DyObj[] objects) {
 			if(state is Enum) {
 				foreach(dynamic obj in objects) {
 					if(ObjectHelper.IsNil(obj["state"])) {
 			this.Update(sql, objects);
 		}
 
-		public void SetState<T>(T state, params DyObj[] objects) {
+		public virtual void SetState<T>(T state, params DyObj[] objects) {
 			if(state is Enum) {
 				foreach(dynamic obj in objects) {
 					if(ObjectHelper.IsNil(obj["state"])) {