Skip to content

Commit d64e42f

Browse files
authored
Merge pull request #311 from eclipse-jnosql/include-neo4j-support
Create support to Neo4J database
2 parents 19cabf9 + 55a0825 commit d64e42f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+3621
-5
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to https://semver.org/spec/v2.0.0.html[Semantic Version
1111
=== Added
1212

1313
- Include TCK tests
14+
- Include support to Neo4J
1415

1516
=== Changed
1617

README.adoc

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1830,8 +1830,82 @@ SolrTemplate template;
18301830
List<Person> people = template.solr("age:@age AND type:@type AND _entity:@entity", params);
18311831
----
18321832

1833+
== Neo4J
18331834

1834-
=== Graph (Apache Tinkerpop)
1835+
image::https://jnosql.github.io/img/logos/neo4j.png[Neo4J Project,align="center",width=25%,height=25%]
1836+
https://neo4j.com/[Neo4J] is a highly scalable, native graph database designed to manage complex relationships in data. It enables developers to build applications that leverage the power of graph traversal, pattern matching, and high-performance querying using the **Cypher** query language.
1837+
1838+
This API provides support for **Graph** database operations, including entity persistence, query execution via Cypher, and relationship traversal.
1839+
1840+
=== How To Install
1841+
1842+
You can use either the Maven or Gradle dependencies:
1843+
1844+
[source,xml]
1845+
----
1846+
<dependency>
1847+
<groupId>org.eclipse.jnosql.databases</groupId>
1848+
<artifactId>jnosql-neo4j</artifactId>
1849+
<version>1.1.4</version>
1850+
</dependency>
1851+
----
1852+
1853+
=== Configuration
1854+
1855+
This API provides the `Neo4JDatabaseConfigurations` class to programmatically establish the credentials. You can configure Neo4J properties using the https://microprofile.io/microprofile-config/[MicroProfile Config] specification.
1856+
1857+
[cols="2,4"]
1858+
|===
1859+
| Configuration Property | Description
1860+
1861+
| `jnosql.neo4j.uri` | The connection URI for the Neo4J database. Example: `bolt://localhost:7687`
1862+
| `jnosql.neo4j.username` | The username for authentication.
1863+
| `jnosql.neo4j.password` | The password for authentication.
1864+
| `jnosql.neo4j.database` | The target database name.
1865+
|===
1866+
1867+
==== Example Using MicroProfile Config
1868+
1869+
[source,properties]
1870+
----
1871+
jnosql.neo4j.uri=bolt://localhost:7687
1872+
jnosql.neo4j.username=neo4j
1873+
jnosql.neo4j.password=yourpassword
1874+
jnosql.neo4j.database=neo4j
1875+
----
1876+
1877+
=== Template API
1878+
1879+
The `Neo4JTemplate` interface extends `GraphTemplate` and allows for dynamic Cypher execution.
1880+
1881+
[source,java]
1882+
----
1883+
@Inject
1884+
private Neo4JTemplate template;
1885+
1886+
List<Person> people = template.cypherQuery("MATCH (p:Person) WHERE p.name = $name RETURN p", params);
1887+
var edge = template.edge(otavio, "FRIENDS_WITH", ada);
1888+
----
1889+
1890+
=== Repository Support
1891+
1892+
The `Neo4JRepository` interface extends the `NoSQLRepository` interface and enables query execution using the `@Cypher` annotation.
1893+
1894+
[source,java]
1895+
----
1896+
@Repository
1897+
interface PersonRepository extends Neo4JRepository<Person, String> {
1898+
1899+
@Cypher("MATCH (p:Person) RETURN p")
1900+
List<Person> findAll();
1901+
1902+
@Cypher("MATCH (p:Person) WHERE p.name = $name RETURN p")
1903+
List<Person> findByName(@Param("name") String name);
1904+
}
1905+
----
1906+
1907+
1908+
== Graph (Apache Tinkerpop)
18351909

18361910
Currently, the Jakarta NoSQL doesn't define an API for Graph database types but Eclipse JNoSQL provides a Graph template to explore the specific behavior of this NoSQL type.
18371911

jnosql-mongodb/src/main/java/org/eclipse/jnosql/databases/mongodb/communication/DocumentQueryConversor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ public static Bson convert(CriteriaCondition condition) {
5757
}
5858
case LIKE -> Filters.regex(document.name(), Pattern.compile(prepareRegexValue(value.toString())));
5959
case AND -> {
60-
List<CriteriaCondition> andList = condition.element().value().get(new TypeReference<>() {
60+
List<CriteriaCondition> andConditions = condition.element().value().get(new TypeReference<>() {
6161
});
62-
yield Filters.and(andList.stream()
62+
yield Filters.and(andConditions.stream()
6363
.map(DocumentQueryConversor::convert).toList());
6464
}
6565
case OR -> {
66-
List<CriteriaCondition> orList = condition.element().value().get(new TypeReference<>() {
66+
List<CriteriaCondition> orConditions = condition.element().value().get(new TypeReference<>() {
6767
});
68-
yield Filters.or(orList.stream()
68+
yield Filters.or(orConditions.stream()
6969
.map(DocumentQueryConversor::convert).toList());
7070
}
7171
case BETWEEN -> {

jnosql-neo4j/pom.xml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright (c) 2022 Contributors to the Eclipse Foundation
4+
~ All rights reserved. This program and the accompanying materials
5+
~ are made available under the terms of the Eclipse Public License v1.0
6+
~ and Apache License v2.0 which accompanies this distribution.
7+
~ The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
8+
~ and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
9+
~
10+
~ You may elect to redistribute this code under either of these licenses.
11+
~
12+
~ Contributors:
13+
~
14+
~ Otavio Santana
15+
-->
16+
17+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
18+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
19+
<modelVersion>4.0.0</modelVersion>
20+
<parent>
21+
<groupId>org.eclipse.jnosql.databases</groupId>
22+
<artifactId>jnosql-databases-parent</artifactId>
23+
<version>1.1.5-SNAPSHOT</version>
24+
</parent>
25+
26+
<artifactId>jnosql-neo4j</artifactId>
27+
28+
<properties>
29+
<neo4j.driver>5.27.0</neo4j.driver>
30+
</properties>
31+
32+
<dependencies>
33+
<dependency>
34+
<groupId>org.neo4j.driver</groupId>
35+
<artifactId>neo4j-java-driver</artifactId>
36+
<version>${neo4j.driver}</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>${project.groupId}</groupId>
40+
<artifactId>jnosql-database-commons</artifactId>
41+
<version>${project.version}</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.eclipse.jnosql.mapping</groupId>
45+
<artifactId>jnosql-mapping-semistructured</artifactId>
46+
<version>${project.version}</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.testcontainers</groupId>
50+
<artifactId>neo4j</artifactId>
51+
<version>${testcontainers.version}</version>
52+
<scope>test</scope>
53+
</dependency>
54+
</dependencies>
55+
56+
</project>

0 commit comments

Comments
 (0)