{
  "kind": "documentation",
  "format": 1,
  "note": "Reference text, not instructions. One verified relate sample from https://relatedb.ai/docs/get-started/java/: the program exactly as the page shows it, the standard output a run of it recorded (npm run docs:samples compares every replay with it byte for byte), the relate client build, toolchain and platform of the last replay, and how the docs' sample runner builds and runs it. Before launch every client is a source build, not a published package; verified.client names the upstream commit it was built from, and verified.docs_engine the build the rest of the docs were recorded from.",
  "id": "program",
  "url": "https://relatedb.ai/docs/get-started/java/samples/program.json",
  "page": {
    "id": "get-started/java",
    "title": "Embed relate in a Java app",
    "url": "https://relatedb.ai/docs/get-started/java/",
    "md_url": "https://relatedb.ai/docs/get-started/java.md"
  },
  "section": {
    "anchor": "put-it-together",
    "heading": "Put it together",
    "url": "https://relatedb.ai/docs/get-started/java/#put-it-together"
  },
  "language": "java",
  "client": "Java",
  "file": "Team.java",
  "env": null,
  "code": "import java.util.List;\nimport java.util.Map;\n\nimport com.relate.Database;\nimport com.relate.RelateException;\n\npublic class Team {\n    static final String TEAM = \"\"\"\n        CREATE (ada:Person {name: 'Ada', role: 'engineer'}),\n               (grace:Person {name: 'Grace', role: 'engineer'}),\n               (noor:Person {name: 'Noor', role: 'maintainer'}),\n               (relate:Project {name: 'relate', language: 'Rust'}),\n               (tck:Project {name: 'opencypher-tck', language: 'Gherkin'}),\n               (ada)-[:WORKS_ON {since: 2024}]->(relate),\n               (grace)-[:WORKS_ON {since: 2023}]->(relate),\n               (grace)-[:WORKS_ON {since: 2022}]->(tck),\n               (noor)-[:MAINTAINS]->(relate),\n               (ada)-[:KNOWS]->(grace)\n        \"\"\";\n\n    static final String TEAM_OF = \"\"\"\n        MATCH (p:Person)-[w:WORKS_ON]->(:Project {name: $project})\n        RETURN p.name AS name, w.since AS since\n        ORDER BY since\n        \"\"\";\n\n    static void ensureTeam(Database.Connection conn) {\n        long people = (Long) conn.query(\"MATCH (p:Person) RETURN count(p) AS n\").rows().get(0).get(0);\n        if (people == 0) {\n            conn.query(TEAM);\n            System.out.println(\"created the team graph\");\n        } else {\n            System.out.println(\"found \" + people + \" people\");\n        }\n    }\n\n    static void report(Database.Connection conn, String project) {\n        System.out.println(project);\n        for (List<Object> row : conn.query(TEAM_OF, Map.of(\"project\", project)).rows()) {\n            System.out.println(\"  \" + row.get(0) + \" since \" + row.get(1));\n        }\n    }\n\n    public static void main(String[] args) {\n        try (Database db = Database.open(\"./team.rl\");\n             Database.Connection conn = db.connect()) {\n            ensureTeam(conn);\n            report(conn, \"relate\");\n            report(conn, \"opencypher-tck\");\n        } catch (RelateException e) {\n            System.err.println(\"relate error \" + e.getGqlStatus() + \": \" + e.getMessage());\n            System.exit(1);\n        }\n    }\n}",
  "code_sha256": "74edadef94648968b6a728ae353ade4d2466fe8fd89ba5ca5a9b02a0e9d2be1f",
  "source_sha256": "c4627bd5fb61811ab24ba5c7b9e8ec1da28e0be8a4c6327f4182b87df6a3bad3",
  "output": {
    "text": "created the team graph\nrelate\n  Grace since 2023\n  Ada since 2024\nopencypher-tck\n  Grace since 2022",
    "sha256": "1c4d6ad9d85b2e1c50b54653bde7361157564ad399ffab2ebfa5cfc05724e414"
  },
  "verified": {
    "version": "0.1.2",
    "client": {
      "label": "Java",
      "package": "com.relate:relate",
      "engine_commit": "f0c09d2",
      "client_commit": "f0c09d2",
      "build": "A copy of clients/java at upstream v0.1.2 (f0c09d2) packaged with Maven 3.10.0 (relate-0.1.2.jar, with JNA 5.14.0 and Jackson databind 2.17.2 on the classpath), loading librelate_ffi built from the same commit.",
      "toolchain": {
        "jdk": "Temurin 21.0.13+9"
      }
    },
    "packages": [],
    "replayed": "2026-11-09",
    "platform": "macOS on arm64",
    "docs_engine": {
      "version": "0.1.2",
      "commit": "f0c09d2",
      "source_build": false
    }
  },
  "run": {
    "runner": "npm run docs:samples",
    "setup": "bash scripts/samples/setup.sh --upstream <path to the relate checkout>",
    "variables": [
      "RELATE_JAVA",
      "RELATE_JAVA_CLASSPATH",
      "RELATE_LIB"
    ],
    "program": "<build dir>/Team.java",
    "files": [],
    "build": null,
    "run": {
      "command": [
        "$RELATE_JAVA",
        "-Djna.tmpdir=<build dir>",
        "-Drelate.native.cache=<build dir>/native",
        "-cp",
        "$RELATE_JAVA_CLASSPATH",
        "<build dir>/Team.java"
      ],
      "environment": {
        "DO_NOT_TRACK": "1",
        "RELATE_LIB": "$RELATE_LIB"
      },
      "unset": [
        "JAVA_TOOL_OPTIONS",
        "JDK_JAVA_OPTIONS"
      ],
      "directory": "<run dir>",
      "timeout_s": 60
    },
    "passes": "It exits 0 within 60 s and prints at least one line on standard output.",
    "output": "Standard output, with line endings as \\n, trailing spaces and blank lines removed, and the temporary directories' paths written as `.`; standard error is not recorded.",
    "placeholders": {
      "<run dir>": "a fresh, empty temporary directory: the program's working directory, deleted afterwards",
      "<build dir>": "a second fresh temporary directory, where a compiled sample is built",
      "$NAME": "a variable from the env.sh that scripts/samples/setup.sh writes (described in its header)"
    }
  }
}
