public void MyTestInitialize() { sdb = new Sequoiadb(config.conf.Coord.Address); sdb.Connect(config.conf.UserName, config.conf.Password); if (sdb.IsCollectionSpaceExist(csName)) sdb.DropCollectionSpace(csName); cs = sdb.CreateCollectionSpace(csName); coll = cs.CreateCollection(cName); }
internal DBLob(DBCollection cl) { this._cl = cl; this._connection = cl.CollSpace.SequoiaDB.Connection; this._isBigEndian = cl.isBigEndian; _id = ObjectId.Empty; _mode = -1; _size = 0; _readOffset = -1; _createTime = 0; _isOpen = false; _contextID = -1; }
internal DBCursor(SDBMessage rtnSDBMessage, DBCollection dbc) { this.dbc = dbc; connection = dbc.CollSpace.SequoiaDB.Connection; hint = new BsonDocument(); hint.Add("", SequoiadbConstants.CLIENT_RECORD_ID_INDEX); sdbMessage = new SDBMessage(); reqId = rtnSDBMessage.RequestID; sdbMessage.NodeID = SequoiadbConstants.ZERO_NODEID; sdbMessage.ContextIDList = rtnSDBMessage.ContextIDList; contextId = sdbMessage.ContextIDList[0]; sdbMessage.NumReturned = -1; // return data count list = rtnSDBMessage.ObjectList; // while using fineOne, ObjectList may have data hasMore = true; isBigEndian = dbc.isBigEndian; isClosed = false; }
public void MyTestInitialize() { try { sdb = new Sequoiadb(config.conf.Coord.Address); sdb.Connect(config.conf.UserName, config.conf.Password); if (sdb.IsCollectionSpaceExist(csName)) sdb.DropCollectionSpace(csName); cs = sdb.CreateCollectionSpace(csName); cl = cs.CreateCollection(cName); } catch (BaseException e) { Console.WriteLine("Failed to Initialize in DBLobTest, ErrorType = {0}", e.ErrorType); Environment.Exit(0); } }
static void FindSpecificRecord(DBCollection dbc) { BsonDocument query = null; try { query = new BsonDocument { { "Id", 50 } }; } catch (Exception e) { Console.WriteLine("Failed to create specific record query condition"); Console.WriteLine(e.Message); return; } // new an empty bson object BsonDocument dummy = new BsonDocument(); Console.WriteLine("Find specific record from collection"); Common.FindRecord(dbc, query, dummy, dummy, dummy, 0, -1); }
public static void GetCount(DBCollection dbc, BsonDocument condition) { try { long result = dbc.GetCount(condition); Console.WriteLine("There are totally {0} records matches the condition", result); } catch (BaseException e) { Console.WriteLine("Failed to get count for query, ErrorType = {0}", e.ErrorType); return; } catch (Exception e) { Console.WriteLine(e.Message); Environment.Exit(0); } }
public static void FindRecord(DBCollection dbc, BsonDocument query, BsonDocument selector, BsonDocument orderBy, BsonDocument hint, long skip, long numReturn) { try { // find specific records from collection with rules DBCursor cursor = dbc.Query(query, selector, orderBy, hint, skip, numReturn); Console.WriteLine("Record read:"); while ( cursor.Next() != null ) Console.WriteLine(cursor.Current().ToString()); } catch (BaseException e) { Console.WriteLine("Failed to find records from collection, ErrorType = {0}", e.ErrorType); return; } catch (Exception e) { Console.WriteLine(e.Message); Environment.Exit(0); } }
public static void FindRecord(DBCollection dbc, DBQuery query) { try { // find specific records from collection with DBQuery DBCursor cursor = dbc.Query(query); Console.WriteLine("Record read:"); while ( cursor.Next() != null ) Console.WriteLine(cursor.Current().ToString()); } catch (BaseException e) { Console.WriteLine("Failed to find records from collection, ErrorType = {0}", e.ErrorType); return; } catch (Exception e) { Console.WriteLine(e.Message); Environment.Exit(0); } }
static void GetNumofRowsCondition(DBCollection dbc) { BsonDocument condition = null; try { condition = new BsonDocument { {"Id", new BsonDocument { {"$gte", 50}, {"$lte", 70} } } }; } catch (Exception e) { Console.WriteLine("Failed to create query condition"); Console.WriteLine(e.Message); return; } Console.WriteLine("Get count for query"); Common.GetCount(dbc, condition); }
// create index on a given collection public static void CreateIndex(DBCollection dbc, string indexName, BsonDocument key, bool isUnique, bool isEnforced ) { try { dbc.CreateIndex(indexName, key, isUnique, isEnforced); } catch (BaseException e) { Console.WriteLine("Failed to create index, ErrorType = {1}", e.ErrorType); Environment.Exit(0); } catch (Exception e) { Console.WriteLine(e.Message); Environment.Exit(0); } }
static void FindRecordsUsingHintIXScan(DBCollection dbc) { DBQuery query = new DBQuery(); try { BsonDocument condition = new BsonDocument { {"Id", new BsonDocument { {"$gte", 50}, {"$lte", 70} } } }; query.Matcher = condition; } catch (Exception e) { Console.WriteLine("Failed to create query condition"); Console.WriteLine(e.Message); return; } try { // provide index name for index scan BsonDocument hint = new BsonDocument { { "", indexName } }; query.Hint = hint; } catch (Exception e) { Console.WriteLine("Failed to create hint"); Console.WriteLine(e.Message); return; } Console.WriteLine("Find records using index scan"); Common.FindRecord(dbc, query); }
static void FindRecordsFields(DBCollection dbc) { DBQuery query = new DBQuery(); try { BsonDocument condition = new BsonDocument { {"Id", new BsonDocument { {"$gte", 50}, {"$lte", 70} } } }; query.Matcher = condition; } catch (Exception e) { Console.WriteLine("Failed to create query condition"); Console.WriteLine(e.Message); return; } try { BsonDocument selector = new BsonDocument { {"id", ""}, {"FirstName", ""}, {"LastName", ""}, {"PhoneNumber", ""} }; query.Selector = selector; } catch (Exception e) { Console.WriteLine("Failed to create fields selector"); Console.WriteLine(e.Message); return; } Console.WriteLine("Find specific fields from Collection"); Common.FindRecord(dbc, query); }
static void FindRangeRecords(DBCollection dbc) { DBQuery query = new DBQuery(); try { BsonDocument condition = new BsonDocument { {"Id", new BsonDocument { {"$gte", 25}, {"$lte", 30} } } }; query.Matcher = condition; } catch (Exception e) { Console.WriteLine("Failed to create range record query condition"); Console.WriteLine(e.Message); return; } Console.WriteLine("Find range records from collection"); Common.FindRecord(dbc, query); }
static void FindAllRecords(DBCollection dbc) { Console.WriteLine("Find all records from collection"); Common.FindRecord(dbc); }
public static void DeleteRecords(DBCollection dbc, BsonDocument condition, BsonDocument hint) { try { dbc.Delete(condition, hint); } catch (BaseException e) { Console.WriteLine("Failed to delete records from collection {0}, ErrorType = {1}", dbc.Name, e.ErrorType); Environment.Exit(0); } catch (Exception e) { Console.WriteLine(e.Message); Environment.Exit(0); } }
static void FindSortedRecords(DBCollection dbc) { DBQuery query = new DBQuery(); try { BsonDocument condition = new BsonDocument { {"Id", new BsonDocument { {"$gte", 50}, {"$lte", 70} } } }; query.Matcher = condition; } catch (Exception e) { Console.WriteLine("Failed to create query condition"); Console.WriteLine(e.Message); return; } try { BsonDocument orderBy = new BsonDocument { { "id", -1 } }; query.OrderBy = orderBy; } catch (Exception e) { Console.WriteLine("Failed to create orderBy clause"); Console.WriteLine(e.Message); return; } Console.WriteLine("Find ordered data ( by \"id\" in DESC order ) from Collection"); Common.FindRecord(dbc, query); }
// get index on a given collection public static BsonDocument GetIndex(DBCollection dbc, string indexName) { DBCursor cursor = null; try { cursor = dbc.GetIndex(indexName); } catch (BaseException e) { Console.WriteLine("Failed to get index {0} from collection, ErrorType = {1}", indexName, e.ErrorType); Environment.Exit(0); } catch (Exception e) { Console.WriteLine(e.Message); Environment.Exit(0); } return cursor.Next(); }
static void FindTotalNumRecords(DBCollection dbc) { BsonDocument condition = new BsonDocument(); Console.WriteLine("Get total number of records for collection"); Common.GetCount(dbc, condition); }
public void AlterCollectionTest() { DBCollection coll = null; BsonDocument options = null; string clName_alter = "alterCLTest"; string fullName = null; int partition = 0; string type = null; int rs = -1; coll = cs.CreateCollection(clName_alter); fullName = coll.CollSpace.Name + "." + clName_alter; // alter collecton attrubute options = new BsonDocument { {"ReplSize", 0}, {"ShardingKey", new BsonDocument{{"a",1}}}, {"ShardingType", "hash"}, {"Partition", 4096} }; coll.Alter(options); // check BsonDocument matcher = new BsonDocument { {"Name", fullName} }; DBCursor cur = sdb.GetSnapshot(8, matcher, null, null ); BsonDocument obj = cur.Next(); if (null == obj) { Assert.Fail(); } try { rs = obj["ReplSize"].AsInt32; Assert.IsTrue(7 == rs); partition = obj["Partition"].AsInt32; Assert.IsTrue(4096 == partition); type = obj["ShardingType"].AsString; Assert.IsTrue(type.Equals("hash")); } catch(System.Exception) { Assert.Fail(); } }
/* \fn void UpdateCurrent(BsonDocument modifier) * \brief Update the current Bson of this cursor * \param modifier The updating rule * \exception SequoiaDB.BaseException * \exception System.Exception */ /* public void UpdateCurrent(BsonDocument modifier) { if (modifier == null) throw new BaseException("SDB_INVALIDARG"); if (dbc == null) throw new BaseException("SDB_CLT_OBJ_NOT_EXIST"); BsonDocument current; if (( current = Current()) != null ) { BsonDocument matcher = new BsonDocument(); matcher.Add(SequoiadbConstants.OID, current[SequoiadbConstants.OID].AsObjectId); dbc.Update(matcher, modifier, hint); BsonDocument dummy = new BsonDocument(); list[index] = dbc.Query(matcher, dummy, dummy, dummy).Next(); } } */ /* \fn void DeleteCurrent() * \brief Delete the current Bson of this cursor * \exception SequoiaDB.BaseException * \exception System.Exception */ /* public void DeleteCurrent() { if ( Current() != null ) dbc.Delete( list[index] ); list.RemoveAt(index); if (index >= list.Count) index = -1; } */ private void ReadNextBuffer() { if (connection == null) { throw new BaseException("SDB_NOT_CONNECTED"); } if (-1 == contextId) { hasMore = false; index = -1; dbc = null; list = null; return; } sdbMessage.OperationCode = Operation.OP_GETMORE; sdbMessage.RequestID = reqId; byte[] request = SDBMessageHelper.BuildGetMoreRequest(sdbMessage, isBigEndian); connection.SendMessage(request); SDBMessage rtnSDBMessage = SDBMessageHelper.MsgExtractReply(connection.ReceiveMessage(isBigEndian), isBigEndian); rtnSDBMessage = SDBMessageHelper.CheckRetMsgHeader(sdbMessage, rtnSDBMessage); int flags = rtnSDBMessage.Flags; if (flags == SequoiadbConstants.SDB_DMS_EOC) { hasMore = false; index = -1 ; dbc = null ; list = null; } else if (flags != 0) { throw new BaseException(flags); } else { reqId = rtnSDBMessage.RequestID; list = rtnSDBMessage.ObjectList; } }