protected QueryBase(Executer executer, JObject query) { string[] target = ((string)query.GetProperty("collection").Value).Split('.'); if (target.Count() != 2) { throw new AegisException(RoseResult.InvalidArgument, "Collection must be in {scheme_name}.{collection_name} format."); } ParentExecuter = executer; JsonQuery = (JObject)query.DeepClone(); Command = ((string)JsonQuery.GetProperty("cmd").Value).Trim(); SchemeName = target[0].Trim(); CollectionName = target[1].Trim(); Collection = SchemeCatalog.GetScheme(SchemeName)?.GetCollection(CollectionName); if (Collection == null) { throw new AegisException(RoseResult.InvalidArgument, $"Invalid scheme name({SchemeName})."); } var where = JsonQuery.GetProperty("where", false)?.Value; if (where != null) { Where = new Where(where); } }
private void collectionList(RequestHandlerArgument arg) { JObject json = JObject.Parse(arg.MessageBody); string schemeName = (string)json.GetProperty("scheme").Value; var scheme = SchemeCatalog.GetScheme(schemeName); var response = new JArray(); scheme.GetCollectionsInfo(ref response); arg.Response(response); }
private void sequenceNumber(RequestHandlerArgument arg) { JToken json = JToken.Parse(arg.MessageBody); var scheme = SchemeCatalog.GetScheme("rose"); var collection = scheme.GetCollection("sequenceNumbers"); string sequenceName = (string)json.GetProperty("name"); long increase = (long)(json.GetProperty("condition/increase", false)?.Value ?? 1); var result = sequenceNumber(sequenceName, increase); arg.Response(result); }
public RoseAPI() { try { // Collection이 없으면 생성 var scheme = SchemeCatalog.GetScheme("rose", true); if (scheme.GetCollection("sequenceNumbers", false) == null) { scheme.CreateCollection("sequenceNumbers", false); } } catch (Exception) { } }
public string Collection_EnterWriterLock(string schemeName, string collectionName) { try { Scheme scheme = SchemeCatalog.GetScheme(schemeName); Collection collection = scheme.GetCollection(collectionName); collection.WriterLock.Enter(); return(ResponseString(RoseResult.Ok, "Ok", null)); } catch (Exception e) { return(ResponseString(RoseResult.UnknownError, e.Message, null)); } }
private void createCollection(RequestHandlerArgument arg) { var json = JsonConverter.Parse(arg.MessageBody); var collection = (string)json.GetProperty("collection").Value; string[] target = collection.Split('.'); if (target.Count() != 2) { throw new AegisException(Engine.RoseResult.InvalidArgument, "Collection must be in {scheme_name}.{collection_name} format."); } bool justInCache = ((string)json.GetProperty("justInCache", false)?.Value ?? "false").ToBoolean(); var scheme = SchemeCatalog.GetScheme(target[0].Trim()); scheme.CreateCollection(target[1].Trim(), justInCache); arg.Response(null); }
public static JToken sequenceNumber(string sequenceName, long increase) { var scheme = SchemeCatalog.GetScheme("rose"); var collection = scheme.GetCollection("sequenceNumbers"); long seqNo; using (collection.WriterLock) { // sequenceName 이름의 데이터 확인 var token = Select("rose", "sequenceNumbers", $"{sequenceName} >= 0", null, null, 0, 1); if (token == null || token.Count() == 0) { // 없으면 생성 Insert(scheme.Name, collection.Name, null, new JObject() { { sequenceName, (long)0 } }); token = Select("rose", "sequenceNumbers", $"{sequenceName} >= 0", null, null, 0, 1); } // 값 증가 seqNo = (long)token.First().GetProperty(sequenceName).Value + increase; token.First().Replace(new JObject() { { sequenceName, seqNo } }); } return(new JObject() { { sequenceName, seqNo } }); }
protected override void InitEngine(TreeNode <string> config) { string ipAddress = config.GetValue("ipAddress", null); int port = config.GetValue("port", "3306").ToInt32(); string userId = config.GetValue("userId", null); string userPwd = config.GetValue("userPwd", null); string dbName = config.GetValue("dbName", null); string charSet = config.GetValue("charSet", "utf8"); int minDBCCount = config.GetValue("minDBCCount", "2").ToInt32(); int maxDBCCount = config.GetValue("maxDBCCount", "4").ToInt32(); if (ipAddress == null || userId == null || userPwd == null || dbName == null) { throw new AegisException(RoseResult.InvalidArgument, "Not enough arguments to connect MySql."); } // Select용 Pool _poolSelect = new ConnectionPool(ipAddress, port, charSet, dbName, userId, userPwd); _poolSelect.MaxDBCCount = maxDBCCount; _poolSelect.IncreasePool(minDBCCount); // Insert / Update / Delete용 pool _poolWork = new ConnectionPool(ipAddress, port, charSet, dbName, userId, userPwd); _poolWork.MaxDBCCount = 1; _poolWork.IncreasePool(1); _queueQuery = new Queue <DBCommand>(); _thread = new Thread(Run); _thread.Start(); // Load schemes using (var cmd = _poolSelect.NewCommand()) { cmd.CommandText.Append("select schemeName from schemes;"); cmd.Query(); while (cmd.Reader.Read()) { SchemeCatalog.AddScheme(cmd.Reader.GetString(0)); } } // Load collections List <Collection> collections = new List <Collection>(); using (var cmd = _poolSelect.NewCommand()) { cmd.CommandText.Append("select collectionName, schemeName, indexes from collections;"); cmd.Query(); while (cmd.Reader.Read()) { string collectionName = cmd.Reader.GetString(0); string schemeName = cmd.Reader.GetString(1); string indexes = cmd.Reader.GetString(2); var scheme = SchemeCatalog.GetScheme(schemeName); if (scheme == null) { Logger.Err("{0} scheme is not exists.", schemeName); continue; } var collection = scheme.AddCollection(collectionName); collections.Add(collection); // Add indexes if (indexes.Length > 1) { JArray indexArray = JArray.Parse(indexes); foreach (var index in indexArray) { string idx = (string)index; if (idx.Length > 0) { collection.AddIndexForInit(idx); } } } } } // Load collection data foreach (var collection in collections) { string tableName = $"{collection.ParentScheme.Name}_{collection.Name}"; Logger.Info("Loading {0}.{1} collection.", collection.ParentScheme.Name, collection.Name); using (var cmd = _poolSelect.NewCommand()) { cmd.CommandText.Append($"select objectId, data from {tableName};"); cmd.Query(); while (cmd.Reader.Read()) { string objectId = cmd.Reader.GetString(0); string data = cmd.Reader.GetString(1); collection.AddData(objectId, data); } } } }
public Collection GetCollection(string schemeName, string collectionName, bool raiseException) { var scheme = SchemeCatalog.GetScheme(schemeName, false); return(scheme.GetCollection(collectionName, raiseException)); }
public Collection CreateCollection(string schemeName, string collectionName, bool justInCache) { var scheme = SchemeCatalog.GetScheme(schemeName, false); return(scheme.CreateCollection(collectionName, justInCache)); }
public Scheme GetScheme(string schemeName, bool createIfNotExists) { return(SchemeCatalog.GetScheme(schemeName, createIfNotExists)); }