本文整理汇总了Java中org.bson.types.ObjectId.toHexString方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectId.toHexString方法的具体用法?Java ObjectId.toHexString怎么用?Java ObjectId.toHexString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bson.types.ObjectId
的用法示例。
在下文中一共展示了ObjectId.toHexString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clearAndPopulateDB
import org.bson.types.ObjectId; //导入方法依赖的package包/类
@Before
public void clearAndPopulateDB() throws IOException {
MongoClient mongoClient = new MongoClient();
MongoDatabase db = mongoClient.getDatabase("test");
MongoCollection<Document> userDocuments = db.getCollection("users");
userDocuments.drop();
List<Document> testUsers = new ArrayList<>();
testUsers.add(Document.parse("{\n" +
" name: \"Chris\",\n" +
" age: 25,\n" +
" company: \"UMM\",\n" +
" email: \"[email protected]\"\n" +
" }"));
testUsers.add(Document.parse("{\n" +
" name: \"Pat\",\n" +
" age: 37,\n" +
" company: \"IBM\",\n" +
" email: \"[email protected]\"\n" +
" }"));
testUsers.add(Document.parse("{\n" +
" name: \"Jamie\",\n" +
" age: 37,\n" +
" company: \"Frogs, Inc.\",\n" +
" email: \"[email protected]\"\n" +
" }"));
ObjectId samsId = new ObjectId();
BasicDBObject sam = new BasicDBObject("_id", samsId);
sam = sam.append("name", "Sam")
.append("age", 45)
.append("company", "Frogs, Inc.")
.append("email", "[email protected]");
samsIdString = samsId.toHexString();
userDocuments.insertMany(testUsers);
userDocuments.insertOne(Document.parse(sam.toJson()));
// It might be important to construct this _after_ the DB is set up
// in case there are bits in the constructor that care about the state
// of the database.
userController = new UserController("test");
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-2-spraguesanborn,代码行数:41,代码来源:UserControllerSpec.java
示例2: getObjectIdByRealType
import org.bson.types.ObjectId; //导入方法依赖的package包/类
public static Object getObjectIdByRealType(Class<?> fieldType, ObjectId objectId) {
if (fieldType == String.class || fieldType == StringObjectId.class) {
return objectId.toHexString();
} else if (fieldType == ObjectId.class) {
return objectId;
} else {
throw new BsonMapperConverterException("BsonValue ObjectId just can be converted to String or ObjectId.");
}
}
示例3: serialize
import org.bson.types.ObjectId; //导入方法依赖的package包/类
@Override
public JsonElement serialize(ObjectId objectId, Type type, JsonSerializationContext jsonSerializationContext) {
return new JsonPrimitive(objectId.toHexString());
}
示例4: clearAndPopulateDB
import org.bson.types.ObjectId; //导入方法依赖的package包/类
@Before
public void clearAndPopulateDB() throws IOException {
MongoClient mongoClient = new MongoClient();
MongoDatabase db = mongoClient.getDatabase("test");
MongoCollection<Document> flowerDocuments = db.getCollection("flowers");
flowerDocuments.drop();
List<Document> testFlowers = new ArrayList<>();
testFlowers.add(Document.parse("{\n" +
" _id: \"id-1\",\n" +
" commonName: \"tulip\",\n" +
" cultivar: \"cltv-tulip\",\n" +
" source: \"src-a\",\n" +
" gardenLocation: \"loc-1\",\n" +
" year: 2016\n" +
" }"));
testFlowers.add(Document.parse("{\n" +
" _id: \"id-2\",\n" +
" commonName: \"lily\",\n" +
" cultivar: \"cltv-lily\",\n" +
" source: \"src-a\",\n" +
" gardenLocation: \"loc-1\",\n" +
" year: 2016\n" +
" }"));
testFlowers.add(Document.parse("{\n" +
" _id: \"id-3\",\n" +
" commonName: \"daisy\",\n" +
" cultivar: \"cltv-daisy\",\n" +
" source: \"src-b\",\n" +
" gardenLocation: \"loc-2\",\n" +
" year: 2016\n" +
" }"));
ObjectId roseId = new ObjectId();
BasicDBObject rose = new BasicDBObject("_id", roseId);
rose = rose.append("commonName", "rose")
.append("cultivar", "cltv-rose")
.append("source", "src-b")
.append("gardenLocation", "loc-2")
.append("year", 2016);
roseIdString = roseId.toHexString();
flowerDocuments.insertMany(testFlowers);
flowerDocuments.insertOne(Document.parse(rose.toJson()));
// It might be important to construct this _after_ the DB is set up
// in case there are bits in the constructor that care about the state
// of the database.
flowerController = new FlowerController("test");
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-2-spraguesanborn,代码行数:48,代码来源:FlowerControllerSpec.java