Class Repository<S extends DataSource<E,?>,E extends DataEntity,M extends IModel>
- java.lang.Object
-
- it.unipd.dei.eis.core.common.Cache<Context,List<M>>
-
- it.unipd.dei.eis.domain.repositories.Repository<S,E,M>
-
- Type Parameters:
S- The data sourceE- The data entityM- The model
- Direct Known Subclasses:
CsvRepository,JsonRepository,TermsExtractionRepository,TheGuardianRepository
public abstract class Repository<S extends DataSource<E,?>,E extends DataEntity,M extends IModel> extends Cache<Context,List<M>>
Repository is the abstract class for repositories.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) SdataSourceThe data source.
-
Constructor Summary
Constructors Constructor Description Repository(S dataSource)Creates a new Repository.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) Madapt(E dataEntity)Adapts a data entity to a model.(package private) Eadapt(M model)Adapts a model to a data entity.List<M>pull(Context context)Pulls the models from the data source.(package private) List<M>pullData(Context context)Pulls the models from the data source.voidpush(Context context, List<M> models)Pushes the models to the data source.(package private) voidpushData(Context context, List<M> models)Pushes the models to the data source.
-
-
-
Field Detail
-
dataSource
final S extends DataSource<E,?> dataSource
The data source.
-
-
Constructor Detail
-
Repository
Repository(S dataSource)
Creates a new Repository.- Parameters:
dataSource- The data source
-
-
Method Detail
-
pull
public final List<M> pull(Context context) throws Exception
Pulls the models from the data source. If the models are cached, the cache is used to improve performance.- Parameters:
context- The context to use- Returns:
- List of models
- Throws:
UnsupportedOperationException- if not implementedException- if an error occurs
-
pullData
List<M> pullData(Context context) throws Exception
Pulls the models from the data source. Provides a default implementation that uses the data source. Override this method to implement a custom pull.- Parameters:
context- The context to use- Returns:
- List of models
- Throws:
Exception- if an error occurs
-
push
public final void push(Context context, List<M> models) throws Exception
Pushes the models to the data source.- Parameters:
context- The context to usemodels- The models to push- Throws:
UnsupportedOperationException- if not implementedException- if an error occurs
-
pushData
void pushData(Context context, List<M> models) throws Exception
Pushes the models to the data source. Provides a default implementation that uses the data source. Override this method to implement a custom push.- Parameters:
context- The context to usemodels- The models to push- Throws:
UnsupportedOperationException- if not implementedException- if an error occurs
-
adapt
M adapt(E dataEntity)
Adapts a data entity to a model. Internally used bypull(Context).- Parameters:
dataEntity- The data entity- Returns:
- The model
- Throws:
UnsupportedOperationException- if not implemented
-
adapt
E adapt(M model)
Adapts a model to a data entity. Internally used bypush(Context, List).- Parameters:
model- The model- Returns:
- The data entity
- Throws:
UnsupportedOperationException- if not implemented
-
-