コード例 #1
0
    [TestMethod()] public void TestLoadAndSaveRegion()
    {
        ModelContext.beginTrans();
        try {
            OracleMappers.RegionDBMapper pdb = new OracleMappers.RegionDBMapper();

            long count = pdb.RecordCount();

            if (pdb.SelectFromObjectName != pdb.ManagedTableName)
            {
                long countFromSelectObject = pdb.dbConn.getLngValue("select count(*) from " + pdb.SelectFromObjectName);
                Assert.AreEqual(count, countFromSelectObject,
                                "Count of records in managedTableName {0} and SelectFromObjectName {1} should be equal, as there needs to be exactly 1 to 1 match between records in managed table and selectFromObject.",
                                pdb.ManagedTableName, pdb.SelectFromObjectName);
            }

            if (count == 0)
            {
                Assert.Inconclusive("No Region in database, table is empty");
            }
            else
            {
                /**
                 * using (DataContext ctx = DBUtils.Current().dbContext()) {
                 *
                 *      var query = ctx.ExecuteQuery<Region>(@"SELECT * FROM " + pdb.SelectFromObjectName ).Skip(1).Take(1);
                 *      var lst = query.ToList();
                 *
                 *      Assert.AreEqual(lst.Count, 1, "Expected to receive 1 record, got: " + lst.Count);
                 *
                 * }
                 * todo: fix boolean fields by generating properties of original fields
                 **/
                object pid = ModelContext.CurrentDBUtils.getObjectValue("select top 1 " + pdb.pkFieldName + " from " + pdb.ManagedTableName);

                Region p  = pdb.findByKey(pid);
                Region p2 = (Region)p.copy();

                //Test equality and hash codes
                Assert.AreEqual(p.GetHashCode(), p2.GetHashCode());
                Assert.AreEqual(p, p2);

                p.isDirty = true;                  // force save
                pdb.save(p);

                // now reload object from database
                p = null;
                p = pdb.findByKey(pid);

                //test fields to be equal before and after save
                Assert.IsTrue(p.PrRegionId == p2.PrRegionId, "Expected Field RegionId to be equal");
                Assert.IsTrue(p.PrRegionName == p2.PrRegionName, "Expected Field RegionName to be equal");

                p.isDirty = true;                 //to force save
                ModelContext.Current.saveModelObject(p);

                p = ModelContext.Current.loadModelObject <Region>(p.Id);
                p.loadObjectHierarchy();

                string json = JsonConvert.SerializeObject(p, Formatting.Indented,
                                                          new JsonSerializerSettings()
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                });
                System.IO.FileInfo jf = new System.IO.FileInfo(".\\Region.json");
                System.IO.File.WriteAllText(jf.FullName, json);

                if (pdb.isPrimaryKeyAutogenerated)
                {
                    p.isNew   = true;
                    p.isDirty = true;

                    try {
                        pdb.save(p);
                    } catch (System.Exception e) {
                        Assert.IsTrue(e.Message.ToUpper().Contains("UNIQUE INDEX") || e.Message.Contains("Violation of UNIQUE KEY constraint"),
                                      "Insert statement produced error other than violation of unique key:" + e.Message);
                    }
                }
            }
        } finally {
            ModelContext.rollbackTrans(); // 'Nothing should be saved to the database!
        }
    }
コード例 #2
0
 public static List<Region> findList(string @where, List<IDataParameter> listOfIParams)
 {
     RegionDBMapper dbm = new RegionDBMapper();
     return dbm.findList(@where,listOfIParams);
 }
コード例 #3
0
 public static Region findOne(string @where, params object[] @params)
 {
     RegionDBMapper dbm = new RegionDBMapper();
     return (Region)dbm.findWhere(@where, @params);
 }
コード例 #4
0
 public static void deleteRegion(Region RegionObj)
 {
     RegionDBMapper dbm = new RegionDBMapper();
     dbm.delete(RegionObj);
 }
コード例 #5
0
 public static List<Region> findList(string @where, params object[] @params)
 {
     RegionDBMapper dbm = new RegionDBMapper();
     return dbm.findList(@where, @params);
 }
コード例 #6
0
        public static void deleteRegion(Region RegionObj)
        {
            RegionDBMapper dbm = new RegionDBMapper();

            dbm.delete(RegionObj);
        }
コード例 #7
0
 /// <summary>
 /// Convinience method to save a Region Object.
 /// Important note: DO NOT CALL THIS IN A LOOP!
 /// </summary>
 /// <param name="RegionObj"></param>
 /// <remarks>
 /// Important note: DO NOT CALL THIS IN A LOOP!  
 /// This method simply instantiates a RegionDBMapper and calls the save method
 /// </remarks>
 public static void saveRegion(params Region[] RegionObj)
 {
     RegionDBMapper dbm = new RegionDBMapper();
     dbm.saveList(RegionObj.ToList());
 }
コード例 #8
0
        /// <summary>
        /// Convinience method to save a Region Object.
        /// Important note: DO NOT CALL THIS IN A LOOP!
        /// </summary>
        /// <param name="RegionObj"></param>
        /// <remarks>
        /// Important note: DO NOT CALL THIS IN A LOOP!
        /// This method simply instantiates a RegionDBMapper and calls the save method
        /// </remarks>
        public static void saveRegion(params Region[] RegionObj)
        {
            RegionDBMapper dbm = new RegionDBMapper();

            dbm.saveList(RegionObj.ToList());
        }
コード例 #9
0
        public static Region findOne(string @where, params object[] @params)
        {
            RegionDBMapper dbm = new RegionDBMapper();

            return((Region)dbm.findWhere(@where, @params));
        }
コード例 #10
0
        public static List <Region> findList(string @where, List <IDataParameter> listOfIParams)
        {
            RegionDBMapper dbm = new RegionDBMapper();

            return(dbm.findList(@where, listOfIParams));
        }
コード例 #11
0
        public static List <Region> findList(string @where, params object[] @params)
        {
            RegionDBMapper dbm = new RegionDBMapper();

            return(dbm.findList(@where, @params));
        }
コード例 #12
0
    public void TestLoadAndSaveRegion()
    {
        ModelContext.beginTrans();
        try {

            OracleMappers.RegionDBMapper pdb = new OracleMappers.RegionDBMapper();

            long count = pdb.RecordCount();

            if (pdb.SelectFromObjectName != pdb.ManagedTableName) {
                long countFromSelectObject = pdb.dbConn.getLngValue("select count(*) from " + pdb.SelectFromObjectName);
                Assert.AreEqual(count, countFromSelectObject,
                    "Count of records in managedTableName {0} and SelectFromObjectName {1} should be equal, as there needs to be exactly 1 to 1 match between records in managed table and selectFromObject.",
                    pdb.ManagedTableName, pdb.SelectFromObjectName);
            }

            if (count == 0) {
                Assert.Inconclusive("No Region in database, table is empty");
            } else {
                /**
                using (DataContext ctx = DBUtils.Current().dbContext()) {

                    var query = ctx.ExecuteQuery<Region>(@"SELECT * FROM " + pdb.SelectFromObjectName ).Skip(1).Take(1);
                    var lst = query.ToList();

                    Assert.AreEqual(lst.Count, 1, "Expected to receive 1 record, got: " + lst.Count);

                }
                todo: fix boolean fields by generating properties of original fields
                **/
                object pid  = ModelContext.CurrentDBUtils.getObjectValue("select top 1 " + pdb.pkFieldName + " from " + pdb.ManagedTableName);

                Region p = pdb.findByKey(pid);
                Region p2 = (Region)p.copy();

                //Test equality and hash codes
                Assert.AreEqual(p.GetHashCode(), p2.GetHashCode());
                Assert.AreEqual(p, p2);

                p.isDirty = true ; // force save
                pdb.save(p);

                // now reload object from database
                p = null;
                p = pdb.findByKey(pid);

                //test fields to be equal before and after save
                Assert.IsTrue(p.PrRegionId==p2.PrRegionId,"Expected Field RegionId to be equal");
                Assert.IsTrue(p.PrRegionName==p2.PrRegionName,"Expected Field RegionName to be equal");

                p.isDirty = true; //to force save
                ModelContext.Current.saveModelObject(p);

                p = ModelContext.Current.loadModelObject< Region >(p.Id);
                p.loadObjectHierarchy();

                string json = JsonConvert.SerializeObject(p,Formatting.Indented,
                    new JsonSerializerSettings(){
                            ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                        });
                System.IO.FileInfo jf = new System.IO.FileInfo(".\\Region.json");
                System.IO.File.WriteAllText(jf.FullName,json);

                if (pdb.isPrimaryKeyAutogenerated) {
                    p.isNew = true;
                    p.isDirty = true;

                    try {
                        pdb.save(p);
                    } catch (System.Exception e) {
                        Assert.IsTrue(e.Message.ToUpper().Contains("UNIQUE INDEX")||e.Message.Contains("Violation of UNIQUE KEY constraint"),
                            "Insert statement produced error other than violation of unique key:"+e.Message);

                    }
                }

            }

        } finally {
            ModelContext.rollbackTrans(); // 'Nothing should be saved to the database!
        }
    }