From 5eb9df28878ee6f1da1e3287f8b9cfacc791425a Mon Sep 17 00:00:00 2001 From: Ryan Fox-Tyler <60440289+ryanfoxtyler@users.noreply.github.com> Date: Mon, 3 Feb 2025 14:23:43 -0500 Subject: [PATCH] chore: repo alignment (#264) --- .github/CODEOWNERS | 2 +- .github/ISSUE_TEMPLATE/bug_report.md | 38 +++ .github/ISSUE_TEMPLATE/config.yml | 5 + .github/ISSUE_TEMPLATE/feature_request.md | 23 ++ .github/PULL_REQUEST_TEMPLATE.md | 26 ++ .github/dependabot.yml | 43 --- renovate.json => .github/renovate.json | 4 +- .../ci-aqua-security-trivy-tests.yml | 37 --- .github/workflows/ci-dgraph4j-tests.yml | 12 +- .github/workflows/stale.yml | 18 -- .trunk/.gitignore | 9 + .trunk/configs/.checkov.yaml | 2 + .trunk/configs/.markdownlint.json | 8 + .trunk/configs/.prettierrc | 5 + .trunk/configs/.shellcheckrc | 7 + .trunk/configs/.yamllint.yaml | 7 + .trunk/trunk.yaml | 38 +++ .vscode/extensions.json | 3 + .vscode/settings.json | 6 + CHANGELOG.md | 135 ++++----- CODE_OF_CONDUCT.md | 113 ++++++++ PUBLISHING.md | 13 +- README.md | 261 ++++++++++-------- build.gradle | 8 +- docker-compose.test.yml | 66 ++--- gradlew | 173 ++++++------ samples/DgraphJavaSample/README.md | 22 +- samples/DgraphJavaSample/gradlew | 187 ++++++------- .../README.md | 30 +- .../gradlew | 187 ++++++------- .../README.md | 30 +- .../DgraphJavaSampleWithDeadlineAfter/gradlew | 187 ++++++------- samples/concurrent-modification/README.md | 31 +-- 33 files changed, 983 insertions(+), 753 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/dependabot.yml rename renovate.json => .github/renovate.json (53%) delete mode 100644 .github/workflows/ci-aqua-security-trivy-tests.yml delete mode 100644 .github/workflows/stale.yml create mode 100644 .trunk/.gitignore create mode 100644 .trunk/configs/.checkov.yaml create mode 100644 .trunk/configs/.markdownlint.json create mode 100644 .trunk/configs/.prettierrc create mode 100644 .trunk/configs/.shellcheckrc create mode 100644 .trunk/configs/.yamllint.yaml create mode 100644 .trunk/trunk.yaml create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json create mode 100644 CODE_OF_CONDUCT.md diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 7a6ad935..8ef236d6 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,4 +1,4 @@ # CODEOWNERS info: https://help.github.com/en/articles/about-code-owners # Owners are automatically requested for review for PRs that changes code # that they own. -* @dgraph-io/committers +* @hypermodeinc/database diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..5f95c284 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: "" +labels: bug +assignees: "" +--- + +## Describe the bug + +A clear and concise description of what the bug is. + +## To Reproduce + +Steps to reproduce the behavior: + +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +## Expected behavior + +A clear and concise description of what you expected to happen. + +## Screenshots + +If applicable, add screenshots to help explain your problem. + +## Environment + +- OS: [e.g. macOS, Windows, Ubuntu] +- Language [e.g. AssemblyScript, Go] +- Version [e.g. v0.xx] + +## Additional context + +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 00000000..29ea9f2b --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,5 @@ +blank_issues_enabled: false +contact_links: + - name: Dgraph Community Support + url: https://discord.hypermode.com + about: Please ask and answer questions here diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 00000000..9a4aae5a --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,23 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: "" +labels: "" +assignees: "" +--- + +## Is your feature request related to a problem? Please describe + +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +## Describe the solution you'd like + +A clear and concise description of what you want to happen. + +## Describe alternatives you've considered + +A clear and concise description of any alternative solutions or features you've considered. + +## Additional context + +Add any other context or screenshots about the feature request here. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..e8c683fd --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,26 @@ +**Description** + +Please explain the changes you made here. + +**Checklist** + +- [ ] Code compiles correctly and linting passes locally +- [ ] For all _code_ changes, an entry added to the `CHANGELOG.md` file describing and linking to + this PR +- [ ] Tests added for new functionality, or regression tests for bug fixes added as applicable +- [ ] For public APIs, new features, etc., PR on + [docs repo](https://github.com/dgraph-io/dgraph-docs) staged and linked here + +**Instructions** + +- The PR title should follow the [Conventional Commits](https://www.conventionalcommits.org/) + syntax, leading with `fix:`, `feat:`, `chore:`, `ci:`, etc. +- The description should briefly explain what the PR is about. In the case of a bugfix, describe or + link to the bug. +- In the checklist section, check the boxes in that are applicable, using `[x]` syntax. + - If not applicable, remove the entire line. Only leave the box unchecked if you intend to come + back and check the box later. +- Delete the `Instructions` line and everything below it, to indicate you have read and are + following these instructions. 🙂 + +Thank you for your contribution to Dgraph! diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index b927429a..00000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,43 +0,0 @@ -version: 2 -updates: - - package-ecosystem: "gradle" - directories: - - "/" - - "/samples/*" - schedule: - interval: "weekly" - day: "wednesday" - time: "16:00" - groups: - minor-and-patch: - applies-to: version-updates - update-types: - - "minor" - - "patch" - - - package-ecosystem: "maven" - directory: "/samples/concurrent-modification" - schedule: - interval: "weekly" - day: "wednesday" - time: "16:00" - groups: - minor-and-patch: - applies-to: version-updates - update-types: - - "minor" - - "patch" - - - package-ecosystem: "github-actions" - # Workflow files stored in the default location of `.github/workflows`. (You don't need to specify `/.github/workflows` for `directory`. You can use `directory: "/"`.) - directory: "/" - schedule: - interval: "weekly" - day: wednesday - time: "16:00" - groups: - actions: - update-types: - - "patch" - - "minor" - - "major" diff --git a/renovate.json b/.github/renovate.json similarity index 53% rename from renovate.json rename to .github/renovate.json index fa2889a1..88015f67 100644 --- a/renovate.json +++ b/.github/renovate.json @@ -1,6 +1,4 @@ { "$schema": "https://docs.renovatebot.com/renovate-schema.json", - "extends": [ - "local>hypermodeinc/renovate-config" - ] + "extends": ["local>hypermodeinc/renovate-config"] } diff --git a/.github/workflows/ci-aqua-security-trivy-tests.yml b/.github/workflows/ci-aqua-security-trivy-tests.yml deleted file mode 100644 index 0c905e65..00000000 --- a/.github/workflows/ci-aqua-security-trivy-tests.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: ci-aqua-security-trivy-tests -on: - push: - branches: - - master - pull_request: - types: - - opened - - reopened - - synchronize - - ready_for_review - branches: - - master - schedule: - - cron: "0 2 * * *" - -permissions: - security-events: write - -jobs: - build: - name: trivy-tests - runs-on: ubuntu-20.04 - steps: - - name: Checkout code - uses: actions/checkout@v4 - - name: Run Trivy vulnerability scanner - uses: aquasecurity/trivy-action@master - with: - scan-type: 'fs' - scan-ref: '.' - format: 'sarif' - output: 'trivy-results.sarif' - - name: Upload Trivy scan results to GitHub Security tab - uses: github/codeql-action/upload-sarif@v3 - with: - sarif_file: 'trivy-results.sarif' diff --git a/.github/workflows/ci-dgraph4j-tests.yml b/.github/workflows/ci-dgraph4j-tests.yml index b0a9e1f5..c8848ba3 100644 --- a/.github/workflows/ci-dgraph4j-tests.yml +++ b/.github/workflows/ci-dgraph4j-tests.yml @@ -1,8 +1,9 @@ name: ci-dgraph4j-tests + on: push: branches: - - master + - main pull_request: types: - opened @@ -10,13 +11,14 @@ on: - synchronize - ready_for_review branches: - - master + - main schedule: - - cron: "0 0 * * *" # run workflow daily + - cron: 0 0 * * * + jobs: build: name: dgraph4j-tests - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - name: Checkout dgraph4j repo uses: actions/checkout@v4 @@ -35,7 +37,7 @@ jobs: uses: actions/checkout@v4 with: path: dgraph - repository: dgraph-io/dgraph + repository: hypermodeinc/dgraph ref: main - name: Set up Go uses: actions/setup-go@v5 diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml deleted file mode 100644 index 7757f776..00000000 --- a/.github/workflows/stale.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: 'Close stale issues and PRs' -on: - schedule: - - cron: '30 1 * * *' - -permissions: - issues: write - pull-requests: write - actions: write - -jobs: - stale: - runs-on: ubuntu-latest - steps: - - uses: actions/stale@v9 - with: - stale-issue-message: 'This issue has been stale for 60 days and will be closed automatically in 7 days. Comment to keep it open.' - stale-pr-message: 'This PR has been stale for 60 days and will be closed automatically in 7 days. Comment to keep it open.' diff --git a/.trunk/.gitignore b/.trunk/.gitignore new file mode 100644 index 00000000..15966d08 --- /dev/null +++ b/.trunk/.gitignore @@ -0,0 +1,9 @@ +*out +*logs +*actions +*notifications +*tools +plugins +user_trunk.yaml +user.yaml +tmp diff --git a/.trunk/configs/.checkov.yaml b/.trunk/configs/.checkov.yaml new file mode 100644 index 00000000..521b240f --- /dev/null +++ b/.trunk/configs/.checkov.yaml @@ -0,0 +1,2 @@ +skip-check: + - CKV_GHA_7 diff --git a/.trunk/configs/.markdownlint.json b/.trunk/configs/.markdownlint.json new file mode 100644 index 00000000..449148d1 --- /dev/null +++ b/.trunk/configs/.markdownlint.json @@ -0,0 +1,8 @@ +{ + "line-length": { "line_length": 150, "tables": false }, + "no-inline-html": false, + "no-bare-urls": false, + "no-space-in-emphasis": false, + "no-emphasis-as-heading": false, + "first-line-heading": false +} diff --git a/.trunk/configs/.prettierrc b/.trunk/configs/.prettierrc new file mode 100644 index 00000000..577642c8 --- /dev/null +++ b/.trunk/configs/.prettierrc @@ -0,0 +1,5 @@ +{ + "semi": false, + "proseWrap": "always", + "printWidth": 100 +} diff --git a/.trunk/configs/.shellcheckrc b/.trunk/configs/.shellcheckrc new file mode 100644 index 00000000..8c7b1ada --- /dev/null +++ b/.trunk/configs/.shellcheckrc @@ -0,0 +1,7 @@ +enable=all +source-path=SCRIPTDIR +disable=SC2154 + +# If you're having issues with shellcheck following source, disable the errors via: +# disable=SC1090 +# disable=SC1091 diff --git a/.trunk/configs/.yamllint.yaml b/.trunk/configs/.yamllint.yaml new file mode 100644 index 00000000..184e251f --- /dev/null +++ b/.trunk/configs/.yamllint.yaml @@ -0,0 +1,7 @@ +rules: + quoted-strings: + required: only-when-needed + extra-allowed: ["{|}"] + key-duplicates: {} + octal-values: + forbid-implicit-octal: true diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml new file mode 100644 index 00000000..1aec2214 --- /dev/null +++ b/.trunk/trunk.yaml @@ -0,0 +1,38 @@ +# This file controls the behavior of Trunk: https://docs.trunk.io/cli +# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml +version: 0.1 +cli: + version: 1.22.9 +# Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins) +plugins: + sources: + - id: trunk + ref: v1.6.7 + uri: https://github.com/trunk-io/plugins +# Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes) +runtimes: + enabled: + - go@1.21.0 + - node@18.20.5 + - python@3.10.8 +# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration) +lint: + enabled: + - actionlint@1.7.7 + - checkov@3.2.361 + - git-diff-check + - markdownlint@0.44.0 + - osv-scanner@1.9.2 + - prettier@3.4.2 + - renovate@39.156.1 + - shellcheck@0.10.0 + - shfmt@3.6.0 + - trufflehog@3.88.4 + - yamllint@1.35.1 +actions: + disabled: + - trunk-announce + - trunk-check-pre-push + - trunk-fmt-pre-commit + enabled: + - trunk-upgrade-available diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 00000000..29d43383 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,3 @@ +{ + "recommendations": ["trunk.io"] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..93ff3ace --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "editor.formatOnSave": true, + "editor.defaultFormatter": "trunk.io", + "editor.trimAutoWhitespace": true, + "trunk.autoInit": false +} diff --git a/CHANGELOG.md b/CHANGELOG.md index 28b49af4..a2e2be9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/), ### Fixed -- build(deps): bump the minor-and-patch group across 1 directory with 4 updates (#245) (#243) (#244) (#241) (#237) +- build(deps): bump the minor-and-patch group across 1 directory with 4 updates (#245) (#243) (#244) + (#241) (#237) - Upgrade to gradle 7.6.4 (#238) ## [24.0.0] - 2024-08-06 @@ -39,15 +40,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/), - chore: added a test for best effort queries ([#182]) -[#220]: https://github.com/dgraph-io/dgraph4j/pull/220 -[#215]: https://github.com/dgraph-io/dgraph4j/pull/215 -[#214]: https://github.com/dgraph-io/dgraph4j/pull/214 -[#212]: https://github.com/dgraph-io/dgraph4j/pull/212 -[#208]: https://github.com/dgraph-io/dgraph4j/pull/208 -[#198]: https://github.com/dgraph-io/dgraph4j/pull/198 -[#195]: https://github.com/dgraph-io/dgraph4j/pull/195 -[#193]: https://github.com/dgraph-io/dgraph4j/pull/193 -[#182]: https://github.com/dgraph-io/dgraph4j/pull/182 +[#220]: https://github.com/hypermodeinc/dgraph4j/pull/220 +[#215]: https://github.com/hypermodeinc/dgraph4j/pull/215 +[#214]: https://github.com/hypermodeinc/dgraph4j/pull/214 +[#212]: https://github.com/hypermodeinc/dgraph4j/pull/212 +[#208]: https://github.com/hypermodeinc/dgraph4j/pull/208 +[#198]: https://github.com/hypermodeinc/dgraph4j/pull/198 +[#195]: https://github.com/hypermodeinc/dgraph4j/pull/195 +[#193]: https://github.com/hypermodeinc/dgraph4j/pull/193 +[#182]: https://github.com/hypermodeinc/dgraph4j/pull/182 ## [Unreleased] @@ -62,8 +63,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/), - feat: Add timeout parameters to transaction requests. ([#172]) - feat: Add shutdown method to client. ([#173]) -[#172]: https://github.com/dgraph-io/dgraph4j/pull/172 -[#173]: https://github.com/dgraph-io/dgraph4j/pull/173 +[#172]: https://github.com/hypermodeinc/dgraph4j/pull/172 +[#173]: https://github.com/hypermodeinc/dgraph4j/pull/173 ## [21.03.1] - 2021-04-22 @@ -71,7 +72,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/), - fix(deprecation): add DgraphClient.clientStubFromCloudEndpoint ([#170]) -[#170]: https://github.com/dgraph-io/dgraph4j/pull/170 +[#170]: https://github.com/hypermodeinc/dgraph4j/pull/170 ## [21.03.0] - 2021-04-08 @@ -87,9 +88,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/), - fix(test): Don't use dgraph binary in tests (GRAPHQL-1144) ([#168]) -[#166]: https://github.com/dgraph-io/dgraph4j/pull/166 -[#167]: https://github.com/dgraph-io/dgraph4j/pull/167 -[#168]: https://github.com/dgraph-io/dgraph4j/pull/168 +[#166]: https://github.com/hypermodeinc/dgraph4j/pull/166 +[#167]: https://github.com/hypermodeinc/dgraph4j/pull/167 +[#168]: https://github.com/hypermodeinc/dgraph4j/pull/168 ## [20.11.0] - 2020-12-23 @@ -101,7 +102,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/), - gRPC: bumped gRPC libs to v1.34.1 -[#160]: https://github.com/dgraph-io/dgraph4j/pull/160 +[#160]: https://github.com/hypermodeinc/dgraph4j/pull/160 ## [20.03.3] - 2020-11-25 @@ -109,7 +110,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/), - feat: add client constructor with executor (DGRAPH-2746) ([#161]) -[#161]: https://github.com/dgraph-io/dgraph4j/pull/161 +[#161]: https://github.com/hypermodeinc/dgraph4j/pull/161 ## [20.03.2] - 2020-10-27 @@ -117,7 +118,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/), - feat: Support for Slash GraphQL endpoint ([#158]) -[#158]: https://github.com/dgraph-io/dgraph4j/pull/158 +[#158]: https://github.com/hypermodeinc/dgraph4j/pull/158 ## [20.03.1] - 2020-07-10 @@ -130,9 +131,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/), - Delete argument from method usePlainText ([#148]) -[#149]: https://github.com/dgraph-io/dgraph4j/pull/149 -[#155]: https://github.com/dgraph-io/dgraph4j/pull/155 -[#148]: https://github.com/dgraph-io/dgraph4j/pull/148 +[#149]: https://github.com/hypermodeinc/dgraph4j/pull/149 +[#155]: https://github.com/hypermodeinc/dgraph4j/pull/155 +[#148]: https://github.com/hypermodeinc/dgraph4j/pull/148 ## [20.03.0] - 2020-04-01 @@ -146,10 +147,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/), - Fix slf4j dependencies. ([#133]) - Fixed running multiple upserts within one transaction ([#137]) -[#130]: https://github.com/dgraph-io/dgraph4j/pull/130 -[1324663]: https://github.com/dgraph-io/dgraph4j/commit/13246633dc87ab884beadf2ac239116890055b48 -[#133]: https://github.com/dgraph-io/dgraph4j/pull/133 -[#137]: https://github.com/dgraph-io/dgraph4j/pull/137 +[#130]: https://github.com/hypermodeinc/dgraph4j/pull/130 +[1324663]: https://github.com/hypermodeinc/dgraph4j/commit/13246633dc87ab884beadf2ac239116890055b48 +[#133]: https://github.com/hypermodeinc/dgraph4j/pull/133 +[#137]: https://github.com/hypermodeinc/dgraph4j/pull/137 ## [2.1.0] - 2020-01-30 @@ -157,7 +158,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/), - Sync proto files with dgo ([#121]) -[#121]: https://github.com/dgraph-io/dgraph4j/pull/121 +[#121]: https://github.com/hypermodeinc/dgraph4j/pull/121 ## [2.0.2] - 2019-10-13 @@ -165,7 +166,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/), - Fix Opencensus tracing. ([#117]) -[#117]: https://github.com/dgraph-io/dgraph4j/pull/117 +[#117]: https://github.com/hypermodeinc/dgraph4j/pull/117 ## [2.0.1] - 2019-09-05 @@ -173,7 +174,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/), - Throw TxnConflictException correctly ([#102]) -[#102]: https://github.com/dgraph-io/dgraph4j/pull/102 +[#102]: https://github.com/hypermodeinc/dgraph4j/pull/102 ## [2.0.0] - 2019-09-02 @@ -182,8 +183,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/), - Upgrade grpc to get rid of Java 11 warnings from grpc ([#94]) - Update grpc API to support Multiple Mutations in future ([#101]) -[#94]: https://github.com/dgraph-io/dgraph4j/pull/94 -[#101]: https://github.com/dgraph-io/dgraph4j/pull/101 +[#94]: https://github.com/hypermodeinc/dgraph4j/pull/94 +[#101]: https://github.com/hypermodeinc/dgraph4j/pull/101 ## [1.7.5] - 2019-06-29 @@ -195,21 +196,22 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/), - Moving the dependency io.opencensus.\* into a test dependency only, ([#89]) -[#88]: https://github.com/dgraph-io/dgraph4j/pull/88 -[#89]: https://github.com/dgraph-io/dgraph4j/pull/89 +[#88]: https://github.com/hypermodeinc/dgraph4j/pull/88 +[#89]: https://github.com/hypermodeinc/dgraph4j/pull/89 ## [1.7.4] - 2019-06-19 ### Added -- Added best effort method to the transaction class to call the AsyncTransaction class method. ([#86]) +- Added best effort method to the transaction class to call the AsyncTransaction class method. + ([#86]) ### Fixed - Fix broken tests ([#87]) -[#86]: https://github.com/dgraph-io/dgraph4j/pull/86 -[#87]: https://github.com/dgraph-io/dgraph4j/pull/87 +[#86]: https://github.com/hypermodeinc/dgraph4j/pull/86 +[#87]: https://github.com/hypermodeinc/dgraph4j/pull/87 ## [1.7.3] - 2019-03-27 @@ -218,8 +220,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/), - added logic for ACL and upgraded the code to be usable with java 11 ([#80]) - Added best effort flag, shorten ACL test timing to match changes in dgraph ([b4bf3bf]) -[#80]: https://github.com/dgraph-io/dgraph4j/pull/80 -[b4bf3bf]: https://github.com/dgraph-io/dgraph4j/commit/b4bf3bf49d7f89f0bffd3a4929f42efbef9a5a31 +[#80]: https://github.com/hypermodeinc/dgraph4j/pull/80 +[b4bf3bf]: https://github.com/hypermodeinc/dgraph4j/commit/b4bf3bf49d7f89f0bffd3a4929f42efbef9a5a31 ## [1.7.1] - 2018-10-31 @@ -232,9 +234,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/), - Fix client selection behavior to match Go client. ([3bb5e23]) -[#70]: https://github.com/dgraph-io/dgraph4j/pull/70 -[#71]: https://github.com/dgraph-io/dgraph4j/pull/71 -[3bb5e23]: https://github.com/dgraph-io/dgraph4j/commit/3bb5e23c6bcbfd7224a602aa34ef33c4c26c24f4 +[#70]: https://github.com/hypermodeinc/dgraph4j/pull/70 +[#71]: https://github.com/hypermodeinc/dgraph4j/pull/71 +[3bb5e23]: https://github.com/hypermodeinc/dgraph4j/commit/3bb5e23c6bcbfd7224a602aa34ef33c4c26c24f4 ## [1.7.0] - 2018-09-20 @@ -259,8 +261,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/), ## [1.2.0] - 2018-02-06 -- Added possibility to create a DgraphClient with a specified request - deadline (#48). +- Added possibility to create a DgraphClient with a specified request deadline (#48). ## [1.1.0] - 2018-01-17 @@ -270,27 +271,27 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/), - Fully compatible with Dgraph v1.0 -[Unreleased]: https://github.com/dgraph-io/dgraph4j/compare/v21.12.0...HEAD -[21.12.0]: https://github.com/dgraph-io/dgraph4j/compare/v21.03.2...v21.12.0 -[21.03.2]: https://github.com/dgraph-io/dgraph4j/compare/v21.03.1...v21.03.2 -[21.03.1]: https://github.com/dgraph-io/dgraph4j/compare/v21.03.0...v21.03.1 -[21.03.0]: https://github.com/dgraph-io/dgraph4j/compare/v20.11.0...v21.03.0 -[20.11.0]: https://github.com/dgraph-io/dgraph4j/compare/v20.03.3...v20.11.0 -[20.03.3]: https://github.com/dgraph-io/dgraph4j/compare/v20.03.2...v20.03.3 -[20.03.2]: https://github.com/dgraph-io/dgraph4j/compare/v20.03.1...v20.03.2 -[20.03.1]: https://github.com/dgraph-io/dgraph4j/compare/v20.03.0...v20.03.1 -[20.03.0]: https://github.com/dgraph-io/dgraph4j/compare/v2.1.0...v20.03.0 -[2.1.0]: https://github.com/dgraph-io/dgraph4j/compare/v2.0.2...v2.1.0 -[2.0.2]: https://github.com/dgraph-io/dgraph4j/compare/v2.0.1...v2.0.2 -[2.0.1]: https://github.com/dgraph-io/dgraph4j/compare/v1.7.4...v2.0.1 -[1.7.4]: https://github.com/dgraph-io/dgraph4j/compare/v1.7.3...v1.7.4 -[1.7.3]: https://github.com/dgraph-io/dgraph4j/compare/v1.7.0...v1.7.3 -[1.7.0]: https://github.com/dgraph-io/dgraph4j/compare/v1.6.0...v1.7.0 -[1.7.0]: https://github.com/dgraph-io/dgraph4j/compare/v1.6.0...v1.7.0 -[1.6.0]: https://github.com/dgraph-io/dgraph4j/compare/v1.5.0...v1.6.0 -[1.5.0]: https://github.com/dgraph-io/dgraph4j/compare/v1.4.2...v1.5.0 -[1.4.2]: https://github.com/dgraph-io/dgraph4j/compare/v1.3.0...v1.4.2 -[1.3.0]: https://github.com/dgraph-io/dgraph4j/compare/v1.2.0...v1.3.0 -[1.2.0]: https://github.com/dgraph-io/dgraph4j/compare/v1.1.0...v1.2.0 -[1.1.0]: https://github.com/dgraph-io/dgraph4j/compare/v1.0.0...v1.1.0 -[1.0.0]: https://github.com/dgraph-io/dgraph4j/tree/v1.0.0 +[Unreleased]: https://github.com/hypermodeinc/dgraph4j/compare/v21.12.0...HEAD +[21.12.0]: https://github.com/hypermodeinc/dgraph4j/compare/v21.03.2...v21.12.0 +[21.03.2]: https://github.com/hypermodeinc/dgraph4j/compare/v21.03.1...v21.03.2 +[21.03.1]: https://github.com/hypermodeinc/dgraph4j/compare/v21.03.0...v21.03.1 +[21.03.0]: https://github.com/hypermodeinc/dgraph4j/compare/v20.11.0...v21.03.0 +[20.11.0]: https://github.com/hypermodeinc/dgraph4j/compare/v20.03.3...v20.11.0 +[20.03.3]: https://github.com/hypermodeinc/dgraph4j/compare/v20.03.2...v20.03.3 +[20.03.2]: https://github.com/hypermodeinc/dgraph4j/compare/v20.03.1...v20.03.2 +[20.03.1]: https://github.com/hypermodeinc/dgraph4j/compare/v20.03.0...v20.03.1 +[20.03.0]: https://github.com/hypermodeinc/dgraph4j/compare/v2.1.0...v20.03.0 +[2.1.0]: https://github.com/hypermodeinc/dgraph4j/compare/v2.0.2...v2.1.0 +[2.0.2]: https://github.com/hypermodeinc/dgraph4j/compare/v2.0.1...v2.0.2 +[2.0.1]: https://github.com/hypermodeinc/dgraph4j/compare/v1.7.4...v2.0.1 +[1.7.4]: https://github.com/hypermodeinc/dgraph4j/compare/v1.7.3...v1.7.4 +[1.7.3]: https://github.com/hypermodeinc/dgraph4j/compare/v1.7.0...v1.7.3 +[1.7.0]: https://github.com/hypermodeinc/dgraph4j/compare/v1.6.0...v1.7.0 +[1.7.0]: https://github.com/hypermodeinc/dgraph4j/compare/v1.6.0...v1.7.0 +[1.6.0]: https://github.com/hypermodeinc/dgraph4j/compare/v1.5.0...v1.6.0 +[1.5.0]: https://github.com/hypermodeinc/dgraph4j/compare/v1.4.2...v1.5.0 +[1.4.2]: https://github.com/hypermodeinc/dgraph4j/compare/v1.3.0...v1.4.2 +[1.3.0]: https://github.com/hypermodeinc/dgraph4j/compare/v1.2.0...v1.3.0 +[1.2.0]: https://github.com/hypermodeinc/dgraph4j/compare/v1.1.0...v1.2.0 +[1.1.0]: https://github.com/hypermodeinc/dgraph4j/compare/v1.0.0...v1.1.0 +[1.0.0]: https://github.com/hypermodeinc/dgraph4j/tree/v1.0.0 diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..614af544 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,113 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our community a +harassment-free experience for everyone, regardless of age, body size, visible or invisible +disability, ethnicity, sex characteristics, gender identity and expression, level of experience, +education, socio-economic status, nationality, personal appearance, race, religion, or sexual +identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and +healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our community include: + +- Demonstrating empathy and kindness toward other people +- Being respectful of differing opinions, viewpoints, and experiences +- Giving and gracefully accepting constructive feedback +- Accepting responsibility and apologizing to those affected by our mistakes, and learning from the + experience +- Focusing on what is best not just for us as individuals, but for the overall community + +Examples of unacceptable behavior include: + +- The use of sexualized language or imagery, and sexual attention or advances of any kind +- Trolling, insulting or derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or email address, without their + explicit permission +- Other conduct which could reasonably be considered inappropriate in a professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior +and will take appropriate and fair corrective action in response to any behavior that they deem +inappropriate, threatening, offensive, or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject comments, commits, +code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and +will communicate reasons for moderation decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when an individual is +officially representing the community in public spaces. Examples of representing our community +include using an official e-mail address, posting via an official social media account, or acting as +an appointed representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community +leaders responsible for enforcement at hello@hypermode.com. All complaints will be reviewed and +investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the reporter of any +incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining the consequences for +any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or +unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing clarity around the +nature of the violation and an explanation of why the behavior was inappropriate. A public apology +may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of actions. + +**Consequence**: A warning with consequences for continued behavior. No interaction with the people +involved, including unsolicited interaction with those enforcing the Code of Conduct, for a +specified period of time. This includes avoiding interactions in community spaces as well as +external channels like social media. Violating these terms may lead to a temporary or permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including sustained inappropriate +behavior. + +**Consequence**: A temporary ban from any sort of interaction or public communication with the +community for a specified period of time. No public or private interaction with the people involved, +including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this +period. Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community standards, including +sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement +of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. diff --git a/PUBLISHING.md b/PUBLISHING.md index f28d5158..819a8889 100644 --- a/PUBLISHING.md +++ b/PUBLISHING.md @@ -1,7 +1,7 @@ ## Publishing artefacts to Maven Central -Dgraph owns the `io.dgraph` namespace on Maven Central. See [JIRA ticket][jira] for details. -This document contains instructions to publish dgraph4j build artefacts to Maven central. +Dgraph owns the `io.dgraph` namespace on Maven Central. See [JIRA ticket][jira] for details. This +document contains instructions to publish dgraph4j build artefacts to Maven central. [jira]: https://issues.sonatype.org/browse/OSSRH-35895 @@ -11,8 +11,10 @@ This document contains instructions to publish dgraph4j build artefacts to Maven - Generate GPG credentials. Make sure you set a passphrase. You can use this [guide](https://help.github.com/en/articles/generating-a-new-gpg-key). - Note down the short version of the Key ID: `gpg --list-keys --keyid-format short`. -- Generate a secret key ring file if not present: `gpg --export-secret-keys -o /path/to/.gnupg/secring.gpg`. -- Publish the keys to the MIT server: `gpg --send-keys ` (Maven Central will check for keys here). +- Generate a secret key ring file if not present: + `gpg --export-secret-keys -o /path/to/.gnupg/secring.gpg`. +- Publish the keys to the MIT server: `gpg --send-keys ` (Maven Central will check for keys + here). - Create `~/.gradle/gradle.properties` and populate it with all the credentials - Get the credentials from `profile` section after loggin into [Sonatype](https://oss.sonatype.org/) @@ -35,7 +37,8 @@ ossrhPassword= - Update CHANGELOG. - Raise a PR for the above changes. Put the changelog in PR description and merge it. - Run `./gradlew publishMavenJavaPublicationToMavenRepository`. -- Release the deployment by following the steps on the page _Releasing the Deployment_ (link in references below). +- 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. ### References diff --git a/README.md b/README.md index 214ab260..a38b3df7 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@ # Dgraph Client for Java [![Build Status](https://teamcity.dgraph.io/guestAuth/app/rest/builds/buildType:%28id:Dgraph4j_Integration%29/statusIcon.svg)](https://teamcity.dgraph.io/viewLog.html?buildTypeId=Dgraph4j_Integration&buildId=lastFinished&guest=1) -[![Coverage Status](https://coveralls.io/repos/github/dgraph-io/dgraph4j/badge.svg)](https://coveralls.io/github/dgraph-io/dgraph4j) +[![Coverage Status](https://coveralls.io/repos/github/hypermodeinc/dgraph4j/badge.svg)](https://coveralls.io/github/hypermodeinc/dgraph4j) A minimal implementation for a Dgraph client for Java 11 and above, using [grpc]. ### 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. + +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/ @@ -14,20 +16,22 @@ This client follows the [Dgraph Go client][goclient] closely. [goclient]: https://github.com/dgraph-io/dgo -Before using this client, we highly recommend that you go through [docs.dgraph.io], -and understand how to run and work with Dgraph. +Before using this client, we highly recommend that you go through [docs.dgraph.io], and understand +how to run and work with Dgraph. -[docs.dgraph.io]:https://docs.dgraph.io +[docs.dgraph.io]: https://docs.dgraph.io -**Use [Discuss Issues](https://discuss.dgraph.io/c/issues/35/clients/46) for reporting issues about this repository.** +**Use [Discuss Issues](https://discuss.dgraph.io/c/issues/35/clients/46) for reporting issues about +this repository.** ## Table of Contents + - [Dgraph Client for Java](#dgraph-client-for-java) - - [IMP NOTE:](#imp-note) + - [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) + - [Note regarding Java 1.8.x support:](#note-regarding-java-18x-support) - [Quickstart](#quickstart) - [Intro](#intro) - [Using the Synchronous Client](#using-the-synchronous-client) @@ -57,14 +61,17 @@ and understand how to run and work with Dgraph. - [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) - * [Building the source](#building-the-source) - * [Code Style](#code-style) - * [Running unit tests](#running-unit-tests) + - [Building the source](#building-the-source) + - [Code Style](#code-style) + - [Running unit tests](#running-unit-tests) ## Download + grab via Maven: ```xml @@ -76,14 +83,15 @@ grab via Maven: ``` or Gradle: + ```groovy compile 'io.dgraph:dgraph4j:24.1.1' ``` ## Supported Versions -Depending on the version of Dgraph that you are connecting to, you will have to -use a different version of this client. +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 | | :-------------: | :--------------: | :----------: | @@ -95,17 +103,19 @@ use a different version of this client. | >= 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. -* 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 - the dependency to use from the version combination table in [this section] in `grpc-netty` docs. + +- 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 the + dependency to use from the version combination table in [this section] in `grpc-netty` docs. For maven: @@ -123,9 +133,9 @@ The following is only applicable to dgraph4j versions < v24.X.X. compile 'io.netty:netty-tcnative-boringssl-static:' ``` - 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: + 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 | | :--------------: | :----------------: | :-------------------------------------: | @@ -145,20 +155,20 @@ The following is only applicable to dgraph4j versions < v24.X.X. [this section]: https://github.com/grpc/grpc-java/blob/master/SECURITY.md#netty ## Quickstart -Build and run the [DgraphJavaSample] project in the `samples` folder, which -contains an end-to-end example of using the Dgraph Java client. Follow the -instructions in the README of that project. -[DgraphJavaSample]: https://github.com/dgraph-io/dgraph4j/tree/master/samples/DgraphJavaSample +Build and run the [DgraphJavaSample] project in the `samples` folder, which contains an end-to-end +example of using the Dgraph Java client. Follow the instructions in the README of that project. + +[DgraphJavaSample]: https://github.com/hypermodeinc/dgraph4j/tree/master/samples/DgraphJavaSample ## Intro -This library supports two styles of clients, the synchronous client `DgraphClient` and -the async client `DgraphAsyncClient`. -A `DgraphClient` or `DgraphAsyncClient` can be initialised by passing it + +This library supports two styles of clients, the synchronous client `DgraphClient` and the async +client `DgraphAsyncClient`. A `DgraphClient` or `DgraphAsyncClient` can be initialised by passing it a list of `DgraphBlockingStub` clients. The `anyClient()` API can randomly pick a stub, which can -then be used for GRPC operations. In the next section, we will explain how to create a -synchronous client and use it to mutate or query dgraph. For the async client, more details can -be found in the [Using the Asynchronous Client](#using-the-asynchronous-client) section. +then be used for GRPC operations. In the next section, we will explain how to create a synchronous +client and use it to mutate or query dgraph. For the async client, more details can be found in the +[Using the Asynchronous Client](#using-the-asynchronous-client) section. ## Using the Synchronous Client @@ -187,9 +197,9 @@ DgraphClient dgraphClient = new DgraphClient(stub1, stub2, stub3); ### Creating a Client for Dgraph Cloud -If you want to connect to Dgraph running on a [Dgraph Cloud](https://cloud.dgraph.io) instance, -then all you need is the URL of your Dgraph Cloud instance and the API key. You can get a client -with them as follows : +If you want to connect to Dgraph running on a [Dgraph Cloud](https://cloud.dgraph.io) instance, then +all you need is the URL of your Dgraph Cloud instance and the API key. You can get a client with +them as follows : ```java DgraphStub stub = DgraphClient.clientStubFromCloudEndpoint("https://your-instance.cloud.dgraph.io/graphql", "your-api-key"); @@ -198,19 +208,21 @@ DgraphClient dgraphClient = new DgraphClient(stub); ### Creating a Secure Client using TLS -To setup a client using TLS, you could use the following code snippet. The server needs to be -setup using the instructions provided [here](https://docs.dgraph.io/deploy/#tls-configuration). +To setup a client using TLS, you could use the following code snippet. The server needs to be setup +using the instructions provided [here](https://docs.dgraph.io/deploy/#tls-configuration). If you are doing client verification, you need to convert the client key from PKCS#1 format to -PKCS#8 format. By default, grpc doesn't support reading PKCS#1 format keys. To convert the -format, you could use the `openssl` tool. +PKCS#8 format. By default, grpc doesn't support reading PKCS#1 format keys. To convert the format, +you could use the `openssl` tool. First, let's install the `openssl` tool: + ```sh apt install openssl ``` Now, use the following command to convert the key: + ```sh openssl pkcs8 -in client.name.key -topk8 -nocrypt -out client.name.java.key ``` @@ -234,31 +246,37 @@ DgraphClient dgraphClient = new DgraphClient(stub); ### Check Dgraph version Checking the version of the Dgraph server this client is interacting with is as easy as: + ```java Version v = dgraphClient.checkVersion(); System.out.println(v.getTag()); ``` -Checking the version, before doing anything else can be used as a test to find out if the client -is able to communicate with the Dgraph server. This will also help reduce the latency of the first -query/mutation which results from some dynamic library loading and linking that happens in JVM -(see [this issue](https://github.com/dgraph-io/dgraph4j/issues/108) for more details). + +Checking the version, before doing anything else can be used as a test to find out if the client is +able to communicate with the Dgraph server. This will also help reduce the latency of the first +query/mutation which results from some dynamic library loading and linking that happens in JVM (see +[this issue](https://github.com/hypermodeinc/dgraph4j/issues/108) for more details). ### Login Using ACL If ACL is enabled then you can log-in to the default namespace (0) with following: + ```java dgraphClient.login(USER_ID, USER_PASSWORD); ``` + For logging-in to some other namespace, use the `loginIntoNamespace` method on the client: + ```java dgraphClient.loginIntoNamespace(USER_ID, USER_PASSWORD, NAMESPACE); ``` + Once logged-in, the `dgraphClient` object can be used to do any further operations. ### Altering the Database -To set the schema, create an `Operation` object, set the schema and pass it to -`DgraphClient#alter` method. +To set the schema, create an `Operation` object, set the schema and pass it to `DgraphClient#alter` +method. ```java String schema = "name: string @index(exact) ."; @@ -266,9 +284,8 @@ Operation operation = Operation.newBuilder().setSchema(schema).build(); dgraphClient.alter(operation); ``` -Starting Dgraph version 20.03.0, indexes can be computed in the background. -You can call the function `setRunInBackground(true)` as shown below before -calling `alter`. You can find more details +Starting Dgraph version 20.03.0, indexes can be computed in the background. You can call the +function `setRunInBackground(true)` as shown below before calling `alter`. You can find more details [here](https://docs.dgraph.io/master/query-language/#indexes-in-background). ```java @@ -280,9 +297,9 @@ Operation operation = Operation.newBuilder() dgraphClient.alter(operation); ``` -`Operation` contains other fields as well, including drop predicate and -drop all. Drop all is useful if you wish to discard all the data, and start from -a clean slate, without bringing the instance down. +`Operation` contains other fields as well, including drop predicate and drop all. Drop all is useful +if you wish to discard all the data, and start from a clean slate, without bringing the instance +down. ```java // Drop all data including schema from the dgraph instance. This is useful @@ -294,15 +311,15 @@ dgraphClient.alter(Operation.newBuilder().setDropAll(true).build()); ### Creating a Transaction There are two types of transactions in dgraph, i.e. the read-only transactions that only include -queries and the transactions that change data in dgraph with mutate operations. Both the -synchronous client `DgraphClient` and the async client `DgraphAsyncClient` support the two types -of transactions by providing the `newTransaction` and the `newReadOnlyTransaction` APIs. Creating - a transaction is a local operation and incurs no network overhead. +queries and the transactions that change data in dgraph with mutate operations. Both the synchronous +client `DgraphClient` and the async client `DgraphAsyncClient` support the two types of transactions +by providing the `newTransaction` and the `newReadOnlyTransaction` APIs. Creating a transaction is a +local operation and incurs no network overhead. -In most of the cases, the normal read-write transactions is used, which can have any -number of query or mutate operations. However, if a transaction only has queries, you might -benefit from a read-only transaction, which can share the same read timestamp across multiple -such read-only transactions and can result in lower latencies. +In most of the cases, the normal read-write transactions is used, which can have any number of query +or mutate operations. However, if a transaction only has queries, you might benefit from a read-only +transaction, which can share the same read timestamp across multiple such read-only transactions and +can result in lower latencies. For normal read-write transactions, it is a good practise to call `Transaction#discard()` in a `finally` block after running the transaction. Calling `Transaction#discard()` after @@ -319,8 +336,8 @@ try { } ``` -For read-only transactions, there is no need to call `Transaction.discard`, which is equivalent -to a no-op. +For read-only transactions, there is no need to call `Transaction.discard`, which is equivalent to a +no-op. ```java Transaction readOnlyTxn = dgraphClient.newReadOnlyTransaction(); @@ -336,12 +353,12 @@ Transaction bestEffortTxn = dgraphClient.newReadOnlyTransaction() ``` ### Running a Mutation -`Transaction#mutate` runs a mutation. It takes in a `Mutation` object, -which provides two main ways to set data: JSON and RDF N-Quad. You can choose -whichever way is convenient. -We're going to use JSON. First we define a `Person` class to represent a person. -This data will be serialized into JSON. +`Transaction#mutate` runs a mutation. It takes in a `Mutation` object, which provides two main ways +to set data: JSON and RDF N-Quad. You can choose whichever way is convenient. + +We're going to use JSON. First we define a `Person` class to represent a person. This data will be +serialized into JSON. ```java class Person { @@ -370,9 +387,9 @@ Response mutationResponse = txn.mutate(mu); System.out.println(mutationResponse.getUidsMap()) ``` -Sometimes, you only want to commit mutation, without querying anything further. -In such cases, you can use a `CommitNow` field in `Mutation` object to -indicate that the mutation must be immediately committed. +Sometimes, you only want to commit mutation, without querying anything further. In such cases, you +can use a `CommitNow` field in `Mutation` object to indicate that the mutation must be immediately +committed. Mutation can be run using the `doRequest` function as well. @@ -384,9 +401,10 @@ txn.doRequest(request); ``` ### Committing a Transaction + A transaction can be committed using the `Transaction#commit()` method. If your transaction -consisted solely of calls to `Transaction#query()`, and no calls to `Transaction#mutate()`, -then calling `Transaction#commit()` is not necessary. +consisted solely of calls to `Transaction#query()`, and no calls to `Transaction#mutate()`, then +calling `Transaction#commit()` is not necessary. An error will be returned if other transactions running concurrently modify the same data that was modified in this transaction. It is up to the user to retry transactions when they fail. @@ -410,12 +428,13 @@ try { ``` ### Running a Query -You can run a query by calling `Transaction#query()`. You will need to pass in a GraphQL+- -query string, and a map (optional, could be empty) of any variables that you might want to -set in the query. -The response would contain a `JSON` field, which has the JSON encoded result. You will need -to decode it before you can do anything useful with it. +You can run a query by calling `Transaction#query()`. You will need to pass in a GraphQL+- query +string, and a map (optional, could be empty) of any variables that you might want to set in the +query. + +The response would contain a `JSON` field, which has the JSON encoded result. You will need to +decode it before you can do anything useful with it. Let’s run the following query: @@ -457,6 +476,7 @@ People ppl = gson.fromJson(response.getJson().toStringUtf8(), People.class); System.out.printf("people found: %d\n", ppl.all.size()); ppl.all.forEach(person -> System.out.println(person.name)); ``` + This should print: ``` @@ -499,9 +519,9 @@ This should print (assuming Alice's `uid` is `0x2`): ### Running an Upsert: Query + Mutation -The `txn.doRequest` function allows you to run upserts consisting of one query and -one mutation. Variables can be defined in the query and used in the mutation. -You could also use `txn.doRequest` to perform a query followed by a mutation. +The `txn.doRequest` function allows you to run upserts consisting of one query and one mutation. +Variables can be defined in the query and used in the mutation. You could also use `txn.doRequest` +to perform a query followed by a mutation. To know more about upsert, we highly recommend going through the docs at https://docs.dgraph.io/mutations/#upsert-block. @@ -523,9 +543,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). @@ -546,9 +566,10 @@ txn.doRequest(request); ``` ### Setting Deadlines -It is recommended that you always set a deadline for each client call, after -which the client terminates. This is in line with the recommendation for any gRPC client. -Read [this forum post][deadline-post] for more details. + +It is recommended that you always set a deadline for each client call, after which the client +terminates. This is in line with the recommendation for any gRPC client. Read [this forum +post][deadline-post] for more details. #### Setting deadlines for all requests @@ -572,12 +593,13 @@ DgraphClient dgraphClient = new DgraphClient(stub); dgraphClient.newTransaction().query(query, 500, TimeUnit.MILLISECONDS); ``` - [deadline-post]: https://discuss.dgraph.io/t/dgraph-java-client-setting-deadlines-per-call/3056 ### Setting Metadata Headers + Certain headers such as authentication tokens need to be set globally for all subsequent calls. Below is an example of setting a header with the name "auth-token": + ```java // create the stub first ManagedChannel channel = @@ -596,13 +618,14 @@ DgraphClient dgraphClient = new DgraphClient(stub); // trigger a RPC call using the DgraphClient dgraphClient.alter(Operation.newBuilder().setDropAll(true).build()); ``` + ### Helper Methods #### Delete multiple edges -The example below uses the helper method `Helpers#deleteEdges` to delete -multiple edges corresponding to predicates on a node with the given uid. -The helper method takes an existing mutation, and returns a new mutation -with the deletions applied. + +The example below uses the helper method `Helpers#deleteEdges` to delete multiple edges +corresponding to predicates on a node with the given uid. The helper method takes an existing +mutation, and returns a new mutation with the deletions applied. ```java Mutation mu = Mutation.newBuilder().build() @@ -612,9 +635,8 @@ dgraphClient.newTransaction().mutate(mu); ### Closing the DB Connection -To disconnect from Dgraph, call `ManagedChannel#shutdown` on the gRPC -channel object created when [creating a Dgraph -client](#creating-a-client). +To disconnect from Dgraph, call `ManagedChannel#shutdown` on the gRPC channel object created when +[creating a Dgraph client](#creating-a-client). ``` channel.shutdown(); @@ -627,15 +649,14 @@ dgraphClient.shutdown(); ``` ## Using the Asynchronous Client -Dgraph Client for Java also bundles an asynchronous API, which can be used by -instantiating the `DgraphAsyncClient` class. The usage is almost exactly the -same as the `DgraphClient` (show in previous section) class. The main -differences is that the `DgraphAsyncClient#newTransacation()` returns an -`AsyncTransaction` class. The API for `AsyncTransaction` is exactly -`Transaction`. The only difference is that instead of returning the results -directly, it returns immediately with a corresponding `CompletableFuture` -object. This object represents the computation which runs asynchronously to -yield the result in the future. Read more about `CompletableFuture` in the + +Dgraph Client for Java also bundles an asynchronous API, which can be used by instantiating the +`DgraphAsyncClient` class. The usage is almost exactly the same as the `DgraphClient` (show in +previous section) class. The main differences is that the `DgraphAsyncClient#newTransacation()` +returns an `AsyncTransaction` class. The API for `AsyncTransaction` is exactly `Transaction`. The +only difference is that instead of returning the results directly, it returns immediately with a +corresponding `CompletableFuture` object. This object represents the computation which runs +asynchronously to yield the result in the future. Read more about `CompletableFuture` in the [Java 8 documentation][futuredocs]. [futuredocs]: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html @@ -663,10 +684,12 @@ txn.query(query).thenAccept(response -> { ppl.all.forEach(person -> System.out.println(person.name)); }); ``` + ## Checking the request latency -If you would like to see the latency for either a mutation or -query request, the latency field in the returned result can be helpful. Here is an example to log - the latency of a query request: + +If you would like to see the latency for either a mutation or query request, the latency field in +the returned result can be helpful. Here is an example to log the latency of a query request: + ```java Response resp = txn.query(query); Latency latency = resp.getLatency(); @@ -674,7 +697,9 @@ logger.info("parsing latency:" + latency.getParsingNs()); logger.info("processing latency:" + latency.getProcessingNs()); logger.info("encoding latency:" + latency.getEncodingNs()); ``` + Similarly you can get the latency of a mutation request: + ```java Assigned assignedIds = dgraphClient.newTransaction().mutate(mu); Latency latency = assignedIds.getLatency(); @@ -684,26 +709,30 @@ Latency latency = assignedIds.getLatency(); ### Building the source -**Warning**: The gradle build runs integration tests on a locally running Dgraph server. -The tests will remove all data from your Dgraph instance. So make sure that you don't -have any important data on your Dgraph instance. +**Warning**: The gradle build runs integration tests on a locally running Dgraph server. The tests +will remove all data from your Dgraph instance. So make sure that you don't have any important data +on your Dgraph instance. + ``` ./gradlew build ``` + If you have made changes to the `task.proto` file, this step will also regenerate the source files generated by Protocol Buffer tools. ### Code Style + We use [google-java-format] to format the source code. If you run `./gradlew build`, you will be warned if there is code that is not conformant. You can run `./gradlew goJF` to format the source - code, before committing it. +code, before committing it. -[google-java-format]:https://github.com/google/google-java-format +[google-java-format]: https://github.com/google/google-java-format ### Running unit tests -**Warning**: This command will runs integration tests on a locally running Dgraph server. -The tests will remove all data from your Dgraph instance. So make sure that you don't -have any important data on your Dgraph instance. + +**Warning**: This command will runs integration tests on a locally running Dgraph server. The tests +will remove all data from your Dgraph instance. So make sure that you don't have any important data +on your Dgraph instance. Make sure you have a Dgraph server running on localhost before you run this task. diff --git a/build.gradle b/build.gradle index bae0a53b..093e6344 100644 --- a/build.gradle +++ b/build.gradle @@ -201,7 +201,7 @@ task updateProto(type: Exec) { } task setupCluster(type: Exec) { - workingDir System.getenv('GOPATH') + '/src/github.com/dgraph-io/dgraph/dgraph' + workingDir System.getenv('GOPATH') + '/src/github.com/hypermodeinc/dgraph/dgraph' commandLine './run.sh' } @@ -257,7 +257,7 @@ if (project.hasProperty('ossrhUsername')) { pom { name = 'dgraph4j' description = 'Dgraph Java Client' - url = 'https://github.com/dgraph-io/dgraph4j' + url = 'https://github.com/hypermodeinc/dgraph4j' licenses { license { @@ -272,8 +272,8 @@ if (project.hasProperty('ossrhUsername')) { } } scm { - connection = 'https://github.com/dgraph-io/dgraph4j.git' - url = 'https://github.com/dgraph-io/dgraph4j' + connection = 'https://github.com/hypermodeinc/dgraph4j.git' + url = 'https://github.com/hypermodeinc/dgraph4j' } } } diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 871b5b07..008cd17b 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -9,16 +9,17 @@ services: labels: cluster: test ports: - - 8180:8180 - - 9180:9180 + - 8180:8180 + - 9180:9180 volumes: - - type: bind - source: ./docker-test-secret.txt - target: /secret/hmac - read_only: true - command: dgraph alpha -o 100 --my=alpha1:7180 --zero=zero1:5180 --logtostderr - -v=2 --raft "idx=1; group=1" --security "whitelist=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16;" - --acl "secret-file=/secret/hmac; access-ttl=3s" + - type: bind + source: ./docker-test-secret.txt + target: /secret/hmac + read_only: true + command: + dgraph alpha -o 100 --my=alpha1:7180 --zero=zero1:5180 --logtostderr -v=2 --raft "idx=1; + group=1" --security "whitelist=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16;" --acl + "secret-file=/secret/hmac; access-ttl=3s" alpha2: image: dgraph/dgraph:local container_name: alpha2 @@ -26,16 +27,17 @@ services: labels: cluster: test ports: - - 8182:8182 - - 9182:9182 + - 8182:8182 + - 9182:9182 volumes: - - type: bind - source: ./docker-test-secret.txt - target: /secret/hmac - read_only: true - command: dgraph alpha -o 102 --my=alpha2:7182 --zero=zero1:5180 --logtostderr - -v=2 --raft "idx=2; group=1" --security "whitelist=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16;" - --acl "secret-file=/secret/hmac; access-ttl=3s" + - type: bind + source: ./docker-test-secret.txt + target: /secret/hmac + read_only: true + command: + dgraph alpha -o 102 --my=alpha2:7182 --zero=zero1:5180 --logtostderr -v=2 --raft "idx=2; + group=1" --security "whitelist=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16;" --acl + "secret-file=/secret/hmac; access-ttl=3s" alpha3: image: dgraph/dgraph:local container_name: alpha3 @@ -43,16 +45,17 @@ services: labels: cluster: test ports: - - 8183:8183 - - 9183:9183 + - 8183:8183 + - 9183:9183 volumes: - - type: bind - source: ./docker-test-secret.txt - target: /secret/hmac - read_only: true - command: dgraph alpha -o 103 --my=alpha3:7183 --zero=zero1:5180 --logtostderr - -v=2 --raft "idx=3; group=1" --security "whitelist=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16;" - --acl "secret-file=/secret/hmac; access-ttl=3s" + - type: bind + source: ./docker-test-secret.txt + target: /secret/hmac + read_only: true + command: + dgraph alpha -o 103 --my=alpha3:7183 --zero=zero1:5180 --logtostderr -v=2 --raft "idx=3; + group=1" --security "whitelist=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16;" --acl + "secret-file=/secret/hmac; access-ttl=3s" zero1: image: dgraph/dgraph:local container_name: zero1 @@ -60,8 +63,7 @@ services: labels: cluster: test ports: - - 5180:5180 - - 6180:6180 - command: dgraph zero -o 100 --raft='idx=1' --my=zero1:5180 --replicas=3 - --logtostderr -v=2 --bindall - + - 5180:5180 + - 6180:6180 + command: + dgraph zero -o 100 --raft='idx=1' --my=zero1:5180 --replicas=3 --logtostderr -v=2 --bindall diff --git a/gradlew b/gradlew index 1b6c7873..cdb5678a 100755 --- a/gradlew +++ b/gradlew @@ -69,18 +69,18 @@ app_path=$0 # Need this for daisy-chained symlinks. while - APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path - [ -h "$app_path" ] + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "${app_path}" ] do - ls=$( ls -ld "$app_path" ) - link=${ls#*' -> '} - case $link in #( - /*) app_path=$link ;; #( - *) app_path=$APP_HOME$link ;; - esac + ls=$(ls -ld "${app_path}") + link=${ls#*' -> '} + case ${link} in #( + /*) app_path=${link} ;; #( + *) app_path=${APP_HOME}${link} ;; + esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit +APP_HOME=$(cd "${APP_HOME:-./}" && pwd -P) || exit APP_NAME="Gradle" APP_BASE_NAME=${0##*/} @@ -91,15 +91,15 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum -warn () { - echo "$*" +warn() { + echo "$*" } >&2 -die () { - echo - echo "$*" - echo - exit 1 +die() { + echo + echo "$*" + echo + exit 1 } >&2 # OS specific support (must be 'true' or 'false'). @@ -107,51 +107,52 @@ cygwin=false msys=false darwin=false nonstop=false -case "$( uname )" in #( - CYGWIN* ) cygwin=true ;; #( - Darwin* ) darwin=true ;; #( - MSYS* | MINGW* ) msys=true ;; #( - NONSTOP* ) nonstop=true ;; +case "$(uname)" in #( +CYGWIN*) cygwin=true ;; #( +Darwin*) darwin=true ;; #( +MSYS* | MINGW*) msys=true ;; #( +NONSTOP*) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - +CLASSPATH=${APP_HOME}/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD=$JAVA_HOME/jre/sh/java - else - JAVACMD=$JAVA_HOME/bin/java - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME +if [ -n "${JAVA_HOME}" ]; then + if [ -x "${JAVA_HOME}/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=${JAVA_HOME}/jre/sh/java + else + JAVACMD=${JAVA_HOME}/bin/java + fi + if [ ! -x "${JAVACMD}" ]; then + die "ERROR: JAVA_HOME is set to an invalid directory: ${JAVA_HOME} Please set the JAVA_HOME variable in your environment to match the location of your Java installation." - fi + fi else - JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi # Increase the maximum file descriptors if we can. -if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then - case $MAX_FD in #( - max*) - MAX_FD=$( ulimit -H -n ) || - warn "Could not query maximum file descriptor limit" - esac - case $MAX_FD in #( - '' | soft) :;; #( - *) - ulimit -n "$MAX_FD" || - warn "Could not set maximum file descriptor limit to $MAX_FD" - esac +if ! "${cygwin}" && ! "${darwin}" && ! "${nonstop}"; then + case ${MAX_FD} in #( + max*) + MAX_FD=$(ulimit -H -n) || + warn "Could not query maximum file descriptor limit" + ;; + esac + case ${MAX_FD} in #( + '' | soft) : ;; #( + *) + ulimit -n "${MAX_FD}" || + warn "Could not set maximum file descriptor limit to ${MAX_FD}" + ;; + esac fi # Collect all arguments for the java command, stacking in reverse order: @@ -163,34 +164,36 @@ fi # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if "$cygwin" || "$msys" ; then - APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) - - JAVACMD=$( cygpath --unix "$JAVACMD" ) - - # Now convert the arguments - kludge to limit ourselves to /bin/sh - for arg do - if - case $arg in #( - -*) false ;; # don't mess with options #( - /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath - [ -e "$t" ] ;; #( - *) false ;; - esac - then - arg=$( cygpath --path --ignore --mixed "$arg" ) - fi - # Roll the args list around exactly as many times as the number of - # args, so each arg winds up back in the position where it started, but - # possibly modified. - # - # NB: a `for` loop captures its iteration list before it begins, so - # changing the positional parameters here affects neither the number of - # iterations, nor the values presented in `arg`. - shift # remove old arg - set -- "$@" "$arg" # push replacement arg - done +if "${cygwin}" || "${msys}"; then + APP_HOME=$(cygpath --path --mixed "${APP_HOME}") + CLASSPATH=$(cygpath --path --mixed "${CLASSPATH}") + + JAVACMD=$(cygpath --unix "${JAVACMD}") + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg; do + if + case ${arg} in #( + -*) false ;; # don't mess with options #( + /?*) + t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "${t}" ] + ;; #( + *) false ;; + esac + then + arg=$(cygpath --path --ignore --mixed "${arg}") + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "${arg}" # push replacement arg + done fi # Collect all arguments for the java command; @@ -200,10 +203,10 @@ fi # * put everything else in single quotes, so that it's not re-expanded. set -- \ - "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ - "$@" + "-Dorg.gradle.appname=${APP_BASE_NAME}" \ + -classpath "${CLASSPATH}" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" # Use "xargs" to parse quoted args. # @@ -225,10 +228,10 @@ set -- \ # eval "set -- $( - printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | - xargs -n1 | - sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | - tr '\n' ' ' - )" '"$@"' + printf '%s\n' "${DEFAULT_JVM_OPTS} ${JAVA_OPTS} ${GRADLE_OPTS}" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' +)" '"$@"' -exec "$JAVACMD" "$@" +exec "${JAVACMD}" "$@" diff --git a/samples/DgraphJavaSample/README.md b/samples/DgraphJavaSample/README.md index e4c33185..fcac6a30 100644 --- a/samples/DgraphJavaSample/README.md +++ b/samples/DgraphJavaSample/README.md @@ -1,7 +1,6 @@ -Sample project demonstrating the use of [dgraph4j], the official Java client -for Dgraph. +Sample project demonstrating the use of [dgraph4j], the official Java client for Dgraph. -[dgraph4j]: https://github.com/dgraph-io/dgraph4 +[dgraph4j]: https://github.com/hypermodeinc/dgraph4 ## Running @@ -9,10 +8,10 @@ for Dgraph. You will need to install [Dgraph v1.1.0 or above][releases] and run it. -[releases]: https://github.com/dgraph-io/dgraph/releases +[releases]: https://github.com/hypermodeinc/dgraph/releases -You can run the commands below to start a clean dgraph server everytime, for testing -and exploration. +You can run the commands below to start a clean dgraph server everytime, for testing and +exploration. First, create two separate directories for `dgraph zero` and `dgraph server`. @@ -35,15 +34,15 @@ rm -rf p w; dgraph alpha --zero localhost:5080 -o 100 ``` Notice that in the command above, we shifted the ports by 100 from the default ports of 7080 for -internal traffic, 8080 for http, and 9080 for GRPC, which means the alpha server is binding to -the port 7180 for internal traffic, 8180 for http, and 9180 for GRPC. +internal traffic, 8080 for http, and 9080 for GRPC, which means the alpha server is binding to the +port 7180 for internal traffic, 8180 for http, and 9180 for GRPC. For more configuration options, and other details, refer to [docs.dgraph.io](https://docs.dgraph.io) ## Run the sample code -**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. +**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. ``` $ ./gradlew run @@ -58,4 +57,5 @@ BUILD SUCCESSFUL in 1s ``` -If you see `Alice` in the output, everything is working fine. You can explore the source code in `src/main/java/App.java` file. +If you see `Alice` in the output, everything is working fine. You can explore the source code in +`src/main/java/App.java` file. diff --git a/samples/DgraphJavaSample/gradlew b/samples/DgraphJavaSample/gradlew index aeb74cbb..5b62df71 100755 --- a/samples/DgraphJavaSample/gradlew +++ b/samples/DgraphJavaSample/gradlew @@ -69,34 +69,34 @@ app_path=$0 # Need this for daisy-chained symlinks. while - APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path - [ -h "$app_path" ] + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "${app_path}" ] do - ls=$( ls -ld "$app_path" ) - link=${ls#*' -> '} - case $link in #( - /*) app_path=$link ;; #( - *) app_path=$APP_HOME$link ;; - esac + ls=$(ls -ld "${app_path}") + link=${ls#*' -> '} + case ${link} in #( + /*) app_path=${link} ;; #( + *) app_path=${APP_HOME}${link} ;; + esac done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit +APP_HOME=$(cd "${APP_HOME:-./}" && pwd -P) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum -warn () { - echo "$*" +warn() { + echo "$*" } >&2 -die () { - echo - echo "$*" - echo - exit 1 +die() { + echo + echo "$*" + echo + exit 1 } >&2 # OS specific support (must be 'true' or 'false'). @@ -104,55 +104,56 @@ cygwin=false msys=false darwin=false nonstop=false -case "$( uname )" in #( - CYGWIN* ) cygwin=true ;; #( - Darwin* ) darwin=true ;; #( - MSYS* | MINGW* ) msys=true ;; #( - NONSTOP* ) nonstop=true ;; +case "$(uname)" in #( +CYGWIN*) cygwin=true ;; #( +Darwin*) darwin=true ;; #( +MSYS* | MINGW*) msys=true ;; #( +NONSTOP*) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - +CLASSPATH=${APP_HOME}/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD=$JAVA_HOME/jre/sh/java - else - JAVACMD=$JAVA_HOME/bin/java - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME +if [ -n "${JAVA_HOME}" ]; then + if [ -x "${JAVA_HOME}/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=${JAVA_HOME}/jre/sh/java + else + JAVACMD=${JAVA_HOME}/bin/java + fi + if [ ! -x "${JAVACMD}" ]; then + die "ERROR: JAVA_HOME is set to an invalid directory: ${JAVA_HOME} Please set the JAVA_HOME variable in your environment to match the location of your Java installation." - fi + fi else - JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi # Increase the maximum file descriptors if we can. -if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then - case $MAX_FD in #( - max*) - # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 - MAX_FD=$( ulimit -H -n ) || - warn "Could not query maximum file descriptor limit" - esac - case $MAX_FD in #( - '' | soft) :;; #( - *) - # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 - ulimit -n "$MAX_FD" || - warn "Could not set maximum file descriptor limit to $MAX_FD" - esac +if ! "${cygwin}" && ! "${darwin}" && ! "${nonstop}"; then + case ${MAX_FD} in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$(ulimit -H -n) || + warn "Could not query maximum file descriptor limit" + ;; + esac + case ${MAX_FD} in #( + '' | soft) : ;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "${MAX_FD}" || + warn "Could not set maximum file descriptor limit to ${MAX_FD}" + ;; + esac fi # Collect all arguments for the java command, stacking in reverse order: @@ -164,37 +165,38 @@ fi # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if "$cygwin" || "$msys" ; then - APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) - - JAVACMD=$( cygpath --unix "$JAVACMD" ) - - # Now convert the arguments - kludge to limit ourselves to /bin/sh - for arg do - if - case $arg in #( - -*) false ;; # don't mess with options #( - /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath - [ -e "$t" ] ;; #( - *) false ;; - esac - then - arg=$( cygpath --path --ignore --mixed "$arg" ) - fi - # Roll the args list around exactly as many times as the number of - # args, so each arg winds up back in the position where it started, but - # possibly modified. - # - # NB: a `for` loop captures its iteration list before it begins, so - # changing the positional parameters here affects neither the number of - # iterations, nor the values presented in `arg`. - shift # remove old arg - set -- "$@" "$arg" # push replacement arg - done +if "${cygwin}" || "${msys}"; then + APP_HOME=$(cygpath --path --mixed "${APP_HOME}") + CLASSPATH=$(cygpath --path --mixed "${CLASSPATH}") + + JAVACMD=$(cygpath --unix "${JAVACMD}") + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg; do + if + case ${arg} in #( + -*) false ;; # don't mess with options #( + /?*) + t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "${t}" ] + ;; #( + *) false ;; + esac + then + arg=$(cygpath --path --ignore --mixed "${arg}") + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "${arg}" # push replacement arg + done fi - # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' @@ -205,15 +207,14 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # * put everything else in single quotes, so that it's not re-expanded. set -- \ - "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ - "$@" + "-Dorg.gradle.appname=${APP_BASE_NAME}" \ + -classpath "${CLASSPATH}" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" # Stop when "xargs" is not available. -if ! command -v xargs >/dev/null 2>&1 -then - die "xargs is not available" +if ! command -v xargs >/dev/null 2>&1; then + die "xargs is not available" fi # Use "xargs" to parse quoted args. @@ -236,10 +237,10 @@ fi # eval "set -- $( - printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | - xargs -n1 | - sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | - tr '\n' ' ' - )" '"$@"' + printf '%s\n' "${DEFAULT_JVM_OPTS} ${JAVA_OPTS} ${GRADLE_OPTS}" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' +)" '"$@"' -exec "$JAVACMD" "$@" +exec "${JAVACMD}" "$@" diff --git a/samples/DgraphJavaSampleDeadlineInterceptors/README.md b/samples/DgraphJavaSampleDeadlineInterceptors/README.md index d800e4a7..80b73b09 100644 --- a/samples/DgraphJavaSampleDeadlineInterceptors/README.md +++ b/samples/DgraphJavaSampleDeadlineInterceptors/README.md @@ -1,15 +1,15 @@ -Sample project demonstrating the use of [dgraph4j], the official Java client -for Dgraph. +Sample project demonstrating the use of [dgraph4j], the official Java client for Dgraph. -[dgraph4j]: https://github.com/dgraph-io/dgraph4 +[dgraph4j]: https://github.com/hypermodeinc/dgraph4 ## Running ### Start Dgraph Server -You will need to install [Dgraph v21.3.0 or above][releases] and start a local cluster as shown below. +You will need to install [Dgraph v21.3.0 or above][releases] and start a local cluster as shown +below. -[releases]: https://github.com/dgraph-io/dgraph/releases +[releases]: https://github.com/hypermodeinc/dgraph/releases First, create two separate directories for `dgraph zero` and `dgraph server`. @@ -32,20 +32,20 @@ rm -rf p w t; dgraph alpha --zero localhost:5080 -o 100 ``` Notice that in the command above, we shifted the ports by 100 from the default ports of 7080 for -internal traffic, 8080 for http, and 9080 for GRPC, which means the alpha server is binding to -the port 7180 for internal traffic, 8180 for http, and 9180 for GRPC. +internal traffic, 8080 for http, and 9080 for GRPC, which means the alpha server is binding to the +port 7180 for internal traffic, 8180 for http, and 9180 for GRPC. For more configuration options, and other details, refer to [docs.dgraph.io](https://docs.dgraph.io) ## Run the sample code -**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. +**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. -This example in [App.java:39](./src/main/java/App.java#L39-L47) creates the -DgraphStub with a deadline using a call interceptor to set timeouts **per -request**. This is most likely what you want to do. For more info, see [Setting -Deadlines](https://github.com/dgraph-io/dgraph4j/#setting-deadlines). +This example in [App.java:39](./src/main/java/App.java#L39-L47) creates the DgraphStub with a +deadline using a call interceptor to set timeouts **per request**. This is most likely what you want +to do. For more info, see +[Setting Deadlines](https://github.com/hypermodeinc/dgraph4j/#setting-deadlines). ```java stub = @@ -115,5 +115,5 @@ Sleeping for 1 second Done! ``` -If you see the output `Done!`, then the example works as expected. -You can explore the source code in `src/main/java/App.java` file. +If you see the output `Done!`, then the example works as expected. You can explore the source code +in `src/main/java/App.java` file. diff --git a/samples/DgraphJavaSampleDeadlineInterceptors/gradlew b/samples/DgraphJavaSampleDeadlineInterceptors/gradlew index aeb74cbb..5b62df71 100755 --- a/samples/DgraphJavaSampleDeadlineInterceptors/gradlew +++ b/samples/DgraphJavaSampleDeadlineInterceptors/gradlew @@ -69,34 +69,34 @@ app_path=$0 # Need this for daisy-chained symlinks. while - APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path - [ -h "$app_path" ] + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "${app_path}" ] do - ls=$( ls -ld "$app_path" ) - link=${ls#*' -> '} - case $link in #( - /*) app_path=$link ;; #( - *) app_path=$APP_HOME$link ;; - esac + ls=$(ls -ld "${app_path}") + link=${ls#*' -> '} + case ${link} in #( + /*) app_path=${link} ;; #( + *) app_path=${APP_HOME}${link} ;; + esac done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit +APP_HOME=$(cd "${APP_HOME:-./}" && pwd -P) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum -warn () { - echo "$*" +warn() { + echo "$*" } >&2 -die () { - echo - echo "$*" - echo - exit 1 +die() { + echo + echo "$*" + echo + exit 1 } >&2 # OS specific support (must be 'true' or 'false'). @@ -104,55 +104,56 @@ cygwin=false msys=false darwin=false nonstop=false -case "$( uname )" in #( - CYGWIN* ) cygwin=true ;; #( - Darwin* ) darwin=true ;; #( - MSYS* | MINGW* ) msys=true ;; #( - NONSTOP* ) nonstop=true ;; +case "$(uname)" in #( +CYGWIN*) cygwin=true ;; #( +Darwin*) darwin=true ;; #( +MSYS* | MINGW*) msys=true ;; #( +NONSTOP*) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - +CLASSPATH=${APP_HOME}/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD=$JAVA_HOME/jre/sh/java - else - JAVACMD=$JAVA_HOME/bin/java - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME +if [ -n "${JAVA_HOME}" ]; then + if [ -x "${JAVA_HOME}/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=${JAVA_HOME}/jre/sh/java + else + JAVACMD=${JAVA_HOME}/bin/java + fi + if [ ! -x "${JAVACMD}" ]; then + die "ERROR: JAVA_HOME is set to an invalid directory: ${JAVA_HOME} Please set the JAVA_HOME variable in your environment to match the location of your Java installation." - fi + fi else - JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi # Increase the maximum file descriptors if we can. -if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then - case $MAX_FD in #( - max*) - # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 - MAX_FD=$( ulimit -H -n ) || - warn "Could not query maximum file descriptor limit" - esac - case $MAX_FD in #( - '' | soft) :;; #( - *) - # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 - ulimit -n "$MAX_FD" || - warn "Could not set maximum file descriptor limit to $MAX_FD" - esac +if ! "${cygwin}" && ! "${darwin}" && ! "${nonstop}"; then + case ${MAX_FD} in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$(ulimit -H -n) || + warn "Could not query maximum file descriptor limit" + ;; + esac + case ${MAX_FD} in #( + '' | soft) : ;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "${MAX_FD}" || + warn "Could not set maximum file descriptor limit to ${MAX_FD}" + ;; + esac fi # Collect all arguments for the java command, stacking in reverse order: @@ -164,37 +165,38 @@ fi # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if "$cygwin" || "$msys" ; then - APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) - - JAVACMD=$( cygpath --unix "$JAVACMD" ) - - # Now convert the arguments - kludge to limit ourselves to /bin/sh - for arg do - if - case $arg in #( - -*) false ;; # don't mess with options #( - /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath - [ -e "$t" ] ;; #( - *) false ;; - esac - then - arg=$( cygpath --path --ignore --mixed "$arg" ) - fi - # Roll the args list around exactly as many times as the number of - # args, so each arg winds up back in the position where it started, but - # possibly modified. - # - # NB: a `for` loop captures its iteration list before it begins, so - # changing the positional parameters here affects neither the number of - # iterations, nor the values presented in `arg`. - shift # remove old arg - set -- "$@" "$arg" # push replacement arg - done +if "${cygwin}" || "${msys}"; then + APP_HOME=$(cygpath --path --mixed "${APP_HOME}") + CLASSPATH=$(cygpath --path --mixed "${CLASSPATH}") + + JAVACMD=$(cygpath --unix "${JAVACMD}") + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg; do + if + case ${arg} in #( + -*) false ;; # don't mess with options #( + /?*) + t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "${t}" ] + ;; #( + *) false ;; + esac + then + arg=$(cygpath --path --ignore --mixed "${arg}") + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "${arg}" # push replacement arg + done fi - # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' @@ -205,15 +207,14 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # * put everything else in single quotes, so that it's not re-expanded. set -- \ - "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ - "$@" + "-Dorg.gradle.appname=${APP_BASE_NAME}" \ + -classpath "${CLASSPATH}" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" # Stop when "xargs" is not available. -if ! command -v xargs >/dev/null 2>&1 -then - die "xargs is not available" +if ! command -v xargs >/dev/null 2>&1; then + die "xargs is not available" fi # Use "xargs" to parse quoted args. @@ -236,10 +237,10 @@ fi # eval "set -- $( - printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | - xargs -n1 | - sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | - tr '\n' ' ' - )" '"$@"' + printf '%s\n' "${DEFAULT_JVM_OPTS} ${JAVA_OPTS} ${GRADLE_OPTS}" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' +)" '"$@"' -exec "$JAVACMD" "$@" +exec "${JAVACMD}" "$@" diff --git a/samples/DgraphJavaSampleWithDeadlineAfter/README.md b/samples/DgraphJavaSampleWithDeadlineAfter/README.md index 03499f14..49e453af 100644 --- a/samples/DgraphJavaSampleWithDeadlineAfter/README.md +++ b/samples/DgraphJavaSampleWithDeadlineAfter/README.md @@ -1,7 +1,6 @@ -Sample project demonstrating the use of [dgraph4j], the official Java client -for Dgraph. +Sample project demonstrating the use of [dgraph4j], the official Java client for Dgraph. -[dgraph4j]: https://github.com/dgraph-io/dgraph4 +[dgraph4j]: https://github.com/hypermodeinc/dgraph4 ## Running @@ -9,10 +8,10 @@ for Dgraph. You will need to install [Dgraph v21.03.0 or above][releases] and run it. -[releases]: https://github.com/dgraph-io/dgraph/releases +[releases]: https://github.com/hypermodeinc/dgraph/releases -You can run the commands below to start a clean dgraph server everytime, for testing -and exploration. +You can run the commands below to start a clean dgraph server everytime, for testing and +exploration. First, create two separate directories for `dgraph zero` and `dgraph server`. @@ -35,20 +34,19 @@ rm -rf p w t; dgraph alpha --zero localhost:5080 -o 100 ``` Notice that in the command above, we shifted the ports by 100 from the default ports of 7080 for -internal traffic, 8080 for http, and 9080 for GRPC, which means the alpha server is binding to -the port 7180 for internal traffic, 8180 for http, and 9180 for GRPC. +internal traffic, 8080 for http, and 9080 for GRPC, which means the alpha server is binding to the +port 7180 for internal traffic, 8180 for http, and 9180 for GRPC. For more configuration options, and other details, refer to [docs.dgraph.io](https://docs.dgraph.io) ## Run the sample code -**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. +**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. -This example in [App.java:34](./src/main/java/App.java#L34) creates the -DgraphStub with a deadline set for the **entire life of the stub**. This is most -likely what you do NOT want to do. For more info, see [Setting -Deadlines](https://github.com/dgraph-io/dgraph4j/#setting-deadlines). +This example in [App.java:34](./src/main/java/App.java#L34) creates the DgraphStub with a deadline +set for the **entire life of the stub**. This is most likely what you do NOT want to do. For more +info, see [Setting Deadlines](https://github.com/hypermodeinc/dgraph4j/#setting-deadlines). ```java stub = stub.withDeadlineAfter(5, TimeUnit.SECONDS); @@ -116,5 +114,5 @@ Caused by: io.grpc.StatusRuntimeException: DEADLINE_EXCEEDED: ClientCall started at java.lang.Thread.run(Thread.java:748) ``` -If you see the output `ClientCall started after deadline exceeded`, then the example works as expected. -You can explore the source code in `src/main/java/App.java` file. +If you see the output `ClientCall started after deadline exceeded`, then the example works as +expected. You can explore the source code in `src/main/java/App.java` file. diff --git a/samples/DgraphJavaSampleWithDeadlineAfter/gradlew b/samples/DgraphJavaSampleWithDeadlineAfter/gradlew index aeb74cbb..5b62df71 100755 --- a/samples/DgraphJavaSampleWithDeadlineAfter/gradlew +++ b/samples/DgraphJavaSampleWithDeadlineAfter/gradlew @@ -69,34 +69,34 @@ app_path=$0 # Need this for daisy-chained symlinks. while - APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path - [ -h "$app_path" ] + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "${app_path}" ] do - ls=$( ls -ld "$app_path" ) - link=${ls#*' -> '} - case $link in #( - /*) app_path=$link ;; #( - *) app_path=$APP_HOME$link ;; - esac + ls=$(ls -ld "${app_path}") + link=${ls#*' -> '} + case ${link} in #( + /*) app_path=${link} ;; #( + *) app_path=${APP_HOME}${link} ;; + esac done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit +APP_HOME=$(cd "${APP_HOME:-./}" && pwd -P) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum -warn () { - echo "$*" +warn() { + echo "$*" } >&2 -die () { - echo - echo "$*" - echo - exit 1 +die() { + echo + echo "$*" + echo + exit 1 } >&2 # OS specific support (must be 'true' or 'false'). @@ -104,55 +104,56 @@ cygwin=false msys=false darwin=false nonstop=false -case "$( uname )" in #( - CYGWIN* ) cygwin=true ;; #( - Darwin* ) darwin=true ;; #( - MSYS* | MINGW* ) msys=true ;; #( - NONSTOP* ) nonstop=true ;; +case "$(uname)" in #( +CYGWIN*) cygwin=true ;; #( +Darwin*) darwin=true ;; #( +MSYS* | MINGW*) msys=true ;; #( +NONSTOP*) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - +CLASSPATH=${APP_HOME}/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD=$JAVA_HOME/jre/sh/java - else - JAVACMD=$JAVA_HOME/bin/java - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME +if [ -n "${JAVA_HOME}" ]; then + if [ -x "${JAVA_HOME}/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=${JAVA_HOME}/jre/sh/java + else + JAVACMD=${JAVA_HOME}/bin/java + fi + if [ ! -x "${JAVACMD}" ]; then + die "ERROR: JAVA_HOME is set to an invalid directory: ${JAVA_HOME} Please set the JAVA_HOME variable in your environment to match the location of your Java installation." - fi + fi else - JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi # Increase the maximum file descriptors if we can. -if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then - case $MAX_FD in #( - max*) - # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 - MAX_FD=$( ulimit -H -n ) || - warn "Could not query maximum file descriptor limit" - esac - case $MAX_FD in #( - '' | soft) :;; #( - *) - # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 - ulimit -n "$MAX_FD" || - warn "Could not set maximum file descriptor limit to $MAX_FD" - esac +if ! "${cygwin}" && ! "${darwin}" && ! "${nonstop}"; then + case ${MAX_FD} in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$(ulimit -H -n) || + warn "Could not query maximum file descriptor limit" + ;; + esac + case ${MAX_FD} in #( + '' | soft) : ;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "${MAX_FD}" || + warn "Could not set maximum file descriptor limit to ${MAX_FD}" + ;; + esac fi # Collect all arguments for the java command, stacking in reverse order: @@ -164,37 +165,38 @@ fi # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if "$cygwin" || "$msys" ; then - APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) - - JAVACMD=$( cygpath --unix "$JAVACMD" ) - - # Now convert the arguments - kludge to limit ourselves to /bin/sh - for arg do - if - case $arg in #( - -*) false ;; # don't mess with options #( - /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath - [ -e "$t" ] ;; #( - *) false ;; - esac - then - arg=$( cygpath --path --ignore --mixed "$arg" ) - fi - # Roll the args list around exactly as many times as the number of - # args, so each arg winds up back in the position where it started, but - # possibly modified. - # - # NB: a `for` loop captures its iteration list before it begins, so - # changing the positional parameters here affects neither the number of - # iterations, nor the values presented in `arg`. - shift # remove old arg - set -- "$@" "$arg" # push replacement arg - done +if "${cygwin}" || "${msys}"; then + APP_HOME=$(cygpath --path --mixed "${APP_HOME}") + CLASSPATH=$(cygpath --path --mixed "${CLASSPATH}") + + JAVACMD=$(cygpath --unix "${JAVACMD}") + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg; do + if + case ${arg} in #( + -*) false ;; # don't mess with options #( + /?*) + t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "${t}" ] + ;; #( + *) false ;; + esac + then + arg=$(cygpath --path --ignore --mixed "${arg}") + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "${arg}" # push replacement arg + done fi - # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' @@ -205,15 +207,14 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # * put everything else in single quotes, so that it's not re-expanded. set -- \ - "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ - "$@" + "-Dorg.gradle.appname=${APP_BASE_NAME}" \ + -classpath "${CLASSPATH}" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" # Stop when "xargs" is not available. -if ! command -v xargs >/dev/null 2>&1 -then - die "xargs is not available" +if ! command -v xargs >/dev/null 2>&1; then + die "xargs is not available" fi # Use "xargs" to parse quoted args. @@ -236,10 +237,10 @@ fi # eval "set -- $( - printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | - xargs -n1 | - sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | - tr '\n' ' ' - )" '"$@"' + printf '%s\n' "${DEFAULT_JVM_OPTS} ${JAVA_OPTS} ${GRADLE_OPTS}" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' +)" '"$@"' -exec "$JAVACMD" "$@" +exec "${JAVACMD}" "$@" diff --git a/samples/concurrent-modification/README.md b/samples/concurrent-modification/README.md index b0ba3c99..51adcda9 100644 --- a/samples/concurrent-modification/README.md +++ b/samples/concurrent-modification/README.md @@ -1,8 +1,8 @@ -This example shows how to handle concurrent modifications using a multi-threaded Java Program. -The example demonstrates [transaction](https://dgraph.io/docs/clients/overview/#transactions) -conflicts in Dgraph. +This example shows how to handle concurrent modifications using a multi-threaded Java Program. The +example demonstrates [transaction](https://dgraph.io/docs/clients/overview/#transactions) conflicts +in Dgraph. -[dgraph4j]: https://github.com/dgraph-io/dgraph4j +[dgraph4j]: https://github.com/hypermodeinc/dgraph4j ## Steps to run this example @@ -12,10 +12,9 @@ Step 1: Start a new terminal and launch Dgraph with the following command line. docker run -it -p 8080:8080 -p 9080:9080 dgraph/standalone:master ``` -Step 2: Checkout the source code from the 'samples' directory in dgraph4j repository. -This particular example can be found at the path "samples/concurrent-modification". -In order to run this example, execute the following maven command from the -'concurrent-modification' folder. +Step 2: Checkout the source code from the 'samples' directory in dgraph4j repository. This +particular example can be found at the path "samples/concurrent-modification". In order to run this +example, execute the following maven command from the 'concurrent-modification' folder. **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. @@ -32,14 +31,14 @@ Step 3: On running the example, the program initializes Dgraph with the followin ``` Step 4: The program also initializes user "Alice" with a 'clickCount' of value '1', and then -proceeds to increment 'clickCount' concurrently in two threads. Dgraph throws an exception if -a transaction is updating a given predicate that is being concurrently modified. As part of the +proceeds to increment 'clickCount' concurrently in two threads. Dgraph throws an exception if a +transaction is updating a given predicate that is being concurrently modified. As part of the exception handling logic, the program sleeps for 1 second on receiving a concurrent modification exception (“TxnConflictException”), and then retries. -
The logs below show that two threads are increasing clickCount for the same user named -Alice (note the same uid). Thread #1 succeeds immediately, and Dgraph throws a concurrent -modification conflict on Thread 2. Thread 2 sleeps for 1 second and retries, and this time succeeds. +
The logs below show that two threads are increasing clickCount for the same user named Alice +(note the same uid). Thread #1 succeeds immediately, and Dgraph throws a concurrent modification +conflict on Thread 2. Thread 2 sleeps for 1 second and retries, and this time succeeds. <-timestamp-> <-log-> @@ -85,6 +84,6 @@ Response: **Summary** Concurrent modifications to the same predicate causes the TxnConflictException. When several -transactions hit the same node's predicate at the same time, the first one succeeds, while the -other will get the “io.dgraph.TxnConflictException”. Upon constantly retrying, the transactions -begin to succeed one after another, and given enough retries, correctly completes its work. +transactions hit the same node's predicate at the same time, the first one succeeds, while the other +will get the “io.dgraph.TxnConflictException”. Upon constantly retrying, the transactions begin to +succeed one after another, and given enough retries, correctly completes its work.