当前位置: 首页>>代码示例>>Java>>正文


Java ObjectId.toHexString方法代码示例

本文整理汇总了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.");
    }
}
 
开发者ID:welkinbai,项目名称:BsonMapper,代码行数:10,代码来源:Utils.java

示例3: serialize

import org.bson.types.ObjectId; //导入方法依赖的package包/类
@Override
public JsonElement serialize(ObjectId objectId, Type type, JsonSerializationContext jsonSerializationContext) {
    return new JsonPrimitive(objectId.toHexString());
}
 
开发者ID:drakeet,项目名称:rebase-server,代码行数:5,代码来源:ObjectIdSerializer.java

示例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


注:本文中的org.bson.types.ObjectId.toHexString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。