Java Code Examples for org.dataloader.DataLoader#newDataLoader()

The following examples show how to use org.dataloader.DataLoader#newDataLoader() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReadmeExamples.java    From java-dataloader with Apache License 2.0 6 votes vote down vote up
private void keyContextExample() {
    DataLoaderOptions options = DataLoaderOptions.newOptions()
            .setBatchLoaderContextProvider(() -> SecurityCtx.getCallingUserCtx());

    BatchLoaderWithContext<String, String> batchLoader = new BatchLoaderWithContext<String, String>() {
        @Override
        public CompletionStage<List<String>> load(List<String> keys, BatchLoaderEnvironment environment) {
            SecurityCtx callCtx = environment.getContext();
            //
            // this is the load context objects in map form by key
            // in this case [ keyA : contextForA, keyB : contextForB ]
            //
            Map<Object, Object> keyContexts = environment.getKeyContexts();
            //
            // this is load context in list form
            //
            // in this case [ contextForA, contextForB ]
            return callDatabaseForResults(callCtx, keys);
        }
    };

    DataLoader<String, String> loader = DataLoader.newDataLoader(batchLoader, options);
    loader.load("keyA", "contextForA");
    loader.load("keyB", "contextForB");
}
 
Example 2
Source File: ReadmeExamples.java    From java-dataloader with Apache License 2.0 5 votes vote down vote up
private void callContextExample() {
    DataLoaderOptions options = DataLoaderOptions.newOptions()
            .setBatchLoaderContextProvider(() -> SecurityCtx.getCallingUserCtx());

    BatchLoaderWithContext<String, String> batchLoader = new BatchLoaderWithContext<String, String>() {
        @Override
        public CompletionStage<List<String>> load(List<String> keys, BatchLoaderEnvironment environment) {
            SecurityCtx callCtx = environment.getContext();
            return callDatabaseForResults(callCtx, keys);
        }
    };

    DataLoader<String, String> loader = DataLoader.newDataLoader(batchLoader, options);
}
 
Example 3
Source File: ReadmeExamples.java    From java-dataloader with Apache License 2.0 4 votes vote down vote up
private void statsConfigExample() {

        DataLoaderOptions options = DataLoaderOptions.newOptions().setStatisticsCollector(() -> new ThreadLocalStatisticsCollector());
        DataLoader<String, User> userDataLoader = DataLoader.newDataLoader(userBatchLoader, options);
    }
 
Example 4
Source File: ReadmeExamples.java    From java-dataloader with Apache License 2.0 3 votes vote down vote up
private void disableCache() {
    DataLoader.newDataLoader(userBatchLoader, DataLoaderOptions.newOptions().setCachingEnabled(false));


    userDataLoader.load("A");
    userDataLoader.load("B");
    userDataLoader.load("A");

    userDataLoader.dispatch();

    // will result in keys to the batch loader with [ "A", "B", "A" ]
}