Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

JNoSQL/Artemis/OrientDB

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);
    }

Links

Back to the top