コード例 #1
0
ファイル: CedarSessionTest.cs プロジェクト: Vadi/Cedar
        public void TestSave()
        {
            var cedarContext = Cedar.CedarAppStore.Instance.GetContextOf("IGD");
            long uid = 0;

            if (cedarContext.IsSetupSchemaRequired)
            {
                cedarContext.SetupSchema(new ShardStartegyData() { StrategyType = Strategy.Sequential });

            }
            uid = cedarContext.CurrentShard;

            long? uId = 0;

            var worker = new Cedar.IdWorker(uid);
            uId = worker.GetUniqueId();

            using (ICedarSession cedarSession = new Cedar.AppContext("IGD").GetSession(uId.Value))
            {
                var parameters = new DynamicParameters();
                parameters.Add("firstName", "TArun");
                parameters.Add("lastName", "Kumar");
                cedarSession.Insert("usp_addemployee", parameters, commandType: Cedar.CommandType.StoredProcedure);
            }
        }
コード例 #2
0
ファイル: AppContextTests.cs プロジェクト: Vadi/Cedar
        public void Test_SetupSchemaForCustomStartegy()
        {
            var ctx = CedarAppStore.Instance.GetContextOf("IGD");
            var strtgy = new RegionalStartegy();
            ctx.ShardStrategy = new RegionalStartegy();
            var uuid = ctx.SetupSchema(new ShardStartegyData() { StrategyType = Strategy.Regional,Region = "Prakash"});

            var worker = new IdWorker(1004);
            var uniqueId = worker.DecomposeKey(uuid);

            Assert.AreEqual(1004 == uniqueId, true, "shard id is not as expected");
        }
コード例 #3
0
ファイル: AppContext.cs プロジェクト: Vadi/Cedar
 /// <summary>
 /// Update the total count for a shard
 /// </summary>
 /// <param name="uuid"></param>
 public void UpdateShard(long uuid)
 {
     var worker = new IdWorker(uuid);
     var uniqueId = worker.DecomposeKey(uuid);
     new DataFactory().GetdataReader(FetchMode.Sql).UpdateShardCount(uniqueId);
     _app.Shards = new DataFactory().GetdataReader(FetchMode.Sql).GetAllShardByAppname(_app.ApplicationName);
 }
コード例 #4
0
ファイル: AppContext.cs プロジェクト: Vadi/Cedar
        /// <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;
        }