Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "JNoSQL/Artemis/OrientDB"
(Created page with "== OrientDB Extension == The goal of an extension goes beyond the Artemis API-core, and with OrientDB Extensions, it does not look different. OrientDB Extension has classes s...") |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== OrientDB Extension == | == OrientDB Extension == | ||
− | The goal of an extension goes beyond the Artemis API-core, and with OrientDB Extensions, it does not look different. OrientDB Extension has classes such as | + | The goal of an extension goes beyond the Artemis API-core, and with OrientDB Extensions, it does not look different. OrientDB Extension has classes such as OrientDBTemplate and OrientDBTemplateAsync whose have support to OrientDB particular behavior as n1ql. |
== Maven Dependency == | == Maven Dependency == | ||
Line 25: | Line 25: | ||
</pre> | </pre> | ||
− | == OrientDB | + | == OrientDB Template == |
− | + | OrientDBTemplate and OrientDBTemplateAsync are specialized classes from DocumentTemplate and DocumentTemplateAsync respectively, so they have all methods plus the OrientDB methods whose has in OrientDB driver such as query. | |
To active, this resource just needs to produce an OrientDBDocumentCollectionManager in a CDI context. | To active, this resource just needs to produce an OrientDBDocumentCollectionManager in a CDI context. | ||
Line 46: | Line 46: | ||
<pre lang="java"> | <pre lang="java"> | ||
@Inject | @Inject | ||
− | private | + | private OrientDBTemplate template; |
public void sample() { | public void sample() { | ||
− | List<Person> people = repository. | + | List<Person> people = repository.sql("select * from Person where name = ?", "Ada"); |
} | } | ||
</pre> | </pre> | ||
Line 66: | Line 66: | ||
− | ==== | + | ==== Repository ==== |
− | Beyond the document repository, OrientDB Extension also has the | + | Beyond the document repository, OrientDB Extension also has the Repository specialization to both sync and async works. These specializations allow querying with query. |
Line 75: | Line 75: | ||
<pre lang="java"> | <pre lang="java"> | ||
− | public interface PersonRepository extends | + | public interface PersonRepository extends OrientDBRepository<Person> { |
@SQL("select * from Person") | @SQL("select * from Person") | ||
Line 82: | Line 82: | ||
@SQL("select * from Person where name = ?") | @SQL("select * from Person where name = ?") | ||
List<Person> findByName(String name); | List<Person> findByName(String name); | ||
− | |||
− | |||
+ | @SQL("select * from Person where age = :age") | ||
+ | List<Person> findByAge(@Param("age") Integer age); | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
</pre> | </pre> | ||
+ | |||
<pre lang="java"> | <pre lang="java"> | ||
− | public interface PersonAsyncRepository extends | + | public interface PersonAsyncRepository extends OrientDBRepositoryAsync<Person> { |
Person findByName(String name); | Person findByName(String name); |
Latest revision as of 04:02, 17 November 2017
Contents
OrientDB Extension
The goal of an extension goes beyond the Artemis API-core, and with OrientDB Extensions, it does not look different. OrientDB Extension has classes such as OrientDBTemplate and OrientDBTemplateAsync whose have support to OrientDB particular behavior as n1ql.
Maven Dependency
To use the OrientDB extension to Artemis:
<dependency>
<groupId>org.jnosql.artemis</groupId>
<artifactId>orientdb-extension</artifactId>
<version>version</version>
</dependency>
E.g:
<dependency>
<groupId>org.jnosql.artemis</groupId>
<artifactId>orientdb-extension</artifactId>
<version>0.0.1</version>
</dependency>
OrientDB Template
OrientDBTemplate and OrientDBTemplateAsync are specialized classes from DocumentTemplate and DocumentTemplateAsync respectively, so they have all methods plus the OrientDB methods whose has in OrientDB driver such as query. To active, this resource just needs to produce an OrientDBDocumentCollectionManager in a CDI context.
@Produces
public OrientDBDocumentCollectionManager getManager() {
//code
return managerFactory.get(KEY_SPACE);
}
Done, the Artemis will take and manage the bean to you.
@Inject
private OrientDBTemplate template;
public void sample() {
List<Person> people = repository.sql("select * from Person where name = ?", "Ada");
}
The similar thing happens with the OrientDBDocumentRepositoryAsync just produces the OrientDBDocumentCollectionManagerAsync.
@Produces
public OrientDBDocumentCollectionManagerAsync getManagerAsync() {
//code
return managerFactory.get(KEY_SPACE);
}
Repository
Beyond the document repository, OrientDB Extension also has the Repository specialization to both sync and async works. These specializations allow querying with query.
Sample Code
public interface PersonRepository extends OrientDBRepository<Person> {
@SQL("select * from Person")
List<Person> findAll();
@SQL("select * from Person where name = ?")
List<Person> findByName(String name);
@SQL("select * from Person where age = :age")
List<Person> findByAge(@Param("age") Integer age);
}
public interface PersonAsyncRepository extends OrientDBRepositoryAsync<Person> {
Person findByName(String name);
@SQL("select * from Person where name= ?")
void queryName(String name);
@SQL("select * from Person where name= ?")
void queryName(String name, Consumer<List<Person>> callBack);
}