Commits

Anonymous committed fa552e7

no more GeneratingValue

  • Participants
  • Parent commits 59e98dd

Comments (0)

Files changed (3)

             }
             throw new Exception("Cannot generate: " + expr);
         }
-        public static Dictionary<string, object> Insert(IDbTransaction trans, InsertRecord ins)
+        public static void Insert(IDbTransaction trans, InsertRecord ins)
         {
-            Dictionary<string, object> r = null;
             var items = ins.Values.ToArray();
             var sqlFields = String.Join(", ", from x in items select x.Key);
             var sqlParams = String.Join(", ", from x in items select (SqlParam(trans.Connection, x.Key)));
-            foreach (var i in items)
-            {
-                var g = i.Value as GeneratingValue;
-                if (g != null)
-                {
-                    if (r == null) r = new Dictionary<string, object>();
-                    r.Add(i.Key, Generate(trans, g.Expression));
-                }
-            }
             using (var cmd = CreateCommand(trans))
             {
                 cmd.CommandText = String.Format("insert into {0} ({1}) values ({2})", ins.TableName, sqlFields, sqlParams);
-                foreach (var i in items)
-                {
-                    object value = null;
-                    if (r == null || !r.TryGetValue(i.Key, out value)) value = i.Value;
-                    AddParamWithValue(cmd, i.Key, value);
-                }
+                foreach (var i in items) AddParamWithValue(cmd, i.Key, i.Value);
                 cmd.ExecuteNonQuery();
             }
-            return r;
         }
         public static string UniqueName(HashSet<string> used, string proposal)
         {

Usually/Resolve.cs

 
 namespace Usually
 {
-    public sealed class GeneratingValue
-    {
-        public string _expression = null;
-        public int _id = -1;
-        public GeneratingValue(string expr, int id)
-        { 
-            this._expression = expr;
-            this._id = id;
-        }
-        public string Expression { get { return this._expression; } }
-        public int Id { get { return this._id; } }
-        public GeneratingValueRef CreateRef()
-        {
-            return new GeneratingValueRef(this._id);
-        }
-    }
-    public sealed class GeneratingValueRef
-    {
-        private int _id;
-        public GeneratingValueRef(int id)
-        {
-            this._id = id;
-        }
-        public int Id { get { return this._id; } }
-    }
     public interface ITransactor
     {
         void Insert(InsertRecord ins);
         object[] GetKey(T obj);
         void ForEachKey(T obj, Action<string, object> action);
         void ForEachExtraKey(string group, T obj, Action<string, object> action);
-        void ForEachInsertValue(Func<string, GeneratingValue> newgen, T obj, Action<string, object> action);
+        void ForEachInsertValue(T obj, Action<string, object> action);
         void ForEachValueChange(T o, T n, Action<string, object, object> action);
     }
 
         {
             this.extraKeys[group].ForEach(obj, action);
         }
-        void IMetaInfo<T>.ForEachInsertValue(Func<string, GeneratingValue> newgen, T obj, Action<string, object> action)
+        void IMetaInfo<T>.ForEachInsertValue(T obj, Action<string, object> action)
         {
-            var done = new HashSet<string>();
-            Action<KeysDef, string, object> addKey = (keys, k, v) =>
-            {
-                if (!done.Contains(k))
-                {
-                    var expr = keys.GeneratingExpr(k, v);
-                    action(k, string.IsNullOrEmpty(expr) ? v : newgen(expr));
-                    done.Add(k);
-                }
-            };
-            this.keys.ForEach(obj, (k, v) => addKey(this.keys, k, v));
-            foreach (var keys in this.extraKeys.Values) 
-                keys.ForEach(obj, (k, v) => addKey(keys, k, v));
-            this.values.ForEach(obj, (k, v) =>
-            {
-                if (!done.Contains(k)) action(k, v);
-            });
+            this.keys.ForEach(obj, action);
+            foreach (var keys in this.extraKeys.Values) keys.ForEach(obj, action);
+            this.values.ForEach(obj, action);
         }
         void IMetaInfo<T>.ForEachValueChange(T o, T n, Action<string, object, object> action)
         {
             public TransactionRecord Record;
             public object Object;
         }
-        private int nextGenId = 1;
         private IMetaInfo<T> info = null;
         private IEnumerable<T> olds = null;
         private IEnumerable<T> news = null;
             if (r.Count != list.Count()) throw new Exception("Duplicate keys");
             return r;
         }
-        private GeneratingValue NewGeneratingValue(string expr)
-        {
-            var r = new GeneratingValue(expr, this.nextGenId);
-            this.nextGenId++;
-            return r;
-        }
         public IEnumerable<Insertion> ReconcileInsertion()
         {
             foreach (var n in this.news)
                 if (!this.oldLookup.TryGetValue(key, out o))
                 {
                     var r = new InsertRecord(this.info.TableName);
-                    this.info.ForEachInsertValue(this.NewGeneratingValue, n, (k, v) => r.Values[k] = v);
+                    this.info.ForEachInsertValue(n, (k, v) => r.Values[k] = v);
                     if (r.Values.Any()) yield return new Insertion { Record = r, Object = n };
                 }
             }

UsuallyTests/TestResolve.cs

                 var t = e.Current as InsertRecord;
                 Assert.AreEqual("ORDER_LINES", t.TableName);
                 Assert.AreEqual(7, t.Values.Count);
-                Assert.IsInstanceOf(typeof(GeneratingValue), t.Values["LINE_ID"]);
-                var g = t.Values["LINE_ID"] as GeneratingValue;
-                Assert.AreEqual("SEQ_ORDER_LINES", g.Expression);
+                Assert.AreEqual(-1, t.Values["LINE_ID"]);
                 Assert.AreEqual(900, t.Values["LINE_UNIQUE_ID"]);
                 Assert.AreEqual(101, t.Values["ORDER_ID"]);
                 Assert.AreEqual(8008, t.Values["ITEM_ID"]);
                 Assert.AreEqual("ORDER_LINES", t.TableName);
                 Assert.AreEqual(7, t.Values.Count);
                 Assert.AreEqual(9, t.Values["LINE_ID"]);
-                Assert.IsInstanceOf(typeof(GeneratingValue), t.Values["LINE_UNIQUE_ID"]);
-                var g = t.Values["LINE_UNIQUE_ID"] as GeneratingValue;
-                Assert.AreEqual("SEQ_ORDER_LINES_UNQ", g.Expression);
+                Assert.AreEqual(-7, t.Values["LINE_UNIQUE_ID"]);
                 Assert.AreEqual(101, t.Values["ORDER_ID"]);
                 Assert.AreEqual(9009, t.Values["ITEM_ID"]);
                 Assert.AreEqual("Nine Thousand Nine", t.Values["ITEM_NAME"]);