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"

Line 9: Line 9:
 
   This template has the duty to be a bridge between the entity model and Graph database.
 
   This template has the duty to be a bridge between the entity model and Graph database.
 
    
 
    
```java  
+
<pre lang="java">
 
    
 
    
 
GraphTemplate graphTemplate =//instance
 
GraphTemplate graphTemplate =//instance
Line 20: Line 20:
 
graphTemplate.delete(person.getId());
 
graphTemplate.delete(person.getId());
  
```
+
</pre>
 +
 
  
 
=== Edge ===
 
=== Edge ===
Line 30: Line 31:
 
The representation of Edge that links two Entity. Along with its Property objects, an Edge has both a Direction and a label.
 
The representation of Edge that links two Entity. Along with its Property objects, an Edge has both a Direction and a label.
  
```java
+
<pre lang="java">
 
Person poliana = graphTemplate.insert(Person.builder().withName("Poliana").withAge(25).build());
 
Person poliana = graphTemplate.insert(Person.builder().withName("Poliana").withAge(25).build());
 
Book shack = graphTemplate.insert(Book.builder().withAge(2007).withName("The Shack").build());
 
Book shack = graphTemplate.insert(Book.builder().withAge(2007).withName("The Shack").build());
Line 39: Line 40:
 
Person outbound = edge.getOutbound();
 
Person outbound = edge.getOutbound();
 
Book inbound = edge.getInbound();
 
Book inbound = edge.getInbound();
```
+
</pre>
  
 
==== Find an EdgeEntity ====
 
==== Find an EdgeEntity ====
  
  
```java
+
<pre lang="java">
 
Optional<EdgeEntity<Person, Book>> reads = graphTemplate.edge(edgeId);
 
Optional<EdgeEntity<Person, Book>> reads = graphTemplate.edge(edgeId);
```
+
</pre>
  
  
Line 55: Line 56:
 
To use Repository, just need to create a new interface that extends the Repository.
 
To use Repository, just need to create a new interface that extends the Repository.
  
```java
+
<pre lang="java">
 
  interface PersonRepository extends Repository<Person, String> {
 
  interface PersonRepository extends Repository<Person, String> {
  
 
}
 
}
```
+
</pre>
  
 
The qualifier is mandatory to define the database type that will be used at the injection point moment.
 
The qualifier is mandatory to define the database type that will be used at the injection point moment.
  
```java
+
<pre lang="java">
 
@Inject
 
@Inject
 
@Database(DatabaseType.GRAPH)
 
@Database(DatabaseType.GRAPH)
 
private PersonRepository graphRepository;
 
private PersonRepository graphRepository;
```
+
</pre>
  
 
So, Artemis will inject automatically.
 
So, Artemis will inject automatically.
  
```java
+
<pre lang="java">
  
 
PersonRepository repository = //instance
 
PersonRepository repository = //instance
Line 84: Line 85:
 
repository.save(people);
 
repository.save(people);
  
```
+
</pre>
  
 
== Transactional ==
 
== Transactional ==
 
The Transactional annotation provides the application the ability to declaratively control transaction boundaries on CDI managed beans. *org.apache.tinkerpop.gremlin.structure.Transaction*
 
The Transactional annotation provides the application the ability to declaratively control transaction boundaries on CDI managed beans. *org.apache.tinkerpop.gremlin.structure.Transaction*
  
```java
+
<pre lang="java">
  
 
   @Transactional//that will use the current trasaction
 
   @Transactional//that will use the current trasaction
Line 97: Line 98:
 
     //after the method will commit the transaction
 
     //after the method will commit the transaction
  
```
+
</pre>
  
 
== Search information from Repository ==
 
== Search information from Repository ==
Line 118: Line 119:
 
* BothV
 
* BothV
  
```java
+
<pre lang="java">
 
interface PersonRepository extends Repository<Person, Long> {
 
interface PersonRepository extends Repository<Person, Long> {
  
Line 133: Line 134:
 
     void deleteByNickName(String nickname);
 
     void deleteByNickName(String nickname);
 
}
 
}
```
+
</pre>

Revision as of 06:35, 22 September 2017

Graph-extension

![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.

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