public override RowsetBase Execute(ICRUDQueryExecutionContext context, Query query, bool oneRow = false)
        {
          var ctx = (MongoDBCRUDQueryExecutionContext)context;
              
          Connector.Collection collection;
          var qry = MakeQuery(ctx.Database, query, out collection );
                            
          Schema schema = null;
          if (query.ResultRowType!=null)
            schema = Schema.GetForTypedRow(query.ResultRowType);
              

          Rowset result = null;
          if (schema!=null)
            result = new Rowset(schema);


          var skipCount = query["SKIP_COUNT"].AsInt(0);

          using(var cursor = collection.Find(qry, skipCount, oneRow ? 1: 0))
            foreach(var doc in cursor)
            {
              if (schema==null)
              {
                schema = m_Store.Converter.InferSchemaFromBSONDocument(doc);
                result = new Rowset(schema);
              }
                  
              var row = Row.MakeRow(schema, query.ResultRowType);
              m_Store.Converter.BSONDocumentToRow(doc, row, m_Store.TargetName);
              result.Add( row );
            }

          return result;
        }
示例#2
0
        public void JSON_SerializeRowset_ComplexTypedRows_Map()
        {
            var rowset = new Rowset(Schema.GetForTypedRow(typeof(PersonWithNesting)));

            for(var i=0; i<10; i++)
             rowset.Insert( new PersonWithNesting{
                                    ID = "POP{0}".Args(i),
                                    FirstName = "Oleg",
                                    LastName = "Popov-{0}".Args(i),
                                    DOB = new DateTime(1953, 12, 10),
                                    YearsInSpace = 12,
                                    LatestHistory = new HistoryItem{ ID = "111", StartDate = DateTime.Now, Description="Chaplin" },
                                    History1  = new List<HistoryItem>
                                    {
                                      new HistoryItem{ ID = "789211", StartDate = DateTime.Now, Description="Chaplin with us" },
                                      new HistoryItem{ ID = "234234", StartDate = DateTime.Now, Description="Chaplin with you" }
                                    },
                                    History2  = new HistoryItem[2]
                                   });

            var json = rowset.ToJSON( NFX.Serialization.JSON.JSONWritingOptions.PrettyPrintRowsAsMap);// );

            Console.WriteLine( json);

            var rowset2 = json.JSONToDynamic();

            Assert.AreEqual("Popov-1", rowset2.Rows[1].LastName);
            Assert.AreEqual("789211", rowset2.Rows[1].History1[0].ID);
        }
示例#3
0
文件: Rowsets.cs 项目: vlapchenko/nfx
        public void BuildUsingAdHockSchema()
        {
            var schema = new Schema("TEZT",
                           new Schema.FieldDef("ID", typeof(int), new List<FieldAttribute>{ new FieldAttribute(required: true, key: true)}),
                           new Schema.FieldDef("Description", typeof(string), new List<FieldAttribute>{ new FieldAttribute(required: true)})
            );

            var tbl = new Rowset(schema);

            for(var i=0; i<1000; i++)
            {
                 var row =  new DynamicRow(tbl.Schema);

                 row["ID"] = i;
                 row["Description"] = "Item-{0}".Args(i);

                 tbl.Insert( row );
            }

            Assert.AreEqual(1000, tbl.Count);

            var match = tbl.FindByKey(178);
            Assert.IsNotNull( match );
            Assert.AreEqual("Item-178", match["Description"]);
        }
示例#4
0
文件: Rowsets.cs 项目: vlapchenko/nfx
        public void Filtered_TypedRows()
        {
            var data = makeTypedRows(1000);

            var view =  new Rowset( data, row => (int)row["YearsWithCompany"] > 500 );

            Assert.AreEqual(499, view.Count);
        }
示例#5
0
文件: Table.cs 项目: vlapchenko/nfx
 /// <summary>
 /// Creates a shallow copy from another rowset resorting data per schema key definition, optionally applying a filter
 /// </summary>
 public Table(Rowset other, Func<Row, bool> filter = null) : base(other.Schema)
 {
   m_List =  new List<Row>();
   
   var src = filter==null ? other : other.Where(filter);
   
   foreach(var row in src)
      Insert(row);
 }
示例#6
0
        /// <summary>
        /// Creates a shallow copy from another rowset resorting data per schema key definition, optionally applying a filter
        /// </summary>
        public Table(Rowset other, Func <Row, bool> filter = null) : base(other.Schema)
        {
            m_List = new List <Row>();

            var src = filter == null ? other : other.Where(filter);

            foreach (var row in src)
            {
                Insert(row);
            }
        }
        public override RowsetBase Execute(ICRUDQueryExecutionContext context, Query query, bool oneRow = false)
        {
            var ctx = (MongoDBCRUDQueryExecutionContext)context;

              Connector.Collection collection;
              var qry = MakeQuery(ctx.Database, query, out collection );

              Schema schema = null;
              var rtp = query.ResultRowType;
              if (rtp!=null && typeof(TypedRow).IsAssignableFrom(rtp))
            schema = Schema.GetForTypedRow(query.ResultRowType);

              Rowset result = null;
              if (schema!=null)
            result = new Rowset(schema);

              var p = query[QUERY_PARAM_SKIP_COUNT];
              var skipCount  = p!=null ? p.Value.AsInt(0) : 0;

              p = query[QUERY_PARAM_FETCH_BY];
              var fetchBy    = p!=null ? p.Value.AsInt(0) : 0;

              p = query[QUERY_PARAM_FETCH_LIMIT];
              var fetchLimit = p!=null ? p.Value.AsInt(-1) : -1;

              using(var cursor = collection.Find(qry, skipCount, oneRow ? 1: fetchBy))
            foreach(var doc in cursor)
            {
              if (schema==null)
              {
                schema = m_Store.Converter.InferSchemaFromBSONDocument(doc);
                result = new Rowset(schema);
              }

              var row = Row.MakeRow(schema, query.ResultRowType);
              m_Store.Converter.BSONDocumentToRow(doc, row, m_Store.TargetName);
              result.Add( row );

              if (fetchLimit>0 && result.Count>=fetchLimit) break;
            }

              return result;
        }
示例#8
0
        public override RowsetBase Execute(ICRUDQueryExecutionContext context, Query query, bool oneRow = false)
        {
            var ctx = (MongoDBCRUDQueryExecutionContext)context;

              NFX.DataAccess.MongoDB.Connector.Collection collection;
              var qry = MakeQuery(ctx.Database, query, out collection);

              var rrow = new TResult();

              var sw = Stopwatch.StartNew();

              rrow.Count = collection.Count(qry);//Performs server-side count over query

              rrow.Interval = sw.Elapsed;

              var result = new Rowset(Schema.GetForTypedRow(typeof(TResult)));
              result.Add(rrow);
              return result;
        }
示例#9
0
文件: Rowsets.cs 项目: vlapchenko/nfx
        public void LogChanges_Delete()
        {
            var tbl = new Rowset(Schema.GetForTypedRow(typeof(Person)));

            tbl.Insert( new Person{
                                    ID = "POP1",
                                    FirstName = "Oleg",
                                    LastName = "Popov",
                                    DOB = new DateTime(1953, 12, 10),
                                    YearsInSpace = 12
                                   });
            tbl.LogChanges = true;

            tbl.Delete( tbl[0] );

            Assert.AreEqual(1, tbl.ChangeCount);
            Assert.AreEqual(0, tbl.Count);

            Assert.AreEqual(RowChangeType.Delete, tbl.GetChangeAt(0).Value.ChangeType);
        }
        /// <summary>
        /// Reads data from reader into rowset. the reader is NOT disposed
        /// </summary>
        public static Rowset PopulateRowset(MySQLCRUDQueryExecutionContext context, MySqlDataReader reader, string target, Query query, QuerySource qSource, bool oneRow)
        {
            Schema.FieldDef[] toLoad;
              Schema schema = GetSchemaForQuery(target, query, reader, qSource, out toLoad);
              var store= context.DataStore;

              var result = new Rowset(schema);
              while(reader.Read())
              {
                var row = PopulateRow(context, query.ResultRowType, schema, toLoad, reader);

                result.Add( row );
                if (oneRow) break;
              }

              return result;
        }
示例#11
0
        public void Save()
        {
            var rowset = new Rowset(Schema.GetForTypedRow(typeof(MyPerzon)));
              rowset.LogChanges = true;

              for(var i=0; i<100; i++)
              {
            rowset.Insert( new MyPerzon
            {
               GDID = new GDID(1, 1, (ulong)i),
               Name = "Jeka Koshmar",
               Age = i
            });
              }

              var qryBetween5060 = new Query("CRUD.LoadPerzonsInAgeSpan", typeof(MyPerzon))
                           {
                             new Query.Param("fromAge", 50),
                             new Query.Param("toAge", 60)
                           };

              var rs = store.LoadOneRowset(qryBetween5060);
              Assert.IsNotNull( rs );

              Assert.AreEqual(0, rs.Count);

              store.Save(rowset);
              rowset.PurgeChanges();

              rs = store.LoadOneRowset(qryBetween5060);
              Assert.IsNotNull( rs );

              Assert.AreEqual(9, rs.Count);

              rowset[55]["Age"] = 900;  //falls out of query
              rowset.Update(rowset[55]);
              rowset.Delete(rowset[59]); //physically deleted
              store.Save(rowset);

              rs = store.LoadOneRowset(qryBetween5060);
              Assert.IsNotNull( rs );

              Assert.AreEqual(7, rs.Count);
              Assert.AreEqual(58, rs.First()["Age"]);
              Assert.AreEqual(51, rs.Last()["Age"]);
        }
示例#12
0
文件: Rowsets.cs 项目: vlapchenko/nfx
        private Rowset makeTypedRows(int count)
        {
            var rset = new Rowset(Schema.GetForTypedRow(typeof(Person)));

                  for(var i=0; i<count; i++)
                     rset.Insert( new Person{
                                            ID = "POP{0}".Args(i),
                                            FirstName = "Oleg",
                                            LastName = "Popov-{0}".Args(i),
                                            DOB = new DateTime(1953, 12, 10),
                                            YearsInSpace = 1000-i,
                                            YearsWithCompany = i
                                           });
                  return rset;
        }
示例#13
0
文件: Rowsets.cs 项目: vlapchenko/nfx
        public void Sorted1columnDESC_TypedRows()
        {
            var data = makeTypedRows(1000);

            var view =  new Rowset( data, row => (int)row["YearsWithCompany"] > 500 );

            Assert.AreEqual(499, view.Count);

            view.SortDefinition = "-YearsWithCompany";

            Assert.AreEqual(999, view[0]["YearsWithCompany"]);
        }
示例#14
0
文件: Rowsets.cs 项目: vlapchenko/nfx
        public void PopulateAndDeleteNonExisting()
        {
            var tbl = new Rowset(Schema.GetForTypedRow(typeof(Person)));

            for(var i=0; i<1000; i++)
             tbl.Insert( new Person{
                                    ID = "POP{0}".Args(i),
                                    FirstName = "Oleg",
                                    LastName = "Popov-{0}".Args(i),
                                    DOB = new DateTime(1953, 12, 10),
                                    YearsInSpace = 12
                                   });

            var delete =  new Person{
                                    ID = "NONE17"
                                   };

            var idx = tbl.Delete( delete );//<-------------!!!!!!

            Assert.IsTrue( idx==-1 );
            Assert.AreEqual(1000, tbl.Count);

            var match = tbl.FindByKey("POP17") as Person;
            Assert.IsNotNull( match );
        }
        public void Rowset_FromJSON(bool rowsAsMap)
        {
            var row = new TeztRow();
            var src = new Rowset(row.Schema);

            row.BoolField = true;
            row.CharField = 'a';
            row.StringField = "aaa";
            row.DateTimeField = new DateTime(2016, 1, 2);
            row.GDIDField = new GDID(1, 2, 3);

            row.ByteField = 100;
            row.ShortField = -100;
            row.IntField = -999;

            row.UIntField = 254869;
            row.LongField = -267392;

            row.FloatField = 32768.32768F;
            row.DoubleField = -1048576.1048576D;

            row.DecimalField = 1.0529M;

            row.NullableField = null;

            row.ArrayInt = new int[] {-1, 0, 1};
            row.ListString = new List<string> {"one", "two", "three"};
            row.DictionaryIntStr = new Dictionary<int, string>
            {
              {1, "first"},
              {2, "second"}
            };

            row.RowField = new Person { Name = "John", Age = 20 };

            src.Add(row);

            row.BoolField = false;
            row.CharField = 'b';
            row.StringField = "bbb";
            row.DateTimeField = new DateTime(2016, 2, 1);
            row.GDIDField = new GDID(4, 5, 6);

            row.ByteField = 101;
            row.ShortField = 100;
            row.IntField = 999;

            row.UIntField = 109876;
            row.LongField = 267392;

            row.FloatField = -32768.32768F;
            row.DoubleField = -048576.1048576D;

            row.DecimalField = -1.0529M;

            row.NullableField = null;

            row.ArrayInt = new int[] {1, 0, -1};
            row.ListString = new List<string> { "three","two", "one" };
            row.DictionaryIntStr = new Dictionary<int, string>
            {
              {0, "zero"},
              {1, "first"},
              {2, "second"}
            };

            row.RowField = new Person { Name = "Ann", Age = 19 };

            src.Add(row);

            var options = new NFX.Serialization.JSON.JSONWritingOptions
                          {
                            RowsetMetadata = true,
                            SpaceSymbols = true,
                            IndentWidth = 2,
                            MemberLineBreak = true,
                            ObjectLineBreak = true,
                            RowsAsMap = rowsAsMap
                          };
            var json = src.ToJSON(options);

            var trg = RowsetBase.FromJSON(json);

            schemaAssertions(trg.Schema, src.Schema);
            rowsAssertions(src, trg, rowsAsMap);
        }
        public void Rowset_FromJSON_FieldMissed(bool rowsAsMap)
        {
            var row = new Person { Name = "Henry", Age = 43 };
            var rowSet = new Rowset(row.Schema);
            rowSet.Add(row);
            var options = new NFX.Serialization.JSON.JSONWritingOptions
                          {
                            RowsetMetadata = true,
                            RowsAsMap = rowsAsMap
                          };
            var json = rowSet.ToJSON(options);
            var map = JSONReader.DeserializeDataObject( json ) as JSONDataMap;
            var rows = (map["Rows"] as IList<object>);
            if (rowsAsMap)
            {
              var pers = rows[0] as IDictionary<string, object>;
              pers.Remove("Age");
            }
            else
            {
              var pers = rows[0] as IList<object>;
              pers.RemoveAt(1);
            }

            bool allMatched;
            var trg = RowsetBase.FromJSON(map, out allMatched);

            Assert.IsFalse(allMatched);
            var trgRow = trg[0];
            Assert.AreEqual(trgRow.Schema.FieldCount, 2);
            Assert.AreEqual(trgRow["Name"], "Henry");
            Assert.IsNull(trgRow["Age"]);
        }
            public RowsetBase Execute(ICRUDQueryExecutionContext context, Query query, bool oneRow = false)
            {
                var ctx = (MySQLCRUDQueryExecutionContext)context;
                var target = ctx.DataStore.TargetName;

                Rowset result = null;

                using (var cmd = ctx.Connection.CreateCommand())
                {
                    
                    cmd.CommandText =  m_Source.StatementSource;
                   
                    PopulateParameters(cmd, query);
                              
                   

                    cmd.Transaction = ctx.Transaction;

                    MySqlDataReader reader = null;

                    try
                    {
                        reader = oneRow ? cmd.ExecuteReader(CommandBehavior.SingleRow) : cmd.ExecuteReader();
                        GeneratorUtils.LogCommand(ctx.DataStore.LogLevel, "queryhandler-ok", cmd, null);
                    }
                    catch(Exception error)
                    {
                        GeneratorUtils.LogCommand(ctx.DataStore.LogLevel, "queryhandler-error", cmd, error);
                        throw;
                    }


                    using (reader)
                    {
                      Schema.FieldDef[] toLoad;
                      Schema schema = getSchema(target, query, reader, out toLoad);

                      result = new Rowset(schema);
                      while(reader.Read())
                      {
                        var row = Row.MakeRow(schema, query.ResultRowType);
                        
                        for (int i = 0; i < reader.FieldCount; i++)
                        {
                            var fdef = toLoad[i];
                            if (fdef==null) continue;

                            var val = reader.GetValue(i);
                            if (fdef.NonNullableType==typeof(bool))
                                row[fdef.Order] = val.AsNullableBool();
                            else
                                row[fdef.Order] = val;
                        }

                        result.Add( row );
                        if (oneRow) break;
                      }
                    }//using reader

                }//using command

               return result;
            }
示例#18
0
文件: Rowsets.cs 项目: vlapchenko/nfx
        public void PopulateAndFindKey_TypedRows()
        {
            var tbl = new Rowset(Schema.GetForTypedRow(typeof(Person)));

            for(var i=0; i<1000; i++)
             tbl.Insert( new Person{
                                    ID = "POP{0}".Args(i),
                                    FirstName = "Oleg",
                                    LastName = "Popov-{0}".Args(i),
                                    DOB = new DateTime(1953, 12, 10),
                                    YearsInSpace = 12
                                   });

            Assert.AreEqual(1000, tbl.Count);

            var match1 = tbl.FindByKey("POP35");
            Assert.IsNotNull( match1 );
            Assert.AreEqual("Popov-35", match1["LastName"]); //example of dynamic row access

            var match2 = tbl.FindByKey("POP36") as Person;
            Assert.IsNotNull( match2 );
            Assert.AreEqual("Popov-36", match2.LastName);//example of typed row access

            var match3 = tbl.FindByKey("DoesNotExist");
            Assert.IsNull( match3 );
        }
示例#19
0
文件: Rowsets.cs 项目: vlapchenko/nfx
        public void PopulateAndFindKey_MixedRows()
        {
            var tbl = new Rowset(Schema.GetForTypedRow(typeof(Person)));

            for(var i=0; i<1000; i++)
            {
                 var row =  new DynamicRow(tbl.Schema);

                 row["ID"] = "DYN{0}".Args(i);
                 row["FirstName"] = "Oleg";
                 row["LastName"] = "DynamicPopov-{0}".Args(i);
                 row["DOB"] = new DateTime(1953, 12, 10);
                 row["YearsInSpace"] = 12;

                 tbl.Insert( row );

                 tbl.Insert( new Person{
                                    ID = "TYPED{0}".Args(i),
                                    FirstName = "Oleg",
                                    LastName = "TypedPopov-{0}".Args(i),
                                    DOB = new DateTime(1953, 12, 10),
                                    YearsInSpace = 12
                                   });
            }

            Assert.AreEqual(2000, tbl.Count);

            var match1 = tbl.FindByKey("DYN35");
            Assert.IsNotNull( match1 );
            Assert.IsTrue( match1 is DynamicRow );
            Assert.AreEqual("DynamicPopov-35", match1["LastName"]);

            var match2 = tbl.FindByKey("TYPED36") as Person;
            Assert.IsNotNull( match2 );
            Assert.AreEqual("TypedPopov-36", match2["LastName"]);

            var match3 = tbl.FindByKey("DoesNotExist");
            Assert.IsNull( match3 );
        }
示例#20
0
文件: Rowsets.cs 项目: vlapchenko/nfx
        public void PopulateAndFindKey_DynamicRows()
        {
            var tbl = new Rowset(Schema.GetForTypedRow(typeof(Person)));

            for(var i=0; i<1000; i++)
            {
                 var row =  new DynamicRow(tbl.Schema);

                 row["ID"] = "POP{0}".Args(i);
                 row["FirstName"] = "Oleg";
                 row["LastName"] = "Popov-{0}".Args(i);
                 row["DOB"] = new DateTime(1953, 12, 10);
                 row["YearsInSpace"] = 12;

                 tbl.Insert( row );
            }

            Assert.AreEqual(1000, tbl.Count);

            var match1 = tbl.FindByKey("POP35");
            Assert.IsNotNull( match1 );
            Assert.AreEqual("Popov-35", match1["LastName"]);

            var match2 = tbl.FindByKey("POP36") as DynamicRow;
            Assert.IsNotNull( match2 );
            Assert.AreEqual("Popov-36", match2["LastName"]);

            var match3 = tbl.FindByKey("DoesNotExist");
            Assert.IsNull( match3 );
        }
示例#21
0
文件: Rowsets.cs 项目: vlapchenko/nfx
        public void PopulateAndFindCompositeKey_TypedRows()
        {
            var tbl = new Rowset(Schema.GetForTypedRow(typeof(WithCompositeKey)));

            for(var i=0; i<1000; i++)
             tbl.Insert( new WithCompositeKey{
                                    ID = "ID{0}".Args(i),
                                    StartDate = new DateTime(1953, 12, 10),
                                    Description = "Descr{0}".Args(i)
                                   });

            Assert.AreEqual(1000, tbl.Count);

            var match1 = tbl.FindByKey("ID35", new DateTime(1953, 12, 10));
            Assert.IsNotNull( match1 );
            Assert.AreEqual("Descr35", match1["Description"]);

            var match2 = tbl.FindByKey("ID35", new DateTime(1953, 07, 10));
            Assert.IsNull( match2 );
        }
示例#22
0
        public void JSON_SerializeRowset_TypedRows()
        {
            var rowset = new Rowset(Schema.GetForTypedRow(typeof(Person)));

            for(var i=0; i<10; i++)
             rowset.Insert( new Person{
                                    ID = "POP{0}".Args(i),
                                    FirstName = "Oleg",
                                    LastName = "Popov-{0}".Args(i),
                                    DOB = new DateTime(1953, 12, 10),
                                    YearsInSpace = 12
                                   });

            var json = rowset.ToJSON( NFX.Serialization.JSON.JSONWritingOptions.PrettyPrint);// );

            Console.WriteLine( json);

            var rowset2 = json.JSONToDynamic();

            Assert.AreEqual("Popov-1", rowset2.Rows[1][2]);
        }
示例#23
0
        public void JSON_SerializeRow_ComplexTypedRow_WithSchema()
        {
            var row1 =  new PersonWithNesting{
                                    ID = "A1",
                                    FirstName = "Joseph",
                                    LastName = "Mc'Cloud",
                                    DOB = new DateTime(1953, 12, 10),
                                    YearsInSpace = 12,
                                    LatestHistory = new HistoryItem{ ID = "111", StartDate = DateTime.Now, Description="Chaplin" },
                                    History1  = new List<HistoryItem>
                                    {
                                      new HistoryItem{ ID = "789211", StartDate = DateTime.Now, Description="Chaplin with us" },
                                      new HistoryItem{ ID = "234234", StartDate = DateTime.Now, Description="Chaplin with you" }
                                    },
                                    History2  = new HistoryItem[2]
                                   };

            var tbl1 = new Rowset(row1.Schema);
            tbl1.Add(row1);

            var json = tbl1.ToJSON( new NFX.Serialization.JSON.JSONWritingOptions
                                   {
                                     RowsetMetadata = true,
                                      SpaceSymbols = true,
                                       IndentWidth = 2,
                                        MemberLineBreak = true,
                                         ObjectLineBreak = true,
                                          RowsAsMap = true,
                                           Purpose = JSONSerializationPurpose.Marshalling
                                   });//AS MAP

            Console.WriteLine(json);

            var tbl2 = json.JSONToDynamic();

            var row2 = tbl2.Rows[0];

            Assert.AreEqual("A1",      row2.ID);
            Assert.AreEqual("Joseph",  row2.FirstName);
            Assert.AreEqual("Mc'Cloud",row2.LastName);
            Assert.AreEqual("111",     row2.LatestHistory.ID);
            Assert.AreEqual(2,         row2.History1.Count);
            Assert.AreEqual("234234",  row2.History1[1].ID);
        }
示例#24
0
    /// <summary>
    /// Converts ErlCRUD response to CLR CRUD rowset
    /// </summary>
    /// <remarks>
    /// An Example data packet is field defs as speced in schema:
    /// "tca_jaba": has two field in PK
    /// [
    ///    {tca_jaba, {1234, tav}, "User is cool", true},
    ///    {tca_jaba, {2344, zap}, "A bird wants to drink", false}, 
    ///    {tca_jaba, {8944, tav}, "Have you seen this?", false} 
    /// ]
    /// 
    /// "aaa": has one field in PK - notice no tuple in key
    /// [
    ///    {aaa, 1234, tav, "User is cool", true},
    ///    {aaa, 2344, zap, "A bird wants to drink", false}, 
    ///    {aaa, 8944, tav, "Have you seen this?", false} 
    /// ]
    /// </remarks>
    public RowsetBase ErlCRUDResponseToRowset(string schemaName, ErlList erlData)
    {
      var crudSchema = GetCRUDSchemaForName(schemaName);
      var result = new Rowset(crudSchema);

      foreach(var elm in erlData)
      {
        var tuple = elm as ErlTuple;
        if (tuple==null)
          throw new ErlDataAccessException(StringConsts.ERL_DS_INVALID_RESPONSE_PROTOCOL_ERROR+"ErlCRUDResponseToRowset(list element is not tuple)");

        var row = ErlTupleToRow(schemaName, tuple, crudSchema);
        result.Add( row );
      }

      return result;
    }
示例#25
0
        public static void ASYNC_InsertManyUsingLogChanges_TypedRow(ICRUDDataStore store)
        {
            var rowset = new Rowset( Schema.GetForTypedRow(typeof(Patient)));
            rowset.LogChanges = true;
       
            for(var i=0; i<1000; i++)
            {
                rowset.Insert( new Patient
                               {
                                 SSN = "999-88-9012",
                                 First_Name = "Jack",
                                 Last_Name = "Kozloff"+i,
                                 DOB = new DateTime(1980, 1, 12)
                               });
            }
            
            for(var i=0; i<327; i++)
            {
                rowset.Insert( new Patient 
                               {
                                 SSN = "999-88-9012",
                                 First_Name = "Jack",
                                 Last_Name = "Abramovich"+i,
                                 DOB = new DateTime(2001, 1, 12)
                               });
            }

            store.SaveAsync( rowset ).Wait();

            var task = store.LoadAsync( new Query("CRUD.Patient.List", typeof(Patient) ) { new Query.Param("LN", "%loff%") } );
            
            Assert.AreEqual(1000, task.Result[0].Count);

            task = store.LoadAsync( new Query("CRUD.Patient.List", typeof(Patient) ) { new Query.Param("LN", "%ovich%") } );
            
            Assert.AreEqual(327, task.Result[0].Count);
        }
示例#26
0
文件: Rowsets.cs 项目: vlapchenko/nfx
        public void PopulateAndUpdateNonExisting()
        {
            var tbl = new Rowset(Schema.GetForTypedRow(typeof(Person)));

            for(var i=0; i<1000; i++)
             tbl.Insert( new Person{
                                    ID = "POP{0}".Args(i),
                                    FirstName = "Oleg",
                                    LastName = "Popov-{0}".Args(i),
                                    DOB = new DateTime(1953, 12, 10),
                                    YearsInSpace = 12
                                   });

            var update =  new Person{
                                    ID = "NONE17",
                                    FirstName = "Yaroslav",
                                    LastName = "Suzkever",
                                    DOB = new DateTime(1952, 12, 10),
                                    YearsInSpace = 14
                                   };

            var idx = tbl.Update(update);//<-------------!!!!!!

            Assert.IsTrue( idx==-1 );

            var match = tbl.FindByKey("NONE17") as Person;
            Assert.IsNull( match );
        }
        public void Rowset_FromJSON_ShemaOnly()
        {
            var src = new Rowset(new TeztRow().Schema);
            var options = new NFX.Serialization.JSON.JSONWritingOptions
                                  {
                                    RowsetMetadata = true,
                                    SpaceSymbols = true,
                                    IndentWidth = 2,
                                    MemberLineBreak = true,
                                    ObjectLineBreak = true
                                  };
            var json = src.ToJSON(options);

            var trg = RowsetBase.FromJSON(json, true);

            schemaAssertions(trg.Schema, src.Schema);
            Assert.AreEqual(trg.Count, 0);
        }
示例#28
0
文件: Rowsets.cs 项目: vlapchenko/nfx
        public void PopulateAndUpsertNonExisting()
        {
            var tbl = new Rowset(Schema.GetForTypedRow(typeof(Person)));

            for(var i=0; i<1000; i++)
             tbl.Insert( new Person{
                                    ID = "POP{0}".Args(i),
                                    FirstName = "Oleg",
                                    LastName = "Popov-{0}".Args(i),
                                    DOB = new DateTime(1953, 12, 10),
                                    YearsInSpace = 12
                                   });

            var update =  new Person{
                                    ID = "GOODMAN17",
                                    FirstName = "John",
                                    LastName = "Jeffer",
                                    DOB = new DateTime(1952, 12, 10),
                                    YearsInSpace = 14
                                   };

            var existed = tbl.Upsert(update);//<-------------!!!!!!

            Assert.IsFalse( existed );

            Assert.AreEqual(1001, tbl.Count);

            var match = tbl.FindByKey("POP17") as Person;
            Assert.IsNotNull( match );
            Assert.AreEqual("Oleg", match.FirstName);
            Assert.AreEqual("Popov-17", match.LastName);

            match = tbl.FindByKey("GOODMAN17") as Person;
            Assert.IsNotNull( match );
            Assert.AreEqual("John", match.FirstName);
            Assert.AreEqual("Jeffer", match.LastName);
        }
示例#29
0
文件: Rowsets.cs 项目: vlapchenko/nfx
        public void SimpleFiltered_TypedRows()
        {
            var data = makeTypedRows(1000);

            var view =  new Rowset( data, row => row.SimpleFilterPredicate("*ov-22") );

            Assert.AreEqual(1, view.Count);
            Assert.AreEqual(22, view[0]["YearsWithCompany"]);
        }
示例#30
0
文件: SchemaMap.cs 项目: yhhno/nfx
    /// <summary>
    /// Converts ErlCRUD response to CLR CRUD rowset
    /// </summary>
    /// <remarks>
    /// An Example data packet is field defs as speced in schema:
    /// "tca_jaba": has two field in PK
    /// [
    ///    {tca_jaba, {1234, tav}, "User is cool", true},
    ///    {tca_jaba, {2344, zap}, "A bird wants to drink", false}, 
    ///    {tca_jaba, {8944, tav}, "Have you seen this?", false} 
    /// ]
    /// 
    /// "aaa": has one field in PK - notice no tuple in key
    /// [
    ///    {aaa, 1234, tav, "User is cool", true},
    ///    {aaa, 2344, zap, "A bird wants to drink", false}, 
    ///    {aaa, 8944, tav, "Have you seen this?", false} 
    /// ]
    /// </remarks>
    public RowsetBase ErlCRUDResponseToRowset(string schemaName, ErlList erlData, Type tRow = null)
    {
      var crudSchema = GetCRUDSchemaForName(schemaName);
      var tSchema    = tRow == null
        ? crudSchema
        : Schema.GetForTypedRow(tRow);

      var result = new Rowset(tSchema);

      foreach(var elm in erlData)
      {
        var tuple = elm as ErlTuple;
        if (tuple==null)
          throw new ErlDataAccessException(StringConsts.ERL_DS_INVALID_RESP_PROTOCOL_ERROR+"ErlCRUDResponseToRowset(list element is not tuple)");

        var row = ErlTupleToRow(schemaName, tuple, crudSchema);
        if (tRow != null)
        {
          var trow = Row.MakeRow(tSchema, tRow);
          row.CopyFields(trow);
          row = trow;
        }
        result.Add( row );
      }

      return result;
    }