Repository
In addition to template class, Artemis has the Repository. This interface helps the Entity repository to save, update, delete and retrieve information.
To use Repository, just need to create a new interface that extends the Repository.
interface PersonRepository extends Repository<Person, String> {
}The qualifier is mandatory to define the database type that will be used at the injection point moment.
@Inject
@Database(DatabaseType.DOCUMENT)
private PersonRepository documentRepository;
@Inject
@Database(DatabaseType.COLUMN)
private PersonRepository columnRepository;And then, as the repository class, create either a ColumnFamilyManager or a DocumentCollectionManager with produces method:
@Produces
public DocumentCollectionManager getManager() {
DocumentCollectionManager manager = //instance
return manager;
}
@Produces
public ColumnFamilyManager getManager() {
ColumnFamilyManager manager = //instance
return manager;
}To work with multiple database you can use qualifiers:
So, Artemis will inject automatically.
Search information from Repository
The Repository also has a method query from the method name. These are the keywords:
findBy: The prefix to find some information
deleteBy: The prefix to delete some information
Also the operators:
And
Or
Between
LessThan
GreaterThan
LessThanEqual
GreaterThanEqual
Like
OrderBy
OrderBy____Desc
OrderBy_____ASC
Using these keywords, Artemis will create the queries.
Using Repository as asynchronous way
The RepositoryAsync interface works similarly as Repository but with asynchronous work.
In other words, just inject and then create an Entity Manager async with producers method.
Also, delete and retrieve information with a callback.
Repository at KeyValue
Key-value database has support to Repository.
And inject the resource.
Then use a producer to BucketManager
You can use qualifier when you want to use a different database in the same application.
Once there is not another to both delete and find information, there isn't dynamic query.
In the key-value resource, the Repository does not support method query resource.
Last updated