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

org.molgenis.data.DataService Maven / Gradle / Ivy

There is a newer version: 8.4.5
Show newest version
package org.molgenis.data;

import java.util.Set;
import java.util.stream.Stream;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.molgenis.data.aggregation.AggregateQuery;
import org.molgenis.data.aggregation.AggregateResult;
import org.molgenis.data.meta.MetaDataService;
import org.molgenis.data.meta.model.EntityType;

/**
 * DataService is a facade that manages data sources Entity names should be unique over all data
 * sources.
 *
 * 

Main entry point for the DataApi */ public interface DataService extends Iterable> { void setMetaDataService(MetaDataService metaDataService); /** * Get the MetaDataService * * @return meta data service */ MetaDataService getMeta(); /** * Get the capabilities of a repository * * @param repositoryName repository name * @return repository capabilities */ Set getCapabilities(String repositoryName); /** * Returns whether a repository exists for the given entity type identifier. * * @param entityTypeId entity type identifier * @return true if a repository exists for the given entity type identifier */ boolean hasRepository(String entityTypeId); /** * Returns the repository for the given entity type identifier. * * @param entityTypeId entity type identifier * @return repository, never null * @throws UnknownEntityTypeException if no entity type with the given identifier exists * @throws UnknownRepositoryException if no repository exists for the entity type */ Repository getRepository(String entityTypeId); /** * Returns the typed repository for the given entity type identifier. * * @param entityTypeId entity type identifier * @param entityTypeClass entity type class * @return typed repository, never null * @throws UnknownEntityTypeException if no entity type with the given identifier exists * @throws UnknownRepositoryException if no repository exists for the entity type */ Repository getRepository(String entityTypeId, Class entityTypeClass); /** * Returns whether an entity type exists for the given entity type identifier. * * @param entityTypeId entity type identifier * @return true if an entity type exists for the given entity type identifier */ boolean hasEntityType(String entityTypeId); /** * Returns the entity type for the given entity type identifier. * * @param entityTypeId entity type identifier * @return entity type, never null * @throws UnknownEntityTypeException if no entity type with the given identifier exists */ EntityType getEntityType(String entityTypeId); /** * Returns the number of entities of the given type. * * @param entityTypeId entity name * @return number of entities */ long count(String entityTypeId); /** * return number of entities matched by query * * @throws MolgenisDataException if the repository of the entity isn't a Queryable */ long count(String entityTypeId, Query q); /** * Find all entities of the given type. Returns empty Stream if no matches. * * @throws MolgenisDataException if the repository of the entity isn't a Queryable */ Stream findAll(String entityTypeId); /** type-safe find all entities */ Stream findAll(String entityTypeId, Class clazz); /** * Find entities that match a query. Returns empty stream if no matches. * *

throws MolgenisDataException if the repository of the entity isn't a Queryable */ Stream findAll(String entityTypeId, Query q); /** * Type-safe find entities that match a query * * @param q query * @param clazz entity class */ Stream findAll(String entityTypeId, Query q, Class clazz); /** * Finds all entities with the given IDs. Returns empty stream if no matches. * * @param ids entity ids * @return (empty) Stream where the order of entities matches the order of ids, never null */ Stream findAll(String entityTypeId, Stream ids); /** * Finds all entities with the given IDs, type-safely. Returns empty stream if no matches. * * @param entityTypeId entity name (case insensitive) * @return (empty) Stream where the order of entities matches the order of ids, never null */ Stream findAll(String entityTypeId, Stream ids, Class clazz); /** * Finds all entities with the given IDs, with a fetch. Returns empty stream if no matches. * * @param entityTypeId entity name (case insensitive) * @param ids entity ids * @param fetch fetch defining which attributes to retrieve * @return (empty) Stream where the order of entities matches the order of ids, never null */ Stream findAll(String entityTypeId, Stream ids, Fetch fetch); /** * Finds all entities with the given IDs, type-safely and with a fetch. Returns empty stream if no * matches. * * @param ids entity ids * @param fetch fetch defining which attributes to retrieve * @param clazz typed entity class * @return (empty) Stream of entities of the give type where the order of entities matches the * order of ids, never null */ Stream findAll( String entityTypeId, Stream ids, Fetch fetch, Class clazz); /** * Find one entity based on id. Returns null if not exists * *

throws MolgenisDataException if the repository of the entity isn't a Queryable */ @Nullable @CheckForNull Entity findOneById(String entityTypeId, Object id); /** * @param id entity id * @param clazz entity type * @return typed entity */ @Nullable @CheckForNull E findOneById(String entityTypeId, Object id, Class clazz); /** * Find one entity based on id. * * @param id entity id * @param fetch fetch defining which attributes to retrieve * @return entity or null */ @Nullable @CheckForNull Entity findOneById(String entityTypeId, Object id, Fetch fetch); /** * Type-safe find one entity based on id. * * @param id entity id * @param fetch fetch defining which attributes to retrieve * @param clazz typed entity class * @return entity of the given type or null */ @Nullable @CheckForNull E findOneById(String entityTypeId, Object id, Fetch fetch, Class clazz); /** * Find one entity based on id. Returns null if not exists * * @throws MolgenisDataException if the repository of the entity isn't a Queryable */ @Nullable @CheckForNull Entity findOne(String entityTypeId, Query q); /** * type-save find an entity by it's id * * @param q query */ @Nullable @CheckForNull E findOne(String entityTypeId, Query q, Class clazz); /** * Adds an entity to it's repository Note: the caller is responsible for updating the other side * of bidirectional relationships (e.g. one-to-many attributes). * * @throws MolgenisDataException if the repository of the entity isn't a Writable */ void add(String entityTypeId, Entity entity); /** * Adds entities to it's repository Note: the caller is responsible for updating the other side of * bidirectional relationships (e.g. one-to-many attributes). * * @param entities entities */ void add(String entityTypeId, Stream entities); /** * Updates an entity Note: the caller is responsible for updating the other side of bidirectional * relationships (e.g. one-to-many attributes). * * @throws MolgenisDataException if the repository of the entity isn't an Updateable */ void update(String entityTypeId, Entity entity); /** * Updates entities Note: the caller is responsible for updating the other side of bidirectional * relationships (e.g. one-to-many attributes). * * @param entities entities */ void update(String entityTypeId, Stream entities); /** * Deletes an entity * * @throws MolgenisDataException if the repository of the entity isn't an Updateable */ void delete(String entityTypeId, Entity entity); /** * Delete entities from it's repository * * @param entities entities */ void delete(String entityTypeId, Stream entities); /** * Deletes an entity by it's id * * @param id entity id */ void deleteById(String entityTypeId, Object id); /** * Deletes entities by id * * @param ids entity ids */ void deleteAll(String entityTypeId, Stream ids); /** Deletes all entities */ void deleteAll(String entityTypeId); /** * Returns an untyped query * * @param entityTypeId entity name * @return an untyped query */ Query query(String entityTypeId); /** * Returns a typed query * * @param entityClass entity class * @param entity type * @return a typed query */ Query query(String entityTypeId, Class entityClass); /** * Creates counts off all possible combinations of xAttr and yAttr attributes of an entity * * @param aggregateQuery aggregation query * @return aggregation results */ AggregateResult aggregate(String entityTypeId, AggregateQuery aggregateQuery); /** Get identifiers of all entity types in this source */ Stream getEntityTypeIds(); }