A Java 11 port of Facebook DataLoader
Repo graphql-java/java-dataloader, read from GitHub 56 min ago. graphql-java has not joined Take My Repo.
This is a breaking change release version of the Java DataLoader
The main breaking change is in org.dataloader.CacheMap and specifically the org.dataloader.CacheMap#putIfAbsentAtomically method.
Previous versions of dataloader used synchronised locks to guard the data structures during a dispatch call.
However to provide even higher performance the code has been changed to use a Compare And Swap (CAS) mechanism instead.
This means that there is a new contract on the org.dataloader.CacheMap implementations that they must be atomically thread safe in their writing and reading of cache entries.
The default implementation uses a java.util.concurrent.ConcurrentHashMap to provide this but if you have your own implementations then you need to update them to be atomically thread safe when putting cache entries.
If you don't use your own org.dataloader.CacheMap implementation then this will not be a breaking change version for you since there are no other breaking changes.
Full Changelog: v5.0.3...v6.0.0
This is a small bug fix release to remove Kotlin stdlib as a dependency of java-dataloader
Kotlin as added as a test dependency to help ensure the JSpecify annotations work as expected in Kotlin land.
However even thought we specified testImplementation in gradle, the Kotlin gradle plugin auto added Kotlin stdlib as a pom dependency on publish
#229 fixes this and this release is to publish a new version with the Kotlin stdlib in the pom
Full Changelog: v5.0.2...v5.0.3
A small bugfix release that includes a nullability annotation fix for Value Cache
Full Changelog: v5.0.1...v5.0.2
This release updates the JSpecify nullable annotations on the BatchLoader method variants so that they work as expected with Kotlin 2 and its stronger enforcement of JSpecify annotations
eg they are now updated like this.
public interface BatchLoader<K, V extends @Nullable Object>
Full Changelog: v5.0.0...v5.0.1
Back in version 4.0.0 we introduced immutability into the DataLoaderOptions class, which was a good thing.
However it left the old mutative set methods in place and made them immutable. This was a mistake. This leads to bugs at runtime
for example
DataLoaderOptions options = DataLoaderOptions.newOptions();
if (maxBatchSize != BatchLoader.UNSET_BATCH_SIZE) {
options.setMaxBatchSize(maxBatchSize);
}
return options.setCacheMap(cache);
The above code would continue compile but the setMaxBatchSize would never take affected with the immutable support.
So to help address #190 version 5.0.0 has removed the set methods and require the Builder methods to be used to ensure that code that relied on the old mutative methods now break at compile time and not at runtime.
A DataLoader can now have a name. Its nullable so that old code can still work but its preferred that DataLoaders are named. This will help in debugging and also in instrumentation.
If you register a DataLoader into a DataLoaderRegistry then the names must match otherwise it will be rejected at registration time.
A series of long standing deprecated DataLoaderFactory methods got removed here as well.
Full Changelog: v4.0.0...v5.0.0
A new org.dataloader.instrumentation.DataLoaderInstrumentation has been added that is a callback to allow you to know when certain DataLoader actions start and when they finish.
DataLoaderInstrumentation timingInstrumentation = new DataLoaderInstrumentation() {
@Override
public DataLoaderInstrumentationContext<DispatchResult<?>> beginDispatch(DataLoader<?, ?> dataLoader) {
long then = System.currentTimeMillis();
return DataLoaderInstrumentationHelper.whenCompleted((result, err) -> {
long ms = System.currentTimeMillis() - then;
System.out.println(format("dispatch time: %d ms", ms));
});
}
@Override
public DataLoaderInstrumentationContext<List<?>> beginBatchLoader(DataLoader<?, ?> dataLoader, List<?> keys, BatchLoaderEnvironment environment) {
long then = System.currentTimeMillis();
return DataLoaderInstrumentationHelper.whenCompleted((result, err) -> {
long ms = System.currentTimeMillis() - then;
System.out.println(format("batch loader time: %d ms", ms));
});
}
};
DataLoaderOptions options = DataLoaderOptions.newOptions().setInstrumentation(timingInstrumentation);
DataLoader<String, User> userDataLoader = DataLoaderFactory.newDataLoader(userBatchLoader, options);
Some of the key classes like org.dataloader.DataLoaderOptions have been made immutable so as to provide more surety in how they get used and transformed. This is technically a breaking change if you code relied on the old mutability, however on balance we think this is a better code position to be in.
Full Changelog: v3.4.0...v4.0.0