-
Notifications
You must be signed in to change notification settings - Fork 94
Breaking change - adds a name to a DataLoader #193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
02a485d
Breaking change - adds a name to a DataLoader and deprecates a bunch …
bbakerman bf3edd2
Breaking change - adds a name to a DataLoader and deprecates a bunch …
bbakerman 496a298
Breaking change - adds a name to a DataLoader and deprecates a bunch …
bbakerman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,7 +58,7 @@ | |
* <p> | ||
* A call to the batch loader might result in individual exception failures for item with the returned list. if | ||
* you want to capture these specific item failures then use {@link org.dataloader.Try} as a return value and | ||
* create the data loader with {@link #newDataLoaderWithTry(BatchLoader)} form. The Try values will be interpreted | ||
* create the data loader with {@link DataLoaderFactory#newDataLoaderWithTry(BatchLoader)} form. The Try values will be interpreted | ||
* as either success values or cause the {@link #load(Object)} promise to complete exceptionally. | ||
* | ||
* @param <K> type parameter indicating the type of the data load keys | ||
|
@@ -70,331 +70,29 @@ | |
@NullMarked | ||
public class DataLoader<K, V> { | ||
|
||
private final @Nullable String name; | ||
private final DataLoaderHelper<K, V> helper; | ||
private final StatisticsCollector stats; | ||
private final CacheMap<Object, V> futureCache; | ||
private final ValueCache<K, V> valueCache; | ||
private final DataLoaderOptions options; | ||
private final Object batchLoadFunction; | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These have been deprecated for FOREVER and since this is a breaking change chance - I am taking it |
||
* Creates new DataLoader with the specified batch loader function and default options | ||
* (batching, caching and unlimited batch size). | ||
* | ||
* @param batchLoadFunction the batch load function to use | ||
* @param <K> the key type | ||
* @param <V> the value type | ||
* @return a new DataLoader | ||
* @deprecated use {@link DataLoaderFactory} instead | ||
*/ | ||
@Deprecated | ||
public static <K, V> DataLoader<K, V> newDataLoader(BatchLoader<K, V> batchLoadFunction) { | ||
return newDataLoader(batchLoadFunction, null); | ||
} | ||
|
||
/** | ||
* Creates new DataLoader with the specified batch loader function with the provided options | ||
* | ||
* @param batchLoadFunction the batch load function to use | ||
* @param options the options to use | ||
* @param <K> the key type | ||
* @param <V> the value type | ||
* @return a new DataLoader | ||
* @deprecated use {@link DataLoaderFactory} instead | ||
*/ | ||
@Deprecated | ||
public static <K, V> DataLoader<K, V> newDataLoader(BatchLoader<K, V> batchLoadFunction, @Nullable DataLoaderOptions options) { | ||
return DataLoaderFactory.mkDataLoader(batchLoadFunction, options); | ||
} | ||
|
||
/** | ||
* Creates new DataLoader with the specified batch loader function and default options | ||
* (batching, caching and unlimited batch size) where the batch loader function returns a list of | ||
* {@link org.dataloader.Try} objects. | ||
* <p> | ||
* If it's important you to know the exact status of each item in a batch call and whether it threw exceptions then | ||
* you can use this form to create the data loader. | ||
* <p> | ||
* Using Try objects allows you to capture a value returned or an exception that might | ||
* have occurred trying to get a value. . | ||
* | ||
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects | ||
* @param <K> the key type | ||
* @param <V> the value type | ||
* @return a new DataLoader | ||
* @deprecated use {@link DataLoaderFactory} instead | ||
*/ | ||
@Deprecated | ||
public static <K, V> DataLoader<K, V> newDataLoaderWithTry(BatchLoader<K, Try<V>> batchLoadFunction) { | ||
return newDataLoaderWithTry(batchLoadFunction, null); | ||
} | ||
|
||
/** | ||
* Creates new DataLoader with the specified batch loader function and with the provided options | ||
* where the batch loader function returns a list of | ||
* {@link org.dataloader.Try} objects. | ||
* | ||
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects | ||
* @param options the options to use | ||
* @param <K> the key type | ||
* @param <V> the value type | ||
* @return a new DataLoader | ||
* @see DataLoaderFactory#newDataLoaderWithTry(BatchLoader) | ||
* @deprecated use {@link DataLoaderFactory} instead | ||
*/ | ||
@Deprecated | ||
public static <K, V> DataLoader<K, V> newDataLoaderWithTry(BatchLoader<K, Try<V>> batchLoadFunction, @Nullable DataLoaderOptions options) { | ||
return DataLoaderFactory.mkDataLoader(batchLoadFunction, options); | ||
} | ||
|
||
/** | ||
* Creates new DataLoader with the specified batch loader function and default options | ||
* (batching, caching and unlimited batch size). | ||
* | ||
* @param batchLoadFunction the batch load function to use | ||
* @param <K> the key type | ||
* @param <V> the value type | ||
* @return a new DataLoader | ||
* @deprecated use {@link DataLoaderFactory} instead | ||
*/ | ||
@Deprecated | ||
public static <K, V> DataLoader<K, V> newDataLoader(BatchLoaderWithContext<K, V> batchLoadFunction) { | ||
return newDataLoader(batchLoadFunction, null); | ||
} | ||
|
||
/** | ||
* Creates new DataLoader with the specified batch loader function with the provided options | ||
* | ||
* @param batchLoadFunction the batch load function to use | ||
* @param options the options to use | ||
* @param <K> the key type | ||
* @param <V> the value type | ||
* @return a new DataLoader | ||
* @deprecated use {@link DataLoaderFactory} instead | ||
*/ | ||
@Deprecated | ||
public static <K, V> DataLoader<K, V> newDataLoader(BatchLoaderWithContext<K, V> batchLoadFunction, @Nullable DataLoaderOptions options) { | ||
return DataLoaderFactory.mkDataLoader(batchLoadFunction, options); | ||
} | ||
|
||
/** | ||
* Creates new DataLoader with the specified batch loader function and default options | ||
* (batching, caching and unlimited batch size) where the batch loader function returns a list of | ||
* {@link org.dataloader.Try} objects. | ||
* <p> | ||
* If it's important you to know the exact status of each item in a batch call and whether it threw exceptions then | ||
* you can use this form to create the data loader. | ||
* <p> | ||
* Using Try objects allows you to capture a value returned or an exception that might | ||
* have occurred trying to get a value. . | ||
* | ||
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects | ||
* @param <K> the key type | ||
* @param <V> the value type | ||
* @return a new DataLoader | ||
* @deprecated use {@link DataLoaderFactory} instead | ||
*/ | ||
@Deprecated | ||
public static <K, V> DataLoader<K, V> newDataLoaderWithTry(BatchLoaderWithContext<K, Try<V>> batchLoadFunction) { | ||
return newDataLoaderWithTry(batchLoadFunction, null); | ||
} | ||
|
||
/** | ||
* Creates new DataLoader with the specified batch loader function and with the provided options | ||
* where the batch loader function returns a list of | ||
* {@link org.dataloader.Try} objects. | ||
* | ||
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects | ||
* @param options the options to use | ||
* @param <K> the key type | ||
* @param <V> the value type | ||
* @return a new DataLoader | ||
* @see DataLoaderFactory#newDataLoaderWithTry(BatchLoader) | ||
* @deprecated use {@link DataLoaderFactory} instead | ||
*/ | ||
@Deprecated | ||
public static <K, V> DataLoader<K, V> newDataLoaderWithTry(BatchLoaderWithContext<K, Try<V>> batchLoadFunction, @Nullable DataLoaderOptions options) { | ||
return DataLoaderFactory.mkDataLoader(batchLoadFunction, options); | ||
} | ||
|
||
/** | ||
* Creates new DataLoader with the specified batch loader function and default options | ||
* (batching, caching and unlimited batch size). | ||
* | ||
* @param batchLoadFunction the batch load function to use | ||
* @param <K> the key type | ||
* @param <V> the value type | ||
* @return a new DataLoader | ||
* @deprecated use {@link DataLoaderFactory} instead | ||
*/ | ||
@Deprecated | ||
public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoader<K, V> batchLoadFunction) { | ||
return newMappedDataLoader(batchLoadFunction, null); | ||
} | ||
|
||
/** | ||
* Creates new DataLoader with the specified batch loader function with the provided options | ||
* | ||
* @param batchLoadFunction the batch load function to use | ||
* @param options the options to use | ||
* @param <K> the key type | ||
* @param <V> the value type | ||
* @return a new DataLoader | ||
* @deprecated use {@link DataLoaderFactory} instead | ||
*/ | ||
@Deprecated | ||
public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoader<K, V> batchLoadFunction, @Nullable DataLoaderOptions options) { | ||
return DataLoaderFactory.mkDataLoader(batchLoadFunction, options); | ||
} | ||
|
||
/** | ||
* Creates new DataLoader with the specified batch loader function and default options | ||
* (batching, caching and unlimited batch size) where the batch loader function returns a list of | ||
* {@link org.dataloader.Try} objects. | ||
* <p> | ||
* If it's important you to know the exact status of each item in a batch call and whether it threw exceptions then | ||
* you can use this form to create the data loader. | ||
* <p> | ||
* Using Try objects allows you to capture a value returned or an exception that might | ||
* have occurred trying to get a value. . | ||
* <p> | ||
* | ||
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects | ||
* @param <K> the key type | ||
* @param <V> the value type | ||
* @return a new DataLoader | ||
* @deprecated use {@link DataLoaderFactory} instead | ||
*/ | ||
@Deprecated | ||
public static <K, V> DataLoader<K, V> newMappedDataLoaderWithTry(MappedBatchLoader<K, Try<V>> batchLoadFunction) { | ||
return newMappedDataLoaderWithTry(batchLoadFunction, null); | ||
} | ||
|
||
/** | ||
* Creates new DataLoader with the specified batch loader function and with the provided options | ||
* where the batch loader function returns a list of | ||
* {@link org.dataloader.Try} objects. | ||
* | ||
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects | ||
* @param options the options to use | ||
* @param <K> the key type | ||
* @param <V> the value type | ||
* @return a new DataLoader | ||
* @see DataLoaderFactory#newDataLoaderWithTry(BatchLoader) | ||
* @deprecated use {@link DataLoaderFactory} instead | ||
*/ | ||
@Deprecated | ||
public static <K, V> DataLoader<K, V> newMappedDataLoaderWithTry(MappedBatchLoader<K, Try<V>> batchLoadFunction, @Nullable DataLoaderOptions options) { | ||
return DataLoaderFactory.mkDataLoader(batchLoadFunction, options); | ||
} | ||
|
||
/** | ||
* Creates new DataLoader with the specified mapped batch loader function and default options | ||
* (batching, caching and unlimited batch size). | ||
* | ||
* @param batchLoadFunction the batch load function to use | ||
* @param <K> the key type | ||
* @param <V> the value type | ||
* @return a new DataLoader | ||
* @deprecated use {@link DataLoaderFactory} instead | ||
*/ | ||
@Deprecated | ||
public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoaderWithContext<K, V> batchLoadFunction) { | ||
return newMappedDataLoader(batchLoadFunction, null); | ||
} | ||
|
||
/** | ||
* Creates new DataLoader with the specified batch loader function with the provided options | ||
* | ||
* @param batchLoadFunction the batch load function to use | ||
* @param options the options to use | ||
* @param <K> the key type | ||
* @param <V> the value type | ||
* @return a new DataLoader | ||
* @deprecated use {@link DataLoaderFactory} instead | ||
*/ | ||
@Deprecated | ||
public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoaderWithContext<K, V> batchLoadFunction, @Nullable DataLoaderOptions options) { | ||
return DataLoaderFactory.mkDataLoader(batchLoadFunction, options); | ||
} | ||
|
||
/** | ||
* Creates new DataLoader with the specified batch loader function and default options | ||
* (batching, caching and unlimited batch size) where the batch loader function returns a list of | ||
* {@link org.dataloader.Try} objects. | ||
* <p> | ||
* If it's important you to know the exact status of each item in a batch call and whether it threw exceptions then | ||
* you can use this form to create the data loader. | ||
* <p> | ||
* Using Try objects allows you to capture a value returned or an exception that might | ||
* have occurred trying to get a value. . | ||
* | ||
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects | ||
* @param <K> the key type | ||
* @param <V> the value type | ||
* @return a new DataLoader | ||
* @deprecated use {@link DataLoaderFactory} instead | ||
*/ | ||
@Deprecated | ||
public static <K, V> DataLoader<K, V> newMappedDataLoaderWithTry(MappedBatchLoaderWithContext<K, Try<V>> batchLoadFunction) { | ||
return newMappedDataLoaderWithTry(batchLoadFunction, null); | ||
} | ||
|
||
/** | ||
* Creates new DataLoader with the specified batch loader function and with the provided options | ||
* where the batch loader function returns a list of | ||
* {@link org.dataloader.Try} objects. | ||
* | ||
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects | ||
* @param options the options to use | ||
* @param <K> the key type | ||
* @param <V> the value type | ||
* @return a new DataLoader | ||
* @see DataLoaderFactory#newDataLoaderWithTry(BatchLoader) | ||
* @deprecated use {@link DataLoaderFactory} instead | ||
*/ | ||
@Deprecated | ||
public static <K, V> DataLoader<K, V> newMappedDataLoaderWithTry(MappedBatchLoaderWithContext<K, Try<V>> batchLoadFunction, @Nullable DataLoaderOptions options) { | ||
return DataLoaderFactory.mkDataLoader(batchLoadFunction, options); | ||
} | ||
|
||
/** | ||
* Creates a new data loader with the provided batch load function, and default options. | ||
* | ||
* @param batchLoadFunction the batch load function to use | ||
* @deprecated use {@link DataLoaderFactory} instead | ||
*/ | ||
@Deprecated | ||
public DataLoader(BatchLoader<K, V> batchLoadFunction) { | ||
this((Object) batchLoadFunction, null); | ||
} | ||
|
||
/** | ||
* Creates a new data loader with the provided batch load function and options. | ||
* | ||
* @param batchLoadFunction the batch load function to use | ||
* @param options the batch load options | ||
* @deprecated use {@link DataLoaderFactory} instead | ||
*/ | ||
@Deprecated | ||
public DataLoader(BatchLoader<K, V> batchLoadFunction, @Nullable DataLoaderOptions options) { | ||
this((Object) batchLoadFunction, options); | ||
} | ||
|
||
@VisibleForTesting | ||
DataLoader(Object batchLoadFunction, @Nullable DataLoaderOptions options) { | ||
this(batchLoadFunction, options, Clock.systemUTC()); | ||
DataLoader(@Nullable String name, Object batchLoadFunction, @Nullable DataLoaderOptions options) { | ||
this(name, batchLoadFunction, options, Clock.systemUTC()); | ||
} | ||
|
||
@VisibleForTesting | ||
DataLoader(Object batchLoadFunction, @Nullable DataLoaderOptions options, Clock clock) { | ||
DataLoader(@Nullable String name, Object batchLoadFunction, @Nullable DataLoaderOptions options, Clock clock) { | ||
DataLoaderOptions loaderOptions = options == null ? new DataLoaderOptions() : options; | ||
this.futureCache = determineFutureCache(loaderOptions); | ||
this.valueCache = determineValueCache(loaderOptions); | ||
// order of keys matter in data loader | ||
this.stats = nonNull(loaderOptions.getStatisticsCollector()); | ||
this.batchLoadFunction = nonNull(batchLoadFunction); | ||
this.options = loaderOptions; | ||
this.name = name; | ||
|
||
this.helper = new DataLoaderHelper<>(this, batchLoadFunction, loaderOptions, this.futureCache, this.valueCache, this.stats, clock); | ||
} | ||
|
@@ -410,6 +108,13 @@ private ValueCache<K, V> determineValueCache(DataLoaderOptions loaderOptions) { | |
return (ValueCache<K, V>) loaderOptions.valueCache().orElseGet(ValueCache::defaultValueCache); | ||
} | ||
|
||
/** | ||
* @return the name of the DataLoader which can be null | ||
*/ | ||
public @Nullable String getName() { | ||
return name; | ||
} | ||
|
||
/** | ||
* @return the options used to build this {@link DataLoader} | ||
*/ | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should DataLoader be final btw?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure