Skip to content

Commit 4569c43

Browse files
committed
Breaking change - renaming old mutable setXX methods
1 parent 8dad2ac commit 4569c43

13 files changed

+91
-91
lines changed

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ for the context object.
205205

206206
```java
207207
DataLoaderOptions options = DataLoaderOptions.newOptions()
208-
.setBatchLoaderContextProvider(() -> SecurityCtx.getCallingUserCtx());
208+
.withBatchLoaderContextProvider(() -> SecurityCtx.getCallingUserCtx());
209209

210210
BatchLoaderWithContext<String, String> batchLoader = new BatchLoaderWithContext<String, String>() {
211211
@Override
@@ -227,7 +227,7 @@ You can gain access to them as a map by key or as the original list of context o
227227

228228
```java
229229
DataLoaderOptions options = DataLoaderOptions.newOptions()
230-
.setBatchLoaderContextProvider(() -> SecurityCtx.getCallingUserCtx());
230+
.withBatchLoaderContextProvider(() -> SecurityCtx.getCallingUserCtx());
231231

232232
BatchLoaderWithContext<String, String> batchLoader = new BatchLoaderWithContext<String, String>() {
233233
@Override
@@ -433,7 +433,7 @@ However, you can create your own custom future cache and supply it to the data l
433433

434434
```java
435435
MyCustomCache customCache = new MyCustomCache();
436-
DataLoaderOptions options = DataLoaderOptions.newOptions().setCacheMap(customCache);
436+
DataLoaderOptions options = DataLoaderOptions.newOptions().withsetCacheMap(customCache);
437437
DataLoaderFactory.newDataLoader(userBatchLoader, options);
438438
```
439439

@@ -467,7 +467,7 @@ The tests have an example based on [Caffeine](https://github.com/ben-manes/caffe
467467
In certain uncommon cases, a DataLoader which does not cache may be desirable.
468468

469469
```java
470-
DataLoaderFactory.newDataLoader(userBatchLoader, DataLoaderOptions.newOptions().setCachingEnabled(false));
470+
DataLoaderFactory.newDataLoader(userBatchLoader, DataLoaderOptions.newOptions().withCachingEnabled(false));
471471
```
472472

473473
Calling the above will ensure that every call to `.load()` will produce a new promise, and requested keys will not be saved in memory.
@@ -533,7 +533,7 @@ Knowing what the behaviour of your data is important for you to understand how e
533533
You can configure the statistics collector used when you build the data loader
534534

535535
```java
536-
DataLoaderOptions options = DataLoaderOptions.newOptions().setStatisticsCollector(() -> new ThreadLocalStatisticsCollector());
536+
DataLoaderOptions options = DataLoaderOptions.newOptions().withStatisticsCollector(() -> new ThreadLocalStatisticsCollector());
537537
DataLoader<String,User> userDataLoader = DataLoaderFactory.newDataLoader(userBatchLoader,options);
538538

539539
```
@@ -780,7 +780,7 @@ You set the `DataLoaderInstrumentation` into the `DataLoaderOptions` at build ti
780780
});
781781
}
782782
};
783-
DataLoaderOptions options = DataLoaderOptions.newOptions().setInstrumentation(timingInstrumentation);
783+
DataLoaderOptions options = DataLoaderOptions.newOptions().withInstrumentation(timingInstrumentation);
784784
DataLoader<String, User> userDataLoader = DataLoaderFactory.newDataLoader(userBatchLoader, options);
785785

786786
```

src/main/java/org/dataloader/DataLoaderOptions.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public boolean batchingEnabled() {
177177
* @param batchingEnabled {@code true} to enable batch loading, {@code false} otherwise
178178
* @return a new data loader options instance for fluent coding
179179
*/
180-
public DataLoaderOptions setBatchingEnabled(boolean batchingEnabled) {
180+
public DataLoaderOptions withBatchingEnabled(boolean batchingEnabled) {
181181
return builder().setBatchingEnabled(batchingEnabled).build();
182182
}
183183

@@ -196,7 +196,7 @@ public boolean cachingEnabled() {
196196
* @param cachingEnabled {@code true} to enable caching, {@code false} otherwise
197197
* @return a new data loader options instance for fluent coding
198198
*/
199-
public DataLoaderOptions setCachingEnabled(boolean cachingEnabled) {
199+
public DataLoaderOptions withCachingEnabled(boolean cachingEnabled) {
200200
return builder().setCachingEnabled(cachingEnabled).build();
201201
}
202202

@@ -220,7 +220,7 @@ public boolean cachingExceptionsEnabled() {
220220
* @param cachingExceptionsEnabled {@code true} to enable caching exceptional values, {@code false} otherwise
221221
* @return a new data loader options instance for fluent coding
222222
*/
223-
public DataLoaderOptions setCachingExceptionsEnabled(boolean cachingExceptionsEnabled) {
223+
public DataLoaderOptions withCachingExceptionsEnabled(boolean cachingExceptionsEnabled) {
224224
return builder().setCachingExceptionsEnabled(cachingExceptionsEnabled).build();
225225
}
226226

@@ -241,7 +241,7 @@ public Optional<CacheKey> cacheKeyFunction() {
241241
* @param cacheKeyFunction the cache key function to use
242242
* @return a new data loader options instance for fluent coding
243243
*/
244-
public DataLoaderOptions setCacheKeyFunction(CacheKey<?> cacheKeyFunction) {
244+
public DataLoaderOptions withCacheKeyFunction(CacheKey<?> cacheKeyFunction) {
245245
return builder().setCacheKeyFunction(cacheKeyFunction).build();
246246
}
247247

@@ -262,7 +262,7 @@ public DataLoaderOptions setCacheKeyFunction(CacheKey<?> cacheKeyFunction) {
262262
* @param cacheMap the cache map instance
263263
* @return a new data loader options instance for fluent coding
264264
*/
265-
public DataLoaderOptions setCacheMap(CacheMap<?, ?> cacheMap) {
265+
public DataLoaderOptions withCacheMap(CacheMap<?, ?> cacheMap) {
266266
return builder().setCacheMap(cacheMap).build();
267267
}
268268

@@ -283,7 +283,7 @@ public int maxBatchSize() {
283283
* @param maxBatchSize the maximum batch size
284284
* @return a new data loader options instance for fluent coding
285285
*/
286-
public DataLoaderOptions setMaxBatchSize(int maxBatchSize) {
286+
public DataLoaderOptions withMaxBatchSize(int maxBatchSize) {
287287
return builder().setMaxBatchSize(maxBatchSize).build();
288288
}
289289

@@ -302,7 +302,7 @@ public StatisticsCollector getStatisticsCollector() {
302302
* @param statisticsCollector the statistics collector to use
303303
* @return a new data loader options instance for fluent coding
304304
*/
305-
public DataLoaderOptions setStatisticsCollector(Supplier<StatisticsCollector> statisticsCollector) {
305+
public DataLoaderOptions withStatisticsCollector(Supplier<StatisticsCollector> statisticsCollector) {
306306
return builder().setStatisticsCollector(nonNull(statisticsCollector)).build();
307307
}
308308

@@ -319,7 +319,7 @@ public BatchLoaderContextProvider getBatchLoaderContextProvider() {
319319
* @param contextProvider the batch loader context provider
320320
* @return a new data loader options instance for fluent coding
321321
*/
322-
public DataLoaderOptions setBatchLoaderContextProvider(BatchLoaderContextProvider contextProvider) {
322+
public DataLoaderOptions withBatchLoaderContextProvider(BatchLoaderContextProvider contextProvider) {
323323
return builder().setBatchLoaderContextProvider(nonNull(contextProvider)).build();
324324
}
325325

@@ -340,7 +340,7 @@ public DataLoaderOptions setBatchLoaderContextProvider(BatchLoaderContextProvide
340340
* @param valueCache the value cache instance
341341
* @return a new data loader options instance for fluent coding
342342
*/
343-
public DataLoaderOptions setValueCache(ValueCache<?, ?> valueCache) {
343+
public DataLoaderOptions withValueCache(ValueCache<?, ?> valueCache) {
344344
return builder().setValueCache(valueCache).build();
345345
}
346346

@@ -357,7 +357,7 @@ public ValueCacheOptions getValueCacheOptions() {
357357
* @param valueCacheOptions the value cache options
358358
* @return a new data loader options instance for fluent coding
359359
*/
360-
public DataLoaderOptions setValueCacheOptions(ValueCacheOptions valueCacheOptions) {
360+
public DataLoaderOptions withValueCacheOptions(ValueCacheOptions valueCacheOptions) {
361361
return builder().setValueCacheOptions(nonNull(valueCacheOptions)).build();
362362
}
363363

@@ -375,7 +375,7 @@ public BatchLoaderScheduler getBatchLoaderScheduler() {
375375
* @param batchLoaderScheduler the scheduler
376376
* @return a new data loader options instance for fluent coding
377377
*/
378-
public DataLoaderOptions setBatchLoaderScheduler(BatchLoaderScheduler batchLoaderScheduler) {
378+
public DataLoaderOptions withBatchLoaderScheduler(BatchLoaderScheduler batchLoaderScheduler) {
379379
return builder().setBatchLoaderScheduler(batchLoaderScheduler).build();
380380
}
381381

@@ -392,7 +392,7 @@ public DataLoaderInstrumentation getInstrumentation() {
392392
* @param instrumentation the new {@link DataLoaderInstrumentation}
393393
* @return a new data loader options instance for fluent coding
394394
*/
395-
public DataLoaderOptions setInstrumentation(DataLoaderInstrumentation instrumentation) {
395+
public DataLoaderOptions withInstrumentation(DataLoaderInstrumentation instrumentation) {
396396
return builder().setInstrumentation(instrumentation).build();
397397
}
398398

src/test/java/ReadmeExamples.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public CompletionStage<List<User>> load(List<Long> userIds) {
105105

106106
private void callContextExample() {
107107
DataLoaderOptions options = DataLoaderOptions.newOptions()
108-
.setBatchLoaderContextProvider(() -> SecurityCtx.getCallingUserCtx());
108+
.withBatchLoaderContextProvider(() -> SecurityCtx.getCallingUserCtx());
109109

110110
BatchLoaderWithContext<String, String> batchLoader = new BatchLoaderWithContext<String, String>() {
111111
@Override
@@ -120,7 +120,7 @@ public CompletionStage<List<String>> load(List<String> keys, BatchLoaderEnvironm
120120

121121
private void keyContextExample() {
122122
DataLoaderOptions options = DataLoaderOptions.newOptions()
123-
.setBatchLoaderContextProvider(() -> SecurityCtx.getCallingUserCtx());
123+
.withBatchLoaderContextProvider(() -> SecurityCtx.getCallingUserCtx());
124124

125125
BatchLoaderWithContext<String, String> batchLoader = new BatchLoaderWithContext<String, String>() {
126126
@Override
@@ -236,7 +236,7 @@ private void clearCacheOnError() {
236236
BatchLoader<String, User> teamsBatchLoader;
237237

238238
private void disableCache() {
239-
DataLoaderFactory.newDataLoader(userBatchLoader, DataLoaderOptions.newOptions().setCachingEnabled(false));
239+
DataLoaderFactory.newDataLoader(userBatchLoader, DataLoaderOptions.newOptions().withCachingEnabled(false));
240240

241241

242242
userDataLoader.load("A");
@@ -283,7 +283,7 @@ public CacheMap clear() {
283283
private void customCache() {
284284

285285
MyCustomCache customCache = new MyCustomCache();
286-
DataLoaderOptions options = DataLoaderOptions.newOptions().setCacheMap(customCache);
286+
DataLoaderOptions options = DataLoaderOptions.newOptions().withCacheMap(customCache);
287287
DataLoaderFactory.newDataLoader(userBatchLoader, options);
288288
}
289289

@@ -311,7 +311,7 @@ private void statsExample() {
311311

312312
private void statsConfigExample() {
313313

314-
DataLoaderOptions options = DataLoaderOptions.newOptions().setStatisticsCollector(() -> new ThreadLocalStatisticsCollector());
314+
DataLoaderOptions options = DataLoaderOptions.newOptions().withStatisticsCollector(() -> new ThreadLocalStatisticsCollector());
315315
DataLoader<String, User> userDataLoader = DataLoaderFactory.newDataLoader(userBatchLoader, options);
316316
}
317317

@@ -410,7 +410,7 @@ public DataLoaderInstrumentationContext<List<?>> beginBatchLoader(DataLoader<?,
410410
});
411411
}
412412
};
413-
DataLoaderOptions options = DataLoaderOptions.newOptions().setInstrumentation(timingInstrumentation);
413+
DataLoaderOptions options = DataLoaderOptions.newOptions().withInstrumentation(timingInstrumentation);
414414
DataLoader<String, User> userDataLoader = DataLoaderFactory.newDataLoader(userBatchLoader, options);
415415
}
416416

src/test/java/org/dataloader/DataLoaderBatchLoaderEnvironmentTest.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void context_is_passed_to_batch_loader_function() {
4141
return CompletableFuture.completedFuture(list);
4242
};
4343
DataLoaderOptions options = DataLoaderOptions.newOptions()
44-
.setBatchLoaderContextProvider(() -> "ctx");
44+
.withBatchLoaderContextProvider(() -> "ctx");
4545
DataLoader<String, String> loader = newDataLoader(batchLoader, options);
4646

4747
loader.load("A");
@@ -61,7 +61,7 @@ public void context_is_passed_to_batch_loader_function() {
6161
public void key_contexts_are_passed_to_batch_loader_function() {
6262
BatchLoaderWithContext<String, String> batchLoader = contextBatchLoader();
6363
DataLoaderOptions options = DataLoaderOptions.newOptions()
64-
.setBatchLoaderContextProvider(() -> "ctx");
64+
.withBatchLoaderContextProvider(() -> "ctx");
6565
DataLoader<String, String> loader = newDataLoader(batchLoader, options);
6666

6767
loader.load("A", "aCtx");
@@ -81,8 +81,8 @@ public void key_contexts_are_passed_to_batch_loader_function() {
8181
public void key_contexts_are_passed_to_batch_loader_function_when_batching_disabled() {
8282
BatchLoaderWithContext<String, String> batchLoader = contextBatchLoader();
8383
DataLoaderOptions options = DataLoaderOptions.newOptions()
84-
.setBatchingEnabled(false)
85-
.setBatchLoaderContextProvider(() -> "ctx");
84+
.withBatchingEnabled(false)
85+
.withBatchLoaderContextProvider(() -> "ctx");
8686
DataLoader<String, String> loader = newDataLoader(batchLoader, options);
8787

8888
CompletableFuture<String> aLoad = loader.load("A", "aCtx");
@@ -104,7 +104,7 @@ public void key_contexts_are_passed_to_batch_loader_function_when_batching_disab
104104
public void missing_key_contexts_are_passed_to_batch_loader_function() {
105105
BatchLoaderWithContext<String, String> batchLoader = contextBatchLoader();
106106
DataLoaderOptions options = DataLoaderOptions.newOptions()
107-
.setBatchLoaderContextProvider(() -> "ctx");
107+
.withBatchLoaderContextProvider(() -> "ctx");
108108
DataLoader<String, String> loader = newDataLoader(batchLoader, options);
109109

110110
loader.load("A", "aCtx");
@@ -133,7 +133,7 @@ public void context_is_passed_to_map_batch_loader_function() {
133133
return CompletableFuture.completedFuture(map);
134134
};
135135
DataLoaderOptions options = DataLoaderOptions.newOptions()
136-
.setBatchLoaderContextProvider(() -> "ctx");
136+
.withBatchLoaderContextProvider(() -> "ctx");
137137
DataLoader<String, String> loader = newMappedDataLoader(mapBatchLoader, options);
138138

139139
loader.load("A", "aCtx");
@@ -199,8 +199,8 @@ public void null_is_passed_as_context_to_map_loader_if_you_do_nothing() {
199199
public void mmap_semantics_apply_to_batch_loader_context() {
200200
BatchLoaderWithContext<String, String> batchLoader = contextBatchLoader();
201201
DataLoaderOptions options = DataLoaderOptions.newOptions()
202-
.setBatchLoaderContextProvider(() -> "ctx")
203-
.setCachingEnabled(false);
202+
.withBatchLoaderContextProvider(() -> "ctx")
203+
.withCachingEnabled(false);
204204
DataLoader<String, String> loader = newDataLoader(batchLoader, options);
205205

206206
loader.load("A", "aCtx");

src/test/java/org/dataloader/DataLoaderBuilderTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class DataLoaderBuilderTest {
1313
BatchLoader<String, Object> batchLoader2 = keys -> null;
1414

1515
DataLoaderOptions defaultOptions = DataLoaderOptions.newOptions();
16-
DataLoaderOptions differentOptions = DataLoaderOptions.newOptions().setCachingEnabled(false);
16+
DataLoaderOptions differentOptions = DataLoaderOptions.newOptions().withCachingEnabled(false);
1717

1818
@Test
1919
void canBuildNewDataLoaders() {

src/test/java/org/dataloader/DataLoaderOptionsTest.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -89,25 +89,25 @@ public Object getKey(Object input) {
8989

9090
@Test
9191
void canBuildOk() {
92-
assertThat(optionsDefault.setBatchingEnabled(false).batchingEnabled(),
92+
assertThat(optionsDefault.withBatchingEnabled(false).batchingEnabled(),
9393
equalTo(false));
94-
assertThat(optionsDefault.setBatchLoaderScheduler(testBatchLoaderScheduler).getBatchLoaderScheduler(),
94+
assertThat(optionsDefault.withBatchLoaderScheduler(testBatchLoaderScheduler).getBatchLoaderScheduler(),
9595
equalTo(testBatchLoaderScheduler));
96-
assertThat(optionsDefault.setBatchLoaderContextProvider(testBatchLoaderContextProvider).getBatchLoaderContextProvider(),
96+
assertThat(optionsDefault.withBatchLoaderContextProvider(testBatchLoaderContextProvider).getBatchLoaderContextProvider(),
9797
equalTo(testBatchLoaderContextProvider));
98-
assertThat(optionsDefault.setCacheMap(testCacheMap).cacheMap().get(),
98+
assertThat(optionsDefault.withCacheMap(testCacheMap).cacheMap().get(),
9999
equalTo(testCacheMap));
100-
assertThat(optionsDefault.setCachingEnabled(false).cachingEnabled(),
100+
assertThat(optionsDefault.withCachingEnabled(false).cachingEnabled(),
101101
equalTo(false));
102-
assertThat(optionsDefault.setValueCacheOptions(testValueCacheOptions).getValueCacheOptions(),
102+
assertThat(optionsDefault.withValueCacheOptions(testValueCacheOptions).getValueCacheOptions(),
103103
equalTo(testValueCacheOptions));
104-
assertThat(optionsDefault.setCacheKeyFunction(testCacheKey).cacheKeyFunction().get(),
104+
assertThat(optionsDefault.withCacheKeyFunction(testCacheKey).cacheKeyFunction().get(),
105105
equalTo(testCacheKey));
106-
assertThat(optionsDefault.setValueCache(testValueCache).valueCache().get(),
106+
assertThat(optionsDefault.withValueCache(testValueCache).valueCache().get(),
107107
equalTo(testValueCache));
108-
assertThat(optionsDefault.setMaxBatchSize(10).maxBatchSize(),
108+
assertThat(optionsDefault.withMaxBatchSize(10).maxBatchSize(),
109109
equalTo(10));
110-
assertThat(optionsDefault.setStatisticsCollector(testStatisticsCollectorSupplier).getStatisticsCollector(),
110+
assertThat(optionsDefault.withStatisticsCollector(testStatisticsCollectorSupplier).getStatisticsCollector(),
111111
equalTo(testStatisticsCollectorSupplier.get()));
112112

113113
DataLoaderOptions builtOptions = optionsDefault.transform(builder -> {

src/test/java/org/dataloader/DataLoaderRegistryTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ public void stats_can_be_collected() {
7979
DataLoaderRegistry registry = new DataLoaderRegistry();
8080

8181
DataLoader<Object, Object> dlA = newDataLoader(identityBatchLoader,
82-
DataLoaderOptions.newOptions().setStatisticsCollector(SimpleStatisticsCollector::new)
82+
DataLoaderOptions.newOptions().withStatisticsCollector(SimpleStatisticsCollector::new)
8383
);
8484
DataLoader<Object, Object> dlB = newDataLoader(identityBatchLoader,
85-
DataLoaderOptions.newOptions().setStatisticsCollector(SimpleStatisticsCollector::new)
85+
DataLoaderOptions.newOptions().withStatisticsCollector(SimpleStatisticsCollector::new)
8686
);
8787
DataLoader<Object, Object> dlC = newDataLoader(identityBatchLoader,
88-
DataLoaderOptions.newOptions().setStatisticsCollector(SimpleStatisticsCollector::new)
88+
DataLoaderOptions.newOptions().withStatisticsCollector(SimpleStatisticsCollector::new)
8989
);
9090

9191
registry.register("a", dlA).register("b", dlB).register("c", dlC);

0 commit comments

Comments
 (0)