Exemplo n.º 1
0
        /// <summary>
        /// this method will set up schema for new user, will return unique id to application
        /// </summary>
        /// <returns></returns>
        public long SetupSchema(ShardStartegyData dto)
        {
            // call ShardStrategy with app name
            // Strategy will return me shardid.
            // call cedar data method which would execute schema def statements in above shard id

            var dataReader = new DataFactory().GetdataReader(FetchMode.Sql);
            dto.App = _app;
            var shardId = ShardStrategy.ShardSelectionStrategy.SelectShardIdForExistingObject(dto);

            var worker = new IdWorker(shardId);
            var uniqueId = worker.GetUniqueId();
            //_currentShard = uniqueId;
            var appSchema = dataReader.GetAppSchema(shardId);

            var cedarSession = new CedarSession(uniqueId) { EnableTrasaction = true };
            cedarSession.SetupSchema(appSchema);
            cedarSession.Close();
            new DataFactory().GetdataReader(FetchMode.Sql).UpdateShard(shardId);
            _app.Shards = new DataFactory().GetdataReader(FetchMode.Sql).GetAllShardByAppname(_app.ApplicationName);
            return uniqueId;
        }
Exemplo n.º 2
0
        public void Whether_Cedardb_Execute_Query()
        {
            var uuid = 174931025376227328;
            using (var cedarSession = new CedarSession(uuid))
            {

                Assert.AreNotEqual(null, "Cedar session is not null, cedar connection opened");

                var ctr =
                    cedarSession.Insert(
                        "insert into employee_" + uuid +
                        " (first_name,last_name,address) values (@FirstName,@LastName,@Address)", new[]
                                                                                                      {
                                                                                                          new
                                                                                                              {
                                                                                                                  FirstName
                                                                                                              = "Tarun",
                                                                                                                  LastName
                                                                                                              = "Kumar",
                                                                                                                  Address
                                                                                                              =
                                                                                                              "C-25 Noida"
                                                                                                              },
                                                                                                          new
                                                                                                              {
                                                                                                                  FirstName
                                                                                                              =
                                                                                                              "Parkash",
                                                                                                                  LastName
                                                                                                              = "Bhatt",
                                                                                                                  Address
                                                                                                              =
                                                                                                              "C-25 Noida"
                                                                                                              },
                                                                                                          new
                                                                                                              {
                                                                                                                  FirstName
                                                                                                              = "Hemant",
                                                                                                                  LastName
                                                                                                              = "Kumar",
                                                                                                                  Address
                                                                                                              =
                                                                                                              "C-25 Noida"
                                                                                                              },
                                                                                                          new
                                                                                                              {
                                                                                                                  FirstName
                                                                                                              =
                                                                                                              "Gurpreet",
                                                                                                                  LastName
                                                                                                              = "Kaur",
                                                                                                                  Address
                                                                                                              =
                                                                                                              "C-25 Noida"
                                                                                                              },
                                                                                                      },
                        Cedar.CommandType.Query);
                Assert.AreEqual(4, ctr, "4 rows inserted");

                cedarSession.Close();
            }
        }
Exemplo n.º 3
0
        public void Whether_Ceder_Update_Query_Work()
        {
            var uuid = 174103530611572736;
            var cedarSession = new CedarSession(uuid );
            Assert.AreNotEqual(null, "Cedar session is not null, cedar connection opened");

            var ctr = cedarSession.Select("select * from employee_"+uuid, null, Cedar.CommandType.Query);
            Assert.AreEqual(4, ctr.Count(), "4 Rows selected");

            var address = "C-25 New Delhi";
            cedarSession.Update("update employee_" + uuid + " set address=@Address where first_name=@FirstName", new { FirstName = "Prakash", Address = address }, Cedar.CommandType.Query);

            ctr = cedarSession.Select("select address from employee__" + uuid + " where first_name=@FirstName", new { FirstName = "Prakash" }, Cedar.CommandType.Query);
            Assert.AreEqual(address,ctr, "Changed adress updated");
            cedarSession.Close();
        }
Exemplo n.º 4
0
        public void Whether_Ceder_Select_Query_Work()
        {
            var uuid = 174103530611572736;
            var cedarSession = new CedarSession(uuid );
            Assert.AreNotEqual(null, "Cedar session is not null, cedar connection opened");

            var ctr = cedarSession.Select("select * from employee_"+uuid, null, Cedar.CommandType.Query);
            Assert.AreEqual(4, ctr.Count(), "4 Rows selected");

            ctr = cedarSession.Select("select * from employee_"+uuid+" where first_name=@FirstName", new { FirstName = "Tarun" }, Cedar.CommandType.Query);
            Assert.AreEqual(1, ctr.Count(), "1 Rows selected");
            cedarSession.Close();
        }
Exemplo n.º 5
0
        public void Whether_Cedardb_SqlConnection_Opened()
        {
            var cedarSession = new CedarSession(174103530611572736);

            Assert.AreNotEqual(null,"Cedar session is not null, cedar connection opened");

            cedarSession.Close();
        }
Exemplo n.º 6
0
        public void SetupSchema(long shardId, long uuid)
        {
            var app = new App();
            var shard = GetShardById(shardId);

            var connectionString = shard.connection_string;

            var appSchema = GetAppSchema(shard.application_name);

            app.AppId = uuid;
            app.ApplicationName = shard.application_name;
            app.Shards.Add(shard);

            var cedarSession = new CedarSession(shardId);
            cedarSession.EnableTrasaction = true;
            cedarSession.SetupSchema(appSchema);
            cedarSession.Close();
        }