Example usage for com.mongodb.client.model PushOptions getSortDocument

List of usage examples for com.mongodb.client.model PushOptions getSortDocument

Introduction

In this page you can find the example usage for com.mongodb.client.model PushOptions getSortDocument.

Prototype

@Nullable
public Bson getSortDocument() 

Source Link

Document

Gets the sort direction for sorting array elements that are documents.

Usage

From source file:com.navercorp.pinpoint.plugin.mongo.WriteContext.java

License:Apache License

private void parseUpdatesObject(Object arg) {
    String argName = arg.getClass().getName();

    //SimpleUpdate
    if (argName.equals(MongoConstants.MONGO_UPDATES_SIMPLE)) {
        logger.debug("writing SimpleUpdate");

        bsonWriter.writeStartDocument();
        bsonWriter.writeName(((OperatorGetter) arg)._$PINPOINT$_getOperator());

        bsonWriter.writeStartDocument();
        bsonWriter.writeName(((FieldNameGetter) arg)._$PINPOINT$_getFieldName());
        writeValue(((ValueGetter) arg)._$PINPOINT$_getValue());
        bsonWriter.writeEndDocument();//w ww  . j av  a2  s  .c  om

        bsonWriter.writeEndDocument();
    }
    //WithEachUpdate
    if (argName.equals(MongoConstants.MONGO_UPDATES_WITHEACH)) {
        logger.debug("writing WithEachUpdate");

        bsonWriter.writeStartDocument();
        bsonWriter.writeName(((OperatorGetter) arg)._$PINPOINT$_getOperator());

        bsonWriter.writeStartDocument();
        bsonWriter.writeName(((FieldNameGetter) arg)._$PINPOINT$_getFieldName());
        bsonWriter.writeStartDocument();

        bsonWriter.writeStartArray("$each");
        for (Object value : ((ListValuesGetter) arg)._$PINPOINT$_getValues()) {
            writeValue(value);
        }
        bsonWriter.writeEndArray();
        bsonWriter.writeEndDocument();
        bsonWriter.writeEndDocument();
        bsonWriter.writeEndDocument();
    }
    //PushUpdate
    if (argName.equals(MongoConstants.MONGO_UPDATES_PUSH)) {
        logger.debug("writing PushUpdate");

        bsonWriter.writeStartDocument();
        bsonWriter.writeName(((OperatorGetter) arg)._$PINPOINT$_getOperator());

        bsonWriter.writeStartDocument();
        bsonWriter.writeName(((FieldNameGetter) arg)._$PINPOINT$_getFieldName());
        bsonWriter.writeStartDocument();

        bsonWriter.writeStartArray("$each");
        for (Object value : ((ListValuesGetter) arg)._$PINPOINT$_getValues()) {
            writeValue(value);
        }
        bsonWriter.writeEndArray();

        PushOptions options = ((PushOptionsGetter) arg)._$PINPOINT$_getPushOptions();
        if (options.getPosition() != null) {
            bsonWriter.writeInt32("$position", options.getPosition());
        }
        if (options.getSlice() != null) {
            bsonWriter.writeInt32("$slice", options.getSlice());
        }
        if (options.getSort() != null) {
            bsonWriter.writeInt32("$sort", options.getSort());
        } else if (options.getSortDocument() != null) {
            bsonWriter.writeName("$sort");
            writeValue(options.getSortDocument());
        }
        bsonWriter.writeEndDocument();
        bsonWriter.writeEndDocument();
        bsonWriter.writeEndDocument();
    }
    //PullAllUpdate
    if (argName.equals(MongoConstants.MONGO_UPDATES_PULLALL)) {
        logger.debug("writing PullAllUpdate");

        bsonWriter.writeStartDocument();
        bsonWriter.writeName("$pullAll");

        bsonWriter.writeStartDocument();
        bsonWriter.writeName(((FieldNameGetter) arg)._$PINPOINT$_getFieldName());

        bsonWriter.writeStartArray();
        for (Object value : ((ListValuesGetter) arg)._$PINPOINT$_getValues()) {
            writeValue(value);
        }
        bsonWriter.writeEndArray();

        bsonWriter.writeEndDocument();

        bsonWriter.writeEndDocument();
    }
    //CompositeUpdate
    if (argName.equals(MongoConstants.MONGO_UPDATES_COMPOSITE)) {
        logger.debug("writing CompositeUpdate");

        bsonWriter.writeStartDocument();

        bsonWriter.writeStartArray("$updates");
        for (Bson value : ((ExtendedBsonListGetter) arg)._$PINPOINT$_getExtendedBsonList()) {
            writeValue(value);
        }
        bsonWriter.writeEndArray();
        bsonWriter.writeEndDocument();
    }

}