Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-2719

Add Java Bean-style setters to options classes

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Icon: Major - P3 Major - P3
    • None
    • None
    • API
    • None

    Description

      The options classes define in com.mongodb.client.model use fluent setter methods, so that all options can be set without first assigning an instance of the options class to a variable, e.g.

      // Java
      collection.updateMany(Filters.eq("x", 1), Updates.set("x", 2),
                  UpdateOptions()
                      .upsert(true)
                      .bypassDocumentValidation(true));
      

      This is convenient for Java, but in Kotlin there is a more natural idiom that could be used if each option were exposed as a standard Java Bean-style setter:

      // Kotlin
      collection.updateMany(Filters.eq("x", 1), Updates.set("x", 2),
              UpdateOptions().apply {
                  upsert = true
                  collation = Collation.builder().backwards(true).build()
                  bypassDocumentValidation = true
              });
      

      which makes use of the <T> T.apply(block: T.() -> Unit): T extension function in the Kotlin standard library.

      Attachments

        Activity

          People

            Unassigned Unassigned
            jeff.yemin@mongodb.com Jeffrey Yemin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: