Esempio n. 1
0
    public void ErlInsertManyDeleteAndQuery()
    {
      var schema = store.GetSchema(new Query("CRUD.SECDEF"));

      for (var i = 0; i < CCY_PAIRS.Length; i++)
      {
        var row = new DynamicRow(schema);

        row.ApplyDefaultFieldValues(store.TargetName);

        var ccy1 = CCY_PAIRS[i].Substring(0, 3);
        var ccy2 = CCY_PAIRS[i].Substring(4, 3);

        row["Exchange"]     = "NYSE";
        row["Symbol"]       = ccy1 + ccy2;
        row["Instr"]        = CCY_PAIRS[i];
        row["SecID"]        = i;
        row["ExchSecID"]    = 1000 + i;
        row["Ccy"]          = ccy1;
        row["SettlCcy"]     = ccy2;

        row["ContractMult"] = 1.0d;
        row["PriceStep"]    = 10e-5d;

        Assert.IsNull(row.Validate());

        var affected = store.Upsert(row);
        Assert.AreEqual(1, affected);
      }

      var qry = new Query("CRUD.SecDef.ByExchange")
      {
          new Query.Param("Exchange", "NYSE")
      };

      var data = store.LoadOneRowset(qry);

      Assert.IsNotNull(data);

      Console.WriteLine(data.ToJSON(JSONWritingOptions.PrettyPrintRowsAsMap));

      Assert.AreEqual(CCY_PAIRS.Length, data.Count);

      var del = new DynamicRow(schema);

      del["Exchange"]  = "CLE";
      del["Symbol"]  = "USDMXN";

      Assert.AreEqual(1, store.Delete(del));
      
      data = store.LoadOneRowset(qry);//NYSE

      Assert.IsNotNull(data);
      Assert.AreEqual(CCY_PAIRS.Length, data.Count); 

      qry = new Query("CRUD.SecDef.ByExchange")
      {
          new Query.Param("Exchange", "CLE")
      };

      data = store.LoadOneRowset(qry);//Requery for CLE

      Assert.IsNotNull(data);
      Assert.AreEqual(CCY_PAIRS.Length - 1, data.Count);//1 was deleted!!!!!!!!!!!
    }
Esempio n. 2
0
    public void ErlInsert()
    {
      var schema = store.GetSchema(new Query("CRUD.SECDEF"));
      var row = new DynamicRow(schema);

      row.ApplyDefaultFieldValues(store.TargetName);

      row["Exchange"] = "HS";
      row["Symbol"] = "EURUSD";
      row["Instr"] =  "EUR/USD";
      row["SecID"] = 1;
      row["ExchSecID"] = 1010;
      row["Ccy"] = "EUR";
      row["SettlCcy"] = "USD";

      row["ContractMult"] = 1.0d;
      row["PriceStep"] = 10e-5d;

      Assert.IsNull(row.Validate());

      var affected = store.Insert(row);
      Assert.AreEqual(1, affected);
    }
Esempio n. 3
0
        public void ErlInsert()
        {
            var schema = store.GetSchema(new Query("CRUD.SECDEF"));
              var row = new DynamicRow(schema);

              row.ApplyDefaultFieldValues(store.TargetName);

              row["xchg"]       = "HS";
              row["symbol"]     = "EURUSD";
              row["instr"]      = "EUR/USD";
              row["secid"]      = 1;
              row["xchg_secid"] = 1010;
              row["ccy"]        = "EUR";
              row["settl_ccy"]  = "USD";

              row["contr_mult"] = 1.0d;
              row["px_step"]    = 10e-5d;

              Assert.IsNull(row.Validate());

              var affected = store.Insert(row);
              Assert.AreEqual(1, affected);
        }
Esempio n. 4
0
        public void ErlInsertManyAndQuery()
        {
            var schema = store.GetSchema(new Query("CRUD.SECDEF"));

              for (var i = 0; i < CCY_PAIRS.Length; i++)
              {
            var row = new DynamicRow(schema);

            row.ApplyDefaultFieldValues(store.TargetName);

            var ccy1 = CCY_PAIRS[i].Substring(0, 3);
            var ccy2 = CCY_PAIRS[i].Substring(4, 3);

            row["xchg"]       = "CLE";
            row["symbol"]     = ccy1 + ccy2;
            row["instr"]      = CCY_PAIRS[i];
            row["secid"]      = i;
            row["xchg_secid"] = 1000 + i;
            row["ccy"]        = ccy1;
            row["settl_ccy"]  = ccy2;

            row["contr_mult"] = 1.0d;
            row["px_step"]    = 10e-5d;

            Assert.IsNull(row.Validate());

            var affected = store.Insert(row);
            Assert.AreEqual(1, affected);
              }

              var qry = new Query("CRUD.SecDef.ByExchange")
              {
              new Query.Param("Exchange", "CLE")
              };

              var data = store.LoadOneRowset(qry);

              Assert.IsNotNull(data);

              Console.WriteLine(data.ToJSON(JSONWritingOptions.PrettyPrintRowsAsMap));

              Assert.AreEqual(CCY_PAIRS.Length, data.Count);
        }
Esempio n. 5
0
        /// <summary>
        /// Convert an Erlang hierarchical term representing a schema to a Row.
        /// </summary>
        /// <param name="row">Row to update</param>
        /// <param name="data">
        ///   Data to update row with.
        ///   The data must be in the form {SchemaName::atom, [{FieldName::atom(), Value}]}.
        /// </param>
        /// <param name="schema">Alternative schema to use in place of row.Schema</param>
        /// <param name="targetName">Name of the target for looking up field attributes</param>
        /// <param name="schemaName">Alternative name of the top-most 'SchemaName' atom used in the "data".</param>
        /// <param name="knownSchemas">List of known schemas to use when initializing a field a DynamicRow type.</param>
        public static void Update(this Row row, IErlObject data, Schema schema = null, string targetName = null,
            string schemaName = null, Registry<Schema> knownSchemas = null)
        {
            if (schema == null)
            schema = row.Schema;

              if (schemaName == null)
            schemaName = schema.Name;

              if (data == null)
            data = new ErlTuple(new ErlAtom(schemaName), new ErlList());

              // Input data must be in the form: {SchemaName::atom(), [{FieldName::atom(), Value}]}
              // where Value can be any primitive value or a hierarchical value with another Row type.
              if (!checkKeyValueTuple(data) || ((ErlTuple)data)[1].TypeOrder != ErlTypeOrder.ErlList)
            throw new ErlDataAccessException(
              StringConsts.ERL_DS_CRUD_RESP_SCH_MISMATCH_ERROR.Args(data.ToString(), schema.Name));

              var dataList = ((ErlTuple)data)[1] as ErlList;

              // Make sure that the first element of the tuple matches the schema name
              if (!((ErlTuple)data)[0].ValueAsString.Equals(schemaName))
            throw new ErlDataAccessException(
              StringConsts.ERL_DS_CRUD_RESP_SCH_MISMATCH_ERROR.Args(data.ToString(), schema.Name));

              // Contains a set of field names that are present in configuration
              var presentFieldNames = new HashSet<string>();
              foreach (var item in dataList.Where(checkKeyValueTuple).Cast<ErlTuple>())
            presentFieldNames.Add(item[0].ValueAsString);

              ErlList newList = null;

              foreach (var fld in schema.Where(fd => typeof(Row).IsAssignableFrom(fd.Type)))
            if (!presentFieldNames.Contains(fld.Name))
            {
              if (newList == null)
            newList = (ErlList)dataList.Clone();
              // Add: {FieldName::atom(), []}
              newList.Add(new ErlTuple(new ErlAtom(fld.Name), new ErlList()));
            }

              // If no new items were added to the list use current list:
              if (newList == null) newList = dataList;

              foreach (var item in newList.Where(checkKeyValueTuple).Cast<ErlTuple>())
              {
            var name  = item[0].ValueAsString;
            var value = item[1];
            var fdef  = schema[name];
            var attr  = fdef[targetName];

            if (!attr.Visible || (attr.Metadata != null && attr.Metadata.Navigate("$readonly|$read-only|$read_only").ValueAsBool()))
              continue;

            // If this field is defined in the schema as a Row type, then we need to descend into the
            // value's hierarchical structure and treat it as a nested row
            if (typeof(Row).IsAssignableFrom(fdef.Type))
            {
              // Get the row associated
              Schema chldSch;
              var chldRow = row[fdef.Order] as Row;

              // If the row has a field of Row type initialized, use its Schema value.
              if (chldRow != null)
            chldSch = chldRow.Schema;
              else
              {
            // Otherwise lookup the schema from the given registry
            if (!knownSchemas.TryGetValue(name, out chldSch))
              throw new ErlDataAccessException(
                StringConsts.ERL_DS_SCHEMA_NOT_KNOWN_ERROR.Args(name, data.ToString()));
            // Construct the field's value as dynmiac row of the looked up schema type
            chldRow = new DynamicRow(chldSch);
            chldRow.ApplyDefaultFieldValues();
            row[fdef.Order] = chldRow;
              }

              if (value.TypeOrder != ErlTypeOrder.ErlList)
            throw new ErlDataAccessException(
              StringConsts.ERL_DS_SCHEMA_INVALID_VALUE_ERROR.Args(chldSch.Name, value));

              // Recursively update the field's value from given data by using the field's schema:
              chldRow.Update(item, chldSch, targetName, knownSchemas: knownSchemas);
            }
            else
            {
              // This is a primitive value type
              var clr = SchemaMap.ErlToClrValue(value, schema, fdef, null, data);
              row.SetFieldValue(fdef, clr);
            }
              }
        }