Java 类org.bson.BsonMaxKey 实例源码

项目:embulk-input-mongodb    文件:TestMongodbInputPlugin.java   
@Test(expected = ValueCodec.UnknownTypeFoundException.class)
public void testRunWithUnsupportedType() throws Exception
{
    ConfigSource config = Exec.newConfigSource()
            .set("uri", MONGO_URI)
            .set("collection", MONGO_COLLECTION)
            .set("stop_on_invalid_record", true);

    PluginTask task = config.loadConfig(PluginTask.class);

    dropCollection(task, MONGO_COLLECTION);
    createCollection(task, MONGO_COLLECTION);

    List<Document> documents = new ArrayList<>();
    documents.add(
        new Document("invalid_field", new BsonMaxKey())
    );
    insertDocument(task, documents);

    plugin.transaction(config, new Control());
}
项目:BsonMapper    文件:BsonMaxKeyConverter.java   
@Override
public BsonMaxKey encode(MaxKey object) {
    return new BsonMaxKey();
}
项目:restheart    文件:JsonUtils.java   
public static boolean checkType(Optional<BsonValue> o, String type) {
    if (!o.isPresent() && !"null".equals(type) && !"notnull".equals(type)) {
        return false;
    }

    switch (type.toLowerCase().trim()) {
        case "null":
            return !o.isPresent();
        case "notnull":
            return o.isPresent();
        case "object":
            return o.get().isDocument();
        case "array":
            return o.get().isArray();
        case "string":
            return o.get().isString();
        case "number":
            return o.get().isNumber();
        case "boolean":
            return o.get().isBoolean();
        case "objectid":
            return o.get().isObjectId();
        case "objectidstring":
            return o.get().isString()
                    && ObjectId.isValid(o.get().asString().getValue());
        case "date":
            return o.get().isDateTime();
        case "timestamp":
            return o.get().isTimestamp();
        case "maxkey":
            return o.get() instanceof BsonMaxKey;
        case "minkey":
            return o.get() instanceof BsonMinKey;
        case "symbol":
            return o.get().isSymbol();
        case "code":
            return o.get() instanceof BsonJavaScript;
        default:
            return false;
    }
}
项目:restheart    文件:URLUtils.java   
/**
 * Gets the id as object from its string representation in the document URI
 * NOTE: for POST the special string id are checked by
 * BodyInjectorHandler.checkSpecialStringId()
 *
 * @param id
 * @param type
 * @return
 * @throws UnsupportedDocumentIdException
 */
public static BsonValue getDocumentIdFromURI(String id, DOC_ID_TYPE type)
        throws UnsupportedDocumentIdException {
    if (id == null) {
        return null;
    }

    if (type == null) {
        type = DOC_ID_TYPE.STRING_OID;
    }

    // MaxKey can be also determined from the _id
    if (RequestContext.MAX_KEY_ID.equalsIgnoreCase(id)) {
        return new BsonMaxKey();
    }

    // MaxKey can be also determined from the _id
    if (RequestContext.MIN_KEY_ID.equalsIgnoreCase(id)) {
        return new BsonMinKey();
    }

    // null can be also determined from the _id
    if (RequestContext.NULL_KEY_ID.equalsIgnoreCase(id)) {
        return new BsonNull();
    }

    // true can be also determined from the _id
    if (RequestContext.TRUE_KEY_ID.equalsIgnoreCase(id)) {
        return new BsonBoolean(true);
    }

    // false can be also determined from the _id
    if (RequestContext.FALSE_KEY_ID.equalsIgnoreCase(id)) {
        return new BsonBoolean(false);
    }

    try {
        switch (type) {
            case STRING_OID:
                return getIdAsStringOrObjectId(id);
            case OID:
                return getIdAsObjectId(id);
            case STRING:
                return new BsonString(id);
            case NUMBER:
                return getIdAsNumber(id);
            case MINKEY:
                return new BsonMinKey();
            case MAXKEY:
                return new BsonMaxKey();
            case DATE:
                return getIdAsDate(id);
            case BOOLEAN:
                return getIdAsBoolean(id);
        }
    } catch (IllegalArgumentException iar) {
        throw new UnsupportedDocumentIdException(iar);
    }

    return new BsonString(id);
}