Skip to content

Commit

Permalink
cleanup the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
mangalaman93 committed Dec 13, 2024
1 parent 1f66396 commit 7c822b1
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 111 deletions.
2 changes: 1 addition & 1 deletion PUBLISHING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ossrhPassword=<…password…>
- Update `dgraph4j version` in `grpc-netty` table in README.
- Update CHANGELOG.
- Raise a PR for the above changes. Put the changelog in PR description and merge it.
- Run `./gradlew uploadArchives`.
- Run `./gradlew publish`.
- Release the deployment by following the steps on the page _Releasing the Deployment_ (link in references below).
- Also cut a release tag on GitHub with the new version.

Expand Down
137 changes: 78 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

A minimal implementation for a Dgraph client for Java 11 and above, using [grpc].

### IMP NOTE:
### IMP NOTE:
v24.0.0 features an upgraded protobuf dependency which requires an upgrade to JDK 11. On account of this breaking change, all legacy applications built upon JDK 8 would be impacted.

[grpc]: https://grpc.io/
Expand All @@ -22,28 +22,41 @@ and understand how to run and work with Dgraph.
**Use [Discuss Issues](https://discuss.dgraph.io/c/issues/35/clients/46) for reporting issues about this repository.**

## Table of Contents
- [Download](#download)
- [Supported Versions](#supported-versions)
- [Quickstart](#quickstart)
- [Intro](#intro)
- [Using the Synchronous Client](#using-the-synchronous-client)
* [Creating a Client](#creating-a-client)
* [Creating a Client for Dgraph Cloud](#creating-a-client-for-dgraph-cloud)
* [Creating a Secure Client Using TLS](#creating-a-secure-client-using-tls)
* [Check Dgraph Version](#check-dgraph-version)
* [Login Using ACL](#login-using-acl)
* [Altering the Database](#altering-the-database)
* [Creating a Transaction](#creating-a-transaction)
* [Running a Mutation](#running-a-mutation)
* [Committing a Transaction](#committing-a-transaction)
* [Running a Query](#running-a-query)
* [Running a Query with RDF response](#running-a-query-with-rdf-response)
* [Running an Upsert: Query + Mutation](#running-an-upsert-query--mutation)
* [Running a Conditional Upsert](#running-a-conditional-upsert)
* [Setting Deadlines](#setting-deadlines)
* [Setting Metadata Headers](#setting-metadata-headers)
* [Helper Methods](#helper-methods)
* [Closing the DB Connection](#closing-the-db-connection)
- [Dgraph Client for Java](#dgraph-client-for-java)
- [IMP NOTE:](#imp-note)
- [Table of Contents](#table-of-contents)
- [Download](#download)
- [Supported Versions](#supported-versions)
- [Note regarding Java 1.8.x support:](#note-regarding-java-18x-support)
- [Quickstart](#quickstart)
- [Intro](#intro)
- [Using the Synchronous Client](#using-the-synchronous-client)
- [Creating a Client](#creating-a-client)
- [Creating a Client for Dgraph Cloud](#creating-a-client-for-dgraph-cloud)
- [Creating a Secure Client using TLS](#creating-a-secure-client-using-tls)
- [Check Dgraph version](#check-dgraph-version)
- [Login Using ACL](#login-using-acl)
- [Altering the Database](#altering-the-database)
- [Creating a Transaction](#creating-a-transaction)
- [Running a Mutation](#running-a-mutation)
- [Committing a Transaction](#committing-a-transaction)
- [Running a Query](#running-a-query)
- [Running a Query with RDF response](#running-a-query-with-rdf-response)
- [Running an Upsert: Query + Mutation](#running-an-upsert-query--mutation)
- [Running a Conditional Upsert](#running-a-conditional-upsert)
- [Setting Deadlines](#setting-deadlines)
- [Setting deadlines for all requests](#setting-deadlines-for-all-requests)
- [Setting deadlines for a single request](#setting-deadlines-for-a-single-request)
- [Setting Metadata Headers](#setting-metadata-headers)
- [Helper Methods](#helper-methods)
- [Delete multiple edges](#delete-multiple-edges)
- [Closing the DB Connection](#closing-the-db-connection)
- [Using the Asynchronous Client](#using-the-asynchronous-client)
- [Checking the request latency](#checking-the-request-latency)
- [Development](#development)
- [Building the source](#building-the-source)
- [Code Style](#code-style)
- [Running unit tests](#running-unit-tests)
* [Using the Asynchronous Client](#using-the-asynchronous-client)
* [Checking the request latency](#checking-the-request-latency)
- [Development](#development)
Expand All @@ -61,6 +74,7 @@ grab via Maven:
<version>24.1.0</version>
</dependency>
```

or Gradle:
```groovy
compile 'io.dgraph:dgraph4j:24.1.0'
Expand All @@ -71,58 +85,62 @@ compile 'io.dgraph:dgraph4j:24.1.0'
Depending on the version of Dgraph that you are connecting to, you will have to
use a different version of this client.

| Dgraph version | dgraph4j version | java version |
|:--------------:|:-----------------:|:------------:|
| 1.0.X | 1.X.X | 1.9.X |
| 1.1.0 - 2.X.X | 2.X.X | 1.9.X |
|20.03.X-20.07.X | 20.03.X | 1.9.X |
| 20.11.X | 20.11.X | 1.9.X |
| >= 21.XX.X | 21.XX.X | 1.9.X |
| >= 24.X.X | 24.X.X | 11 |
| Dgraph version | dgraph4j version | java version |
| :-------------: | :--------------: | :----------: |
| 1.0.X | 1.X.X | 1.9.X |
| 1.1.0 - 2.X.X | 2.X.X | 1.9.X |
| 20.03.X-20.07.X | 20.03.X | 1.9.X |
| 20.11.X | 20.11.X | 1.9.X |
| >= 21.XX.X | 21.XX.X | 1.9.X |
| >= 24.X.X | 24.X.X | 11 |

#### Note regarding Java 1.8.x support:
v24.0.0 features an upgraded protoc-protobuf dependency that requires an upgrade to JDK 11. This version is incompatible with Java 1.8 and and requires an upgrade to Java 11.
v24.0.0 features an upgraded protoc-protobuf dependency that requires an upgrade to JDK 11.
This version is incompatible with Java 1.8 and and requires an upgrade to Java 11.

The following is only applicable to dgraph4j versions < v24.X.X.
The following is only applicable to dgraph4j versions < v24.X.X.
* If you aren't using gRPC with TLS, then the above version table will work for you with Java
1.8.x too.
* If you're using gRPC with TLS on Java 1.8.x, then you will need to follow gRPC docs [here
](https://github.com/grpc/grpc-java/blob/master/SECURITY.md#tls-on-non-android). Basically, it
will require you to add the following dependency in your app with correct version for the
corresponding `grpc-netty` version used by `dgraph4j`. You can find out the correct version of
will require you to add the following dependency in your app with correct version for the
corresponding `grpc-netty` version used by `dgraph4j`. You can find out the correct version of
the dependency to use from the version combination table in [this section] in `grpc-netty` docs.

For maven:

```xml
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version><!-- See table in gRPC docs for correct version --></version>
</dependency>
```

For Gradle:

```groovy
compile 'io.netty:netty-tcnative-boringssl-static:<See table in gRPC docs for correct version>'
```

The following table lists the `grpc-netty` versions used by different `dgraph4j` versions over time, along with the supported versions of `netty-tcnative-boringssl-static` for the corresponding `grpc-netty` version:

| dgraph4j version | grpc-netty version | netty-tcnative-boringssl-static version |
|:-----------------:|:------------------:|:---------------------------------------:|
| 1.0.0-1.2.0 | 1.7.0 | 2.0.6.Final |
| 1.4.0-1.6.0 | 1.10.0 | 2.0.7.Final |
| 1.7.0 | 1.15.0 | 2.0.12.Final |
| 1.7.3-1.7.5 | 1.15.1 | 2.0.12.Final |
| 2.0.0-2.1.0 | 1.22.1 | 2.0.25.Final |
| 20.03.0-20.03.3 | 1.26.0 | 2.0.26.Final |
| >= 20.11.0 | 1.34.1 | 2.0.31.Final |
| >= 24.0.0 | 1.65.1 | 4.1.100.Final |
| >= 24.1.0 | 1.68.2 | 4.1.110.Final |

For example, when using `dgraph4j v24.0.0`, the version of the `netty-tcnative-boringssl-static` dependency to be used is `4.1.100.Final`, as suggested by gRPC docs for `grpc-netty v1.65.1`.

The following table lists the `grpc-netty` versions used by different `dgraph4j` versions
over time, along with the supported versions of `netty-tcnative-boringssl-static`
for the corresponding `grpc-netty` version:

| dgraph4j version | grpc-netty version | netty-tcnative-boringssl-static version |
| :--------------: | :----------------: | :-------------------------------------: |
| 1.0.0-1.2.0 | 1.7.0 | 2.0.6.Final |
| 1.4.0-1.6.0 | 1.10.0 | 2.0.7.Final |
| 1.7.0 | 1.15.0 | 2.0.12.Final |
| 1.7.3-1.7.5 | 1.15.1 | 2.0.12.Final |
| 2.0.0-2.1.0 | 1.22.1 | 2.0.25.Final |
| 20.03.0-20.03.3 | 1.26.0 | 2.0.26.Final |
| >= 20.11.0 | 1.34.1 | 2.0.31.Final |
| >= 24.0.0 | 1.65.1 | 4.1.100.Final |
| >= 24.1.0 | 1.68.2 | 4.1.110.Final |

For example, when using `dgraph4j v24.0.0`, the version of the `netty-tcnative-boringssl-static`
dependency to be used is `4.1.100.Final`, as suggested by gRPC docs for `grpc-netty v1.65.1`.

[this section]: https://github.com/grpc/grpc-java/blob/master/SECURITY.md#netty

Expand Down Expand Up @@ -457,7 +475,7 @@ txn.doRequest(request);

### Running a Query with RDF response

You can get query results as an RDF response by calling either `queryRDF()` or `queryRDFWithVars()`.
You can get query results as an RDF response by calling either `queryRDF()` or `queryRDFWithVars()`.
The response contains the `getRdf()` method, which will provide the RDF encoded output.

**Note**: If you are querying for `uid` values only, use a JSON format response
Expand Down Expand Up @@ -505,8 +523,9 @@ txn.doRequest(request);

### Running a Conditional Upsert

The upsert block also allows specifying a conditional mutation block using an `@if` directive. The mutation is executed
only when the specified condition is true. If the condition is false, the mutation is silently ignored.
The upsert block also allows specifying a conditional mutation block using an `@if` directive.
The mutation is executed only when the specified condition is true. If the condition is false,
the mutation is silently ignored.

See more about Conditional Upsert [Here](https://docs.dgraph.io/mutations/#conditional-upsert).

Expand Down Expand Up @@ -625,7 +644,7 @@ Here is the asynchronous version of the code above, which runs a query.

```java
// Query
String query =
String query =
"query all($a: string){\n" +
" all(func: eq(name, $a)) {\n" +
" name\n" +
Expand Down
38 changes: 19 additions & 19 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 DGraph Labs, Inc.
* Copyright 2016 Dgraph Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,7 +19,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
Expand Down Expand Up @@ -50,7 +50,7 @@ base {
archivesName = 'dgraph4j'
}

// Upgrade to Java SE 11 to match updated protobuf-protoc version.
// Upgrade to Java SE 11 to match updated protobuf-protoc version.
// WARNING: Needs local toolchain upgrade from Java 8 to Java 11.
java {
sourceCompatibility = JavaVersion.VERSION_11
Expand All @@ -66,7 +66,7 @@ protobuf {
// The version of protoc must match protobuf-java. If you don't depend on
// protobuf-java directly, you will be transitively depending on the
// protobuf-java version that grpc depends on.
artifact = "com.google.protobuf:protoc:4.29.1"
artifact = 'com.google.protobuf:protoc:4.29.1'
}
plugins {
grpc {
Expand All @@ -81,9 +81,9 @@ protobuf {
option 'annotate_code'
}
}
}
}
all()*.plugins {
grpc {}
grpc { }
}
}
generatedFilesBaseDir = "$projectDir/src/generated"
Expand Down Expand Up @@ -113,29 +113,29 @@ configurations {
// In this section you declare the dependencies for your production and test code
dependencies {
// The production code uses the SLF4J logging API at compile time
implementation "org.slf4j:slf4j-api:2.0.16"
implementation 'org.slf4j:slf4j-api:2.0.16'

// Specific slf4j bindings should not be included in the default (compile) scope.
// See http://www.slf4j.org/faq.html#maven2.
testImplementation "org.slf4j:slf4j-simple:2.0.16"
testImplementation 'org.slf4j:slf4j-simple:2.0.16'

implementation "io.grpc:grpc-protobuf:${grpcVersion}"
implementation "io.grpc:grpc-netty:${grpcVersion}"
implementation "io.grpc:grpc-stub:${grpcVersion}"

implementation "com.google.guava:guava:33.3.1-jre"
implementation 'com.google.guava:guava:33.3.1-jre'

// Explicit matching of protobuf-java and protoc versions to address
// compilation errors arising due to transitive dependency on the version of
// protobuf-java that grpc depends on.
implementation "com.google.protobuf:protobuf-java:4.29.1"
// compilation errors arising due to transitive dependency on the version of
// protobuf-java that grpc depends on.
implementation 'com.google.protobuf:protobuf-java:4.29.1'

testImplementation "io.opencensus:opencensus-api:${openCensusVersion}"
testImplementation "io.opencensus:opencensus-exporter-trace-jaeger:${openCensusVersion}"
testRuntimeOnly "io.opencensus:opencensus-impl:${openCensusVersion}"

// Used for unmarshalling a JSON GraphQL response
testImplementation "com.google.code.gson:gson:2.11.0"
testImplementation 'com.google.code.gson:gson:2.11.0'

// Declare the dependency for your favourite test framework you want to use in your tests.
testImplementation 'org.testng:testng:6.8.8'
Expand All @@ -146,14 +146,14 @@ dependencies {

googleJavaFormat {
toolVersion = '1.5'
exclude "src/generated/**/*.java"
exclude 'src/generated/**/*.java'
}
compileJava.dependsOn 'googleJavaFormat'

idea {
module {
sourceDirs += file("${projectDir}/src/generated/main/java");
sourceDirs += file("${projectDir}/src/generated/main/grpc");
sourceDirs += file("${projectDir}/src/generated/main/java")
sourceDirs += file("${projectDir}/src/generated/main/grpc")
}
}

Expand All @@ -176,9 +176,9 @@ task fatJar(type: Jar) {

tasks.named('shadowJar', ShadowJar) {
enableRelocation true
relocationPrefix "io.dgraph.dgraph4j.shaded"
relocationPrefix 'io.dgraph.dgraph4j.shaded'
relocate 'google', 'io.dgraph.dgraph4j.shaded.google'
archiveClassifier.set("shaded")
archiveClassifier.set('shaded')
mergeServiceFiles()
}

Expand Down Expand Up @@ -223,7 +223,7 @@ jacocoTestReport {
}
}

task version() {
task version {
doLast {
println dgraph4jVersion
}
Expand Down
7 changes: 0 additions & 7 deletions release.sh

This file was deleted.

7 changes: 4 additions & 3 deletions samples/DgraphJavaSample/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
Sample project demonstrating the use of [dgraph4j], the official Java client
for Dgraph.

[dgraph4j]:https://github.com/dgraph-io/dgraph4
[dgraph4j]: https://github.com/dgraph-io/dgraph4

## Running

### Start Dgraph Server

You will need to install [Dgraph v1.1.0 or above][releases] and run it.

[releases]: https://github.com/dgraph-io/dgraph/releases


You can run the commands below to start a clean dgraph server everytime, for testing
and exploration.

Expand Down Expand Up @@ -41,7 +42,7 @@ For more configuration options, and other details, refer to [docs.dgraph.io](htt

## Run the sample code

**Warning**: The sample code, when run, will remove all data from your locally running Dgraph instance.
**Warning**: The sample code, when run, will remove all data from your locally running Dgraph instance.
So make sure that you don't have any important data on your Dgraph instance.

```
Expand Down
4 changes: 2 additions & 2 deletions samples/DgraphJavaSample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ repositories {
}

dependencies {
// Use Dgraph Java client
implementation 'io.dgraph:dgraph4j:24.0.0'
// Use Dgraph Java client
implementation 'io.dgraph:dgraph4j:24.1.0'

// Use JUnit test framework
testImplementation 'junit:junit:4.13.2'
Expand Down
Loading

0 comments on commit 7c822b1

Please sign in to comment.