All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.ravendb.client.documents.session.loaders.LazyMultiLoaderWithInclude Maven / Gradle / Ivy

There is a newer version: 6.0.1
Show newest version
package net.ravendb.client.documents.session.loaders;

import net.ravendb.client.documents.Lazy;
import net.ravendb.client.documents.session.IDocumentSessionImpl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

public class LazyMultiLoaderWithInclude implements ILazyLoaderWithInclude {

    private final IDocumentSessionImpl _session;
    private final List _includes = new ArrayList<>();

    public LazyMultiLoaderWithInclude(IDocumentSessionImpl session) {
        _session = session;
    }

    /**
     * Includes the specified path.
     */
    @Override
    public ILazyLoaderWithInclude include(String path) {
        _includes.add(path);
        return this;
    }

    /**
     * Loads the specified ids.
     */
    @Override
    public  Lazy> load(Class clazz, String... ids) {
        return _session.lazyLoadInternal(clazz, ids, _includes.toArray(new String[0]), null);
    }

    /**
     * Loads the specified ids.
     */
    @Override
    public  Lazy> load(Class clazz, Collection ids) {
        return _session.lazyLoadInternal(clazz, ids.toArray(new String[0]), _includes.toArray(new String[0]), null);
    }

    /**
     * Loads the specified id.
     */
    @SuppressWarnings("unchecked")
    @Override
    public  Lazy load(Class clazz, String id) {
        Lazy> results = _session.lazyLoadInternal(clazz, new String[]{id}, _includes.toArray(new String[0]), null);
        return new Lazy(() -> results.getValue().values().iterator().next());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy