org.molgenis.data.support.AbstractRepository Maven / Gradle / Ivy
package org.molgenis.data.support;
import static com.google.common.base.Predicates.notNull;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.partition;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Maps.uniqueIndex;
import static com.google.common.collect.Streams.stream;
import com.google.common.collect.Iterators;
import com.google.common.collect.Sets;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Stream;
import org.molgenis.data.Entity;
import org.molgenis.data.Fetch;
import org.molgenis.data.Query;
import org.molgenis.data.QueryRule.Operator;
import org.molgenis.data.Repository;
import org.molgenis.data.RepositoryCapability;
import org.molgenis.data.aggregation.AggregateQuery;
import org.molgenis.data.aggregation.AggregateResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** Base class for repositories. Subclasses can override supported methods */
public abstract class AbstractRepository implements Repository {
private static final int FIND_ALL_BATCH_SIZE = 1000;
private final Logger log = LoggerFactory.getLogger(getClass());
private String name;
@Override
public String getName() {
if (name == null) name = getEntityType().getId();
return name;
}
@Override
public Set getQueryOperators() {
if (!getCapabilities().contains(RepositoryCapability.QUERYABLE)) {
return Collections.emptySet();
} else {
return EnumSet.allOf(Operator.class);
}
}
public Query query() {
return new QueryImpl<>(this);
}
@Override
public long count() {
return count(new QueryImpl<>());
}
@Override
public void close() {}
@Override
public long count(Query q) {
throw new UnsupportedOperationException();
}
@Override
public Stream findAll(Query q) {
throw new UnsupportedOperationException();
}
@Override
public Entity findOne(Query q) {
throw new UnsupportedOperationException();
}
@Override
public Entity findOneById(Object id) {
return findOneById(id, null);
}
@Override
public Entity findOneById(Object id, Fetch fetch) {
throw new UnsupportedOperationException();
}
@Override
public Stream findAll(Stream