File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -126,6 +126,7 @@ public class MongoURI {
126
126
public static final String MONGODB_PREFIX = "mongodb://" ;
127
127
128
128
private final MongoClientURI mongoClientURI ;
129
+ private final MongoOptions mongoOptions ;
129
130
130
131
/**
131
132
* Creates a MongoURI from a string.
@@ -134,10 +135,12 @@ public class MongoURI {
134
135
*/
135
136
public MongoURI ( String uri ) {
136
137
this .mongoClientURI = new MongoClientURI (uri , new MongoClientOptions .Builder ().legacyDefaults ());
138
+ mongoOptions = new MongoOptions (mongoClientURI .getOptions ());
137
139
}
138
140
139
141
public MongoURI (final MongoClientURI mongoClientURI ) {
140
142
this .mongoClientURI = mongoClientURI ;
143
+ mongoOptions = new MongoOptions (mongoClientURI .getOptions ());
141
144
}
142
145
143
146
// ---------------------------------
@@ -183,11 +186,12 @@ public String getCollection(){
183
186
}
184
187
185
188
/**
186
- * Gets the options
187
- * @return
189
+ * Gets the options. This method will return the same instance of {@code MongoOptions} for every call, so it's
190
+ * possible to mutate the returned instance to change the defaults.
191
+ * @return the mongo options
188
192
*/
189
193
public MongoOptions getOptions (){
190
- return new MongoOptions ( mongoClientURI . getOptions ()) ;
194
+ return mongoOptions ;
191
195
}
192
196
193
197
/**
Original file line number Diff line number Diff line change @@ -66,4 +66,10 @@ public void testOptionDefaults() {
66
66
assertEquals (options .slaveOk , false );
67
67
assertEquals (options .isCursorFinalizerEnabled (), true );
68
68
}
69
+
70
+ @ Test
71
+ public void testOptionSameInstance () {
72
+ MongoURI mongoURI = new MongoURI ( "mongodb://localhost" );
73
+ assertSame (mongoURI .getOptions (), mongoURI .getOptions ());
74
+ }
69
75
}
You can’t perform that action at this time.
0 commit comments