TuGraph Java Client

September 28, 2023 ยท View on GitHub

This repo is a Java client for developers to connect to TuGraph.

Features

  • RPC client in Java
  • OGM, short for Object-Graph Mapping, supports mapping entities and relations in graph to Java objects, which speeds up the Java development process.

Prerequisites

  • Java 8
  • TuGraph Server deployed

Usage

Dependency Integration

If you are using Maven to manage the dependency in your Java project, you can add the following snippet to your pom.xml


<dependency>
    <groupId>com.antgroup.tugraph</groupId>
    <artifactId>tugraph-db-java-rpc-client</artifactId>
    <version>${version}</version>
</dependency>
<dependency>
  <groupId>com.antgroup.tugraph</groupId>
  <artifactId>tugraph-db-ogm-api</artifactId>
  <version>${version}</version>
</dependency>
<dependency>
  <groupId>com.antgroup.tugraph</groupId>
  <artifactId>tugraph-db-ogm-core</artifactId>
  <version>${version}</version>
</dependency>
<dependency>
  <groupId>com.antgroup.tugraph</groupId>
  <artifactId>tugraph-db-rpc-driver</artifactId>
  <version>${version}</version>
</dependency>

Java client usage

Please refer to the code example:

Java Client Test

OGM usage

Please refer to the code example: OGM Test

OGM API Reference

FeatureAPI
Save objectvoid session.save(T object)
Delete objectvoid session.delete(T object)
Delete with a typevoid session.deleteAll(Class<T> type)
Purge databasevoid purgeDatabase()
Update an objectvoid session.save(T newObject)
Load with a singe IDT load(Class type, ID id)
Load with IDsCollection<T> loadAll(Class<T> type, Collection ids)
Load with a typeCollection<T> loadAll(Class<T> type)
Load with filtersCollection<T> loadAll(Class<T> type, Filters filters)
Cypher query with specific result typeT queryForObject(Class<T> objectType, String cypher, Map<String, ?> parameters)
Cypher queryResult query(String cypher, Map<String, ?> parameters)

FAQ

Upgrade the version

Revision feature is used in this project to keep all the versions in submodules consistent. If you want to upgrade the version, e.g. for SNAPSHOT version, just set the ${revision} property instead of using mvn version:set.

Version Map

Client VersionTuGraph Version
1.1.13.3.3
1.2.1, 1.2.23.4.x, 3.5.0
1.3.03.6.0
1.4.0, 1.4.14.0.0, 4.0.1

Note:

  • 3.3.0~3.3.2 versions of TuGraph Server are legacy versions before java-client refactoring, which are not supported by this repo.
  • 1.1.0 and 1.2.0 is not available due to the unconsumable issue introduced by ${revision} variable in pom file[1].

[1] https://stackoverflow.com/questions/41086512/maven-issue-to-build-one-module-using-revision-property