# Runnable protected order editing example

Read the [developer guide](https://teaql.io/docs/cookbook/secure-document-references/).
Download `OrderEditExample.java`, `SqliteOrderDocumentService.java` and `run.sh`
into the same directory.

The example uses Java source preview
`af59bf4ee6f003f509ce8cc42a5d96bb5dcdb8c3`. Install its dependencies first:

```bash
git clone https://github.com/teaql/teaql-java.git
cd teaql-java
git checkout af59bf4ee6f003f509ce8cc42a5d96bb5dcdb8c3
mvn -pl examples/round-trip-reference-runtime -am install -DskipTests
export TEAQL_JAVA_SOURCE="$PWD"
```

Then, from the directory containing the three downloads:

```bash
bash run.sh
```

Use Java 21 on PATH and Maven. If necessary set `MAVEN_BIN` and
`TEAQL_MAVEN_REPO` to the executable and cache used for the source installation.
The runner exports the source example's runtime dependency classpath, compiles
both Java files and executes `OrderEditExample`. No generated domain library,
web server or database server is required. It creates and removes an owned
SQLite file. The compile scratch and downloaded remote-run copy are cleaned.

## What is application code?

`SqliteOrderDocumentService.java` is a byte-for-byte copy of the application-owned
service in the pinned runtime's `examples/round-trip-reference-runtime` source.
It is not a generic service installed automatically by
`SecureDocumentReferenceModule`. It defines the Order projection, complete item
relation, quantity/removal rules, SQL authorization, optimistic versions and
atomic command receipt persistence for this fixture. It uses JDBC directly.

`OrderEditExample.java` supplies the disposable schema/fixture, governed provider,
trusted demo identities and key, client-body helpers and checked operations.
It creates a random key once per execution and shares it across its fresh
request contexts. Production key management, authentication and ownership rules
must be provided by the embedding application. Do not generate a new random
key for each real request or derive the trusted principal from client JSON.
The example uses DEVELOPMENT profile with a governed provider, not a raw-ID
fallback.

## Verified on 2026-11-01

`verification.json` retains exact inputs and Java revision, successful source
installation and native compile/run commands, output, dependency hashes and
class-byte matches with source-built core/runtime/secure JARs. It was executed
with Java 21.0.6, Maven 3.9.16 and SQLite JDBC 3.53.2.1. The original domain service
was compared byte for byte before compilation. Native output has nine PASS
receipts and no printed document tokens. The temporary application database,
compiled classes and remote runner directory were removed.

The receipts check:

1. Open an order by business ID, with two item rows and a protected token.
2. Reject changed read-only product names and an omitted row without removal.
3. Reject Bob's submission of Alice's document.
4. Inject a child SQL write failure and verify root/quantity/receipt rollback.
5. Retry after removing that failure: quantity 2→5, root revision 1→2, one receipt.
6. Replay that exact request in a fresh Alice context without another write;
   reject a changed body under the same command ID.
7. Reject a new command against the original stale document.
8. Continue from the returned document and remove only the explicitly named row.
9. Revoke SQL permission and reject both new open and committed-command replay.

A telemetry startup notice remains in native output. No expiry/rotation,
process-restart recovery, HTTP transport, generated Q/E, governed view preparation,
Blob selection, concurrency stress or deployed application qualification is
claimed. The old Rust generated example is a distinct source example with its
own historical evidence; this Java run does not certify it. One initial SSH
connection closed before remote-run output; it is not a passing attempt.
