[JAVA-2719] Add Java Bean-style setters to options classes Created: 28/Dec/17  Updated: 18/Oct/18  Resolved: 18/Oct/18

Status: Closed
Project: Java Driver
Component/s: API
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Jeffrey Yemin Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Epic Link: Kotlin Support

 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.


Generated at Thu Feb 08 08:57:55 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.