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

Difference between revisions of "JNoSQL/Artemis/Graph"

 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== Graph-extension ==
 
== Graph-extension ==
 +
[[File:Tinkerpop.png]]
  
![Graph Project](https://github.com/JNOSQL/jnosql-site/blob/master/assets/img/logos/tinkerpop.png)
 
  
 
JNoSQL has the support of the Graph database through the TinkerPop project. Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) and graph analytic systems (OLAP). The TinkerPop has support to more than twenty Graph databases.
 
JNoSQL has the support of the Graph database through the TinkerPop project. Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) and graph analytic systems (OLAP). The TinkerPop has support to more than twenty Graph databases.
Line 104: Line 104:
 
The Repository also has a method query from the method name. These are the keywords:
 
The Repository also has a method query from the method name. These are the keywords:
  
* **findBy**: The prefix to find some information
+
* <b>findBy</b>: The prefix to find some information
* **deleteBy**: The prefix to delete some information
+
* <b>deleteBy</b>: The prefix to delete some information
  
</br>
+
<br/>
 
<p>Also the operators:</p>
 
<p>Also the operators:</p>
  
Line 120: Line 120:
 
* <b>BothV</b>
 
* <b>BothV</b>
  
</br>
+
<br/>
</br>
+
<br/>
  
 
<pre lang="java">
 
<pre lang="java">

Latest revision as of 06:42, 22 September 2017

Graph-extension

Tinkerpop.png


JNoSQL has the support of the Graph database through the TinkerPop project. Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) and graph analytic systems (OLAP). The TinkerPop has support to more than twenty Graph databases.

Graph Template

This template has the duty to be a bridge between the entity model and Graph database.

  
GraphTemplate graphTemplate =//instance

 Person person = builder().withAge(27).withName("Otavio").build();
graphTemplate.insert(person);

person.setAge(29);
graphTemplate.update(person);
graphTemplate.delete(person.getId());


Edge

An Edge links two Vertex objects. Along with its Property objects, an Edge has both a Direction and a label. The Direction determines which Vertex is the tail Vertex (out Vertex) and which Vertex is the head Vertex (in Vertex). The Edge label determines the type of relationship that exists between the two vertices.

EdgeEntity<OUT, IN>

The representation of Edge that links two Entity. Along with its Property objects, an Edge has both a Direction and a label.

Person poliana = graphTemplate.insert(Person.builder().withName("Poliana").withAge(25).build());
Book shack = graphTemplate.insert(Book.builder().withAge(2007).withName("The Shack").build());
EdgeEntity<Person, Book> reads = graphTemplate.edge(poliana, "reads", shack);
reads.add("where", "Brazil");
int size = edge.size();
String label = edge.getLabel();
Person outbound = edge.getOutbound();
Book inbound = edge.getInbound();

Find an EdgeEntity

Optional<EdgeEntity<Person, Book>> reads = graphTemplate.edge(edgeId);


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.GRAPH)
private PersonRepository graphRepository;

So, Artemis will inject automatically.


PersonRepository repository = //instance

Person person = new Person();
person.setNickname("diana");
person.setName("Diana Goodness");

List<Person> people = Collections.singletonList(person);

repository.save(person);
repository.save(people);

Transactional

The Transactional annotation provides the application the ability to declaratively control transaction boundaries on CDI managed beans. *org.apache.tinkerpop.gremlin.structure.Transaction*


   @Transactional//that will use the current trasaction
    public void save(Site site) {
        repository.save(site);
    }
    //after the method will commit the transaction

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
  • Between
  • LessThan
  • GreaterThan
  • LessThanEqual
  • GreaterThanEqual
  • OutV
  • InV
  • BothV



interface PersonRepository extends Repository<Person, Long> {

    List<Person> findByAddress(String address);

    Stream<Person> findByName(String name);

    Stream<Person> findByNameAndKnowsOutV(String name);
    
    Stream<Person> findByNameAndBothV(String name, String label);

    Optional<Person> findByNickname(String nickname);

    void deleteByNickName(String nickname);
}

Back to the top