本文整理汇总了C++中OID::init方法的典型用法代码示例。如果您正苦于以下问题:C++ OID::init方法的具体用法?C++ OID::init怎么用?C++ OID::init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OID
的用法示例。
在下文中一共展示了OID::init方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: construct
void OIDInfo::construct(JSContext* cx, JS::CallArgs args) {
OID oid;
if (args.length() == 0) {
oid.init();
} else {
auto str = ValueWriter(cx, args.get(0)).toString();
Scope::validateObjectIdString(str);
oid.init(str);
}
make(cx, oid, args.rval());
}
示例2: testoid
void testoid() {
OID id;
id.init();
// sleepsecs(3);
OID b;
// goes with sleep above...
// b.init();
// assert( memcmp(id.getData(), b.getData(), 12) < 0 );
b.init( id.str() );
assert( b == id );
}
示例3: getoid
BSONObj StorageEngine::getoid(string oid) {
OID oidobj;
oidobj.init(oid);
BSONObjBuilder ob;
ob.appendOID("_id",&oidobj);
return ob.obj();
}
示例4: ObjectId
ObjectId() : ns_( testNs( this ) ) {
OID id;
for( int i = 0; i < 100000; ++i ) {
id.init();
client_->insert( ns_.c_str(), BSON( "a" << id ) );
}
}
示例5: log
bool HealthLog::log(const HealthLogEntry& entry) {
BSONObjBuilder builder;
OID oid;
oid.init();
builder.append("_id", oid);
entry.serialize(&builder);
return _writer.insertDocument(builder.obj());
}
示例6: object_id_constructor
JSBool object_id_constructor( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval ){
Convertor c( cx );
OID oid;
if ( argc == 0 ){
oid.init();
}
else {
uassert( "object_id_constructor can't take more than 1 param" , argc == 1 );
oid.init( c.toString( argv[0] ) );
}
jsval v = c.toval( oid.str().c_str() );
assert( JS_SetProperty( cx , obj , "str" , &v ) );
return JS_TRUE;
}
示例7: toOID
OID toOID( jsval v ) {
JSContext * cx = _context;
assert( JSVAL_IS_OID( v ) );
JSObject * o = JSVAL_TO_OBJECT( v );
OID oid;
oid.init( getString( o , "str" ) );
return oid;
}
示例8: expectConfigCollectionInsert
void ShardingTestFixture::expectConfigCollectionInsert(const HostAndPort& configHost,
StringData collName,
Date_t timestamp,
const std::string& what,
const std::string& ns,
const BSONObj& detail) {
onCommand([&](const RemoteCommandRequest& request) {
ASSERT_EQUALS(configHost, request.target);
ASSERT_EQUALS("config", request.dbname);
BatchedInsertRequest actualBatchedInsert;
std::string errmsg;
ASSERT_TRUE(actualBatchedInsert.parseBSON(request.dbname, request.cmdObj, &errmsg));
ASSERT_EQ("config", actualBatchedInsert.getNS().db());
ASSERT_EQ(collName, actualBatchedInsert.getNS().coll());
auto inserts = actualBatchedInsert.getDocuments();
ASSERT_EQUALS(1U, inserts.size());
const ChangeLogType& actualChangeLog = assertGet(ChangeLogType::fromBSON(inserts.front()));
ASSERT_EQUALS(operationContext()->getClient()->clientAddress(true),
actualChangeLog.getClientAddr());
ASSERT_EQUALS(detail, actualChangeLog.getDetails());
ASSERT_EQUALS(ns, actualChangeLog.getNS());
ASSERT_EQUALS(network()->getHostName(), actualChangeLog.getServer());
ASSERT_EQUALS(timestamp, actualChangeLog.getTime());
ASSERT_EQUALS(what, actualChangeLog.getWhat());
// Handle changeId specially because there's no way to know what OID was generated
std::string changeId = actualChangeLog.getChangeId();
size_t firstDash = changeId.find("-");
size_t lastDash = changeId.rfind("-");
const std::string serverPiece = changeId.substr(0, firstDash);
const std::string timePiece = changeId.substr(firstDash + 1, lastDash - firstDash - 1);
const std::string oidPiece = changeId.substr(lastDash + 1);
ASSERT_EQUALS(grid.getNetwork()->getHostName(), serverPiece);
ASSERT_EQUALS(timestamp.toString(), timePiece);
OID generatedOID;
// Just make sure this doesn't throws and assume the OID is valid
generatedOID.init(oidPiece);
BatchedCommandResponse response;
response.setOk(true);
return response.toBSON();
});
}
示例9: insert
void insert( const BSONObj &o ) {
if ( o["_id"].eoo() ) {
BSONObjBuilder b;
OID oid;
oid.init();
b.appendOID( "_id", &oid );
b.appendElements( o );
_collection->insertDocument( &_txn, b.obj(), false );
}
else {
_collection->insertDocument( &_txn, o, false );
}
}
示例10: objectIdInit
v8::Handle<v8::Value> objectIdInit( const v8::Arguments& args ){
v8::Handle<v8::Object> it = args.This();
if ( it->IsUndefined() || it == v8::Context::GetCurrent()->Global() ){
v8::Function * f = getObjectIdCons();
it = f->NewInstance();
}
OID oid;
if ( args.Length() == 0 ){
oid.init();
}
else {
string s = toSTLString( args[0] );
oid.init( s );
}
it->Set( String::New( "str" ) , String::New( oid.str().c_str() ) );
return it;
}
示例11: buildFile
BSONObj GridFileBuilder::buildFile(const string &name,
const string& content_type) {
privateAppendPendingData();
/* from gridfs.cpp at https://github.com/mongodb/mongo-cxx-driver/blob/legacy/src/mongo/client/gridfs.cpp */
// Wait for any pending writebacks to finish
BSONObj errObj = _client->getLastErrorDetailed();
uassert( 16428,
str::stream() << "Error storing GridFS chunk for file: " << name
<< ", error: " << errObj,
DBClientWithCommands::getLastErrorString(errObj) == "" );
BSONObj res;
if ( ! _client->runCommand( _dbName.c_str() ,
BSON( "filemd5" << _file_id << "root" << _prefix ) ,
res ) )
throw UserException( 9008 , "filemd5 failed" );
BSONObjBuilder file;
file << "_id" << _file_id["_id"]
<< "filename" << name
<< "chunkSize" << (unsigned int)_chunkSize
<< "uploadDate" << DATENOW
<< "md5" << res["md5"]
;
if (_file_length < 1024*1024*1024) { // 2^30
file << "length" << (int) _file_length;
}
else {
file << "length" << (long long) _file_length;
}
if (!content_type.empty())
file << "contentType" << content_type;
BSONObj ret = file.obj();
_client->insert(_filesNS.c_str(), ret);
// resets the object
_current_chunk = 0;
_pending_data = NULL;
_pending_data_size = 0;
_file_length = 0;
OID id;
id.init();
_file_id = BSON("_id" << id);
return ret;
}
示例12: _shouldIBalance
bool Balancer::_shouldIBalance( DBClientBase& conn ){
BSONObj x = conn.findOne( ShardNS::settings , BSON( "_id" << "balancer" ) );
log(2) << "balancer: " << x << endl;
if ( ! x.isEmpty() ){
if ( x["who"].String() == _myid ){
log(2) << "balancer: i'm the current balancer" << endl;
return true;
}
BSONObj other = conn.findOne( ShardNS::mongos , x["who"].wrap( "_id" ) );
massert( 13125 , (string)"can't find mongos: " + x["who"].String() , ! other.isEmpty() );
int secsSincePing = (int)(( jsTime() - other["ping"].Date() ) / 1000 );
log(2) << "current balancer is: " << other << " ping delay(secs): " << secsSincePing << endl;
if ( secsSincePing < ( 60 * 10 ) ){
return false;
}
log() << "balancer: going to take over" << endl;
// we want to take over, so fall through to below
}
// Taking over means replacing 'who' with this balancer's address. Note that
// to avoid any races, we use a compare-and-set strategy relying on the
// incarnation of the previous balancer (the key 'x').
OID incarnation;
incarnation.init();
BSONObjBuilder updateQuery;
updateQuery.append( "_id" , "balancer" );
if ( x["x"].type() )
updateQuery.append( x["x"] );
else
updateQuery.append( "x" , BSON( "$exists" << false ) );
conn.update( ShardNS::settings ,
updateQuery.obj() ,
BSON( "$set" << BSON( "who" << _myid << "x" << incarnation ) ) ,
true );
// If another balancer beats this one to the punch, the following query will see
// the incarnation for that other guy.
x = conn.findOne( ShardNS::settings , BSON( "_id" << "balancer" ) );
log() << "balancer: after update: " << x << endl;
return _myid == x["who"].String() && incarnation == x["x"].OID();
}
示例13: aux
GridFileBuilder::GridFileBuilder(DBClientBase *client,
const string &dbName,
unsigned int chunkSize,
const string& prefix) :
_client(client), _dbName(dbName), _prefix(prefix), _chunkSize(chunkSize),
_current_chunk(0), _pending_data(NULL), _pending_data_size(0),
_file_length(0) {
_chunkNS = _dbName + "." + _prefix + ".chunks";
_filesNS = _dbName + "." + _prefix + ".files";
OID id;
id.init();
_file_id = BSON("_id" << id);
// forces to build the gridFS collections
GridFS aux(*client, dbName, prefix);
}
示例14: insert
void insert(const char* s) {
WriteUnitOfWork wunit(&_txn);
const BSONObj o = fromjson(s);
if (o["_id"].eoo()) {
BSONObjBuilder b;
OID oid;
oid.init();
b.appendOID("_id", &oid);
b.appendElements(o);
_collection->insertDocument(&_txn, b.obj(), false);
} else {
_collection->insertDocument(&_txn, o, false);
}
wunit.commit();
}
示例15: insert
void insert(const char* s) {
WriteUnitOfWork wunit(&_opCtx);
const BSONObj o = fromjson(s);
OpDebug* const nullOpDebug = nullptr;
if (o["_id"].eoo()) {
BSONObjBuilder b;
OID oid;
oid.init();
b.appendOID("_id", &oid);
b.appendElements(o);
_collection->insertDocument(&_opCtx, b.obj(), nullOpDebug, false);
} else {
_collection->insertDocument(&_opCtx, o, nullOpDebug, false);
}
wunit.commit();
}