Skip to content

Commit 2bcc027

Browse files
author
Philip Z
committed
Add executable Java conformance example
1 parent e50ca25 commit 2bcc027

41 files changed

Lines changed: 3023 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎examples/conformance/.gitignore‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
*.gz
3+
target/
4+
*.db
5+
6+
### IntelliJ IDEA ###
7+
.idea/*
8+
.idea/modules.xml
9+
.idea/jarRepositories.xml
10+
.idea/compiler.xml
11+
.idea/libraries/
12+
*.iws
13+
*.iml
14+
*.ipr
15+
out/
16+
!**/src/main/**/out/
17+
!**/src/test/**/out/
18+
19+
### Eclipse ###
20+
.apt_generated
21+
.classpath
22+
.factorypath
23+
.project
24+
.settings
25+
.springBeans
26+
.sts4-cache
27+
bin/
28+
!**/src/main/**/bin/
29+
!**/src/test/**/bin/
30+
31+
### NetBeans ###
32+
/nbproject/private/
33+
/dist/
34+
/nbdist/
35+
36+
### VS Code ###
37+
.vscode/
38+
39+
### Mac OS ###
40+
.DS_Store
41+
42+
*.class
43+
*.log
44+
*.contextt
45+
.mtj.tmp/
46+
*.jar
47+
*.war
48+
*.nar
49+
*.ear
50+
*.zip
51+
*.tar.gz
52+
*.rar
53+
hs_err_pid*
54+
replay_pid*

‎examples/conformance/AGENTS.md‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<!-- DISCARD_BLOCK: phase_modeling -->
2+
3+
# TeaQL Java Agent Instructions
4+
5+
> [!WARNING]
6+
> **IGNORE GENERIC ORM EXPERIENCE**
7+
>
8+
> Do **not** use pre-trained habits from data-access frameworks, ORMs, or database integration libraries.
9+
>
10+
> Do **not** use MyBatis, JPA, Hibernate, Spring Data, MyBatis-Plus, or similar frameworks.
11+
>
12+
> Do **not** write raw SQL, DAOs, Repository implementations, or custom persistence layers.
13+
>
14+
> Do **not** guess TeaQL method names.
15+
16+
## How to Write Domain Code
17+
18+
To get the exact API usage and query examples for the entity you are working on, execute the following command:
19+
20+
```bash
21+
cargo teaql --input models/runtime-example-conformance-service.xml java-assist-[action]/[entity-name]
22+
```
23+
24+
> `models/runtime-example-conformance-service.xml` is the default model path. If the model file is located elsewhere, adjust the `--input` path to match the actual file location in this project.
25+
26+
Replace `[action]` with one of the following:
27+
28+
| action | when-to-use |
29+
|--------|-------------|
30+
| query | Read/find records from the database using Q. |
31+
| create | Insert a new record into the database |
32+
| update | Modify and save an existing record |
33+
| delete | Remove or soft-delete a record |
34+
| expression | Safely extract nested relation values using E. |
35+
| list-page | Implement a paginated query returning SmartList |
36+
| debug | View instructions for enabling SQL logging and debugging |
37+
38+
Replace `[entity-name]` with the exact entity-name from the table below:
39+
40+
| entity-name | display-name |
41+
|-------------|--------------|
42+
| platform | Platform |
43+
| work_item | Work Item |
44+
45+
46+
Once the command succeeds, read its output. Use the printed code as a template to write your logic.
47+
48+
If the command cannot be executed, stop and report the missing context. Do not invent APIs.
49+
50+
## Additional References
51+
52+
Read these only when the task requires them:
53+
54+
* **`TOOL_API_GUIDE.md`**
55+
Framework runtime references and context handling.
56+
57+
* **`RUNTIME_CUSTOM_GUIDE.md`**
58+
Runtime setup, debugging, and project-specific restrictions.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
**ATTENTION AI AGENTS:** Do not guess TeaQL API methods! To get the exact API usage and query examples for the entity you are working on, you must fetch the dynamically generated prompt directly from the code generation server. Use your tools to execute the following command to download the exact contextual prompt for the entity:
3+
4+
```bash
5+
cargo teaql --input models/runtime-example-conformance-service.xml java-assist-[action]/[entity-name]
6+
```
7+
8+
Replace `[entity-name]` with the exact entity-name of the entity.
9+
10+
**Available candidate entities in this model:**
11+
12+
| entity-name | display-name |
13+
|-------------|--------------|
14+
| platform | Platform |
15+
| work_item | Work Item |
16+
17+
18+
Replace `[action]` with one of the following depending on what you are trying to write:
19+
20+
| action | when-to-use |
21+
|--------|-------------|
22+
| query | You need to read/find records from the database using Q:: |
23+
| create | You need to insert a new record into the database |
24+
| update | You need to modify and save an existing record |
25+
| delete | You need to remove or soft-delete a record |
26+
| expression | You need to safely extract nested relation values (avoiding null panics) using the E:: facade |
27+
| list-page | You need to implement a paginated query returning a SmartList |
28+
29+
Once the command succeeds, read its output. Use the printed code as a template to write your logic.

‎examples/conformance/Makefile‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
# TEAQL WARNING: This project uses TeaQL. TeaQL was explicitly designed to PREVENT AI hallucinations and random guessing.
3+
# AI AGENTS MUST STRICTLY USE THESE MAKE TARGETS ONLY. Do NOT guess other build commands.
4+
5+
.PHONY: build test run clean help generate-lib
6+
7+
# Default target
8+
help:
9+
@echo "Available commands:"
10+
@echo " make generate-lib - Regenerate the TeaQL domain library"
11+
@echo " make build - Build the Spring Boot application (mvn clean package)"
12+
@echo " make test - Run application tests (mvn test)"
13+
@echo " make run - Run the application locally (mvn spring-boot:run)"
14+
@echo " make clean - Clean the project"
15+
16+
generate-lib:
17+
@echo "Regenerating TeaQL library..."
18+
./gen-lib.sh || echo "Please ensure gen-lib.sh exists or run teaql code generator manually"
19+
20+
build:
21+
mvn -f lib/pom.xml install -DskipTests
22+
mvn clean package -DskipTests
23+
24+
test:
25+
mvn -f lib/pom.xml install -DskipTests
26+
mvn test
27+
28+
run:
29+
mvn -f lib/pom.xml install -DskipTests
30+
mvn spring-boot:run
31+
32+
clean:
33+
mvn clean

‎examples/conformance/README.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Java minimum runtime conformance example
2+
3+
This retained SQLite workspace is generated from `model.xml`. It verifies
4+
explicit `ensureSchema`, Checker rejection before persistence, Create, typed Q
5+
and `SmartList`, E loaded/null/not-loaded semantics, Update/version, and Delete.
6+
7+
```bash
8+
make run
9+
```
10+
11+
The generated Runtime Module is installed at application startup but remains a
12+
passive manifest. Schema reconciliation is invoked separately and explicitly.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
# TeaQL Runtime Customization Guide
3+
4+
> [!WARNING]
5+
> **DO NOT GUESS RUNTIME CONFIGURATION**
6+
> Do not guess how to configure the runtime, connection pools, or schema generation.
7+
8+
To get the exact usage and examples for Customizing the Runtime (UserContext assembly, SQL debugging, Schema modes), you must fetch the dynamically generated prompt directly from the code generation server. Use your tools to execute the following command:
9+
10+
```bash
11+
cargo teaql --input models/runtime-example-conformance-service.xml java-assist-runtime-custom
12+
```
13+
14+
Once the command succeeds, read its output. Use the printed code as a template to write your logic.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
# TeaQL Tool & Runtime API Reference
3+
4+
> [!WARNING]
5+
> **DO NOT GUESS FRAMEWORK APIS**
6+
> Do not guess how to use `UserContext`, `SmartList`, `WebResponse`, or how to manage transactions.
7+
8+
> [!IMPORTANT]
9+
> **USE TEAQL'S OWN TOOLING FIRST**
10+
> Always use `cargo teaql` to retrieve assist content. Never bypass the CLI or invoke the generator endpoint directly.
11+
12+
To get the exact API usage and examples for Framework-level APIs (UserContext, SmartList, WebResponse, Entity Expression, Checkers, etc.), you must fetch the dynamically generated prompt directly from the code generation server. Use your tools to execute the following command:
13+
14+
```bash
15+
cargo teaql --input models/runtime-example-conformance-service.xml java-assist-tool-api
16+
```
17+
18+
Once the command succeeds, read its output. Use the printed code as a template to write your logic.
19+
20+
## Domain Object Assist APIs
21+
22+
If you need reference code or tool APIs specifically tailored for your domain objects (e.g., `user`, `order`), TeaQL provides code generators that yield perfect, ready-to-copy Java code snippets.
23+
24+
You can query these assist APIs for any object defined in your `models/runtime-example-conformance-service.xml`:
25+
26+
| Target | Description | Example Command |
27+
|--------|-------------|-----------------|
28+
| `java-assist-query/[object]` | How to query and filter `[object]` | `cargo teaql --input models/runtime-example-conformance-service.xml java-assist-query/school` |
29+
| `java-assist-create/[object]` | How to insert/create `[object]` | `cargo teaql --input models/runtime-example-conformance-service.xml java-assist-create/school` |
30+
| `java-assist-update/[object]` | How to update `[object]` | `cargo teaql --input models/runtime-example-conformance-service.xml java-assist-update/school` |
31+
| `java-assist-delete/[object]` | How to delete `[object]` | `cargo teaql --input models/runtime-example-conformance-service.xml java-assist-delete/school` |
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
2+
# TeaQL Java CRUD Guide
3+
4+
Generated for `com.teaql.runtimeexampleconformanceservice`. Use this guide when adding controllers, services, jobs, or integration code in this workspace.
5+
6+
## Setup
7+
8+
```java
9+
import com.teaql.runtimeexampleconformanceservice.Q;
10+
import com.teaql.runtimeexampleconformanceservice.RuntimeExampleConformanceServiceUserContext;
11+
import io.teaql.core.web.WebResponse;
12+
```
13+
14+
Most workspace code receives a TeaQL context from Spring:
15+
16+
```java
17+
public WebResponse handle(@TQLContext UserContext userContext) {
18+
// use Q, WebResponse, and entity.auditAs("comment").save(userContext)
19+
}
20+
```
21+
22+
## Non-Negotiable Database Rule
23+
24+
Never use SQL to operate on the database from workspace business code. This includes select, insert, update, delete, schema changes, JDBC templates, native queries, direct repositories, and ad hoc SQL helpers.
25+
26+
If the generated TeaQL API does not provide a path for the requested change, stop and report the missing API. Do not implement a SQL workaround.
27+
28+
## Mandatory Update Method Rule
29+
30+
Use generated `updateXxx(...)` methods for all entity field changes. Do not use `setXxx(...)` in new code. Setters are deprecated even when the IDE or generated class makes them visible.
31+
32+
```java
33+
entity.updateName("new value");
34+
```
35+
36+
Do not write:
37+
38+
```java
39+
entity.setName("new value");
40+
```
41+
42+
## Read One Entity
43+
44+
Prefer typed generated query entry points. Controller methods that return one object should wrap the result in `WebResponse.of(...)`:
45+
46+
```java
47+
public WebResponse getOne(@TQLContext UserContext userContext, Long id) {
48+
try {
49+
var entity = Q.platforms()
50+
.filterById(id)
51+
.selectSelf()
52+
.comment("load detail by id")
53+
.purpose("get task detail")
54+
.executeForOne(userContext);
55+
return WebResponse.of(entity);
56+
} catch (Exception e) {
57+
return WebResponse.fail(e.getMessage());
58+
}
59+
}
60+
```
61+
62+
## Read A Page
63+
64+
Controller methods that return multiple objects should wrap the list in `WebResponse.of(...)`:
65+
66+
```java
67+
public WebResponse list(@TQLContext UserContext userContext) {
68+
try {
69+
var list = Q.platforms()
70+
.selectSelf()
71+
.page(1, 20)
72+
.comment("list tasks")
73+
.purpose("render dashboard list")
74+
.executeForList(userContext);
75+
return WebResponse.of(list);
76+
} catch (Exception e) {
77+
return WebResponse.fail(e.getMessage());
78+
}
79+
}
80+
```
81+
82+
## Create
83+
84+
```java
85+
var entity = new Platform();
86+
// Fill fields with generated updateXxx(...) methods, not setXxx(...).
87+
entity.auditAs("Create new item").save(userContext);
88+
```
89+
90+
## Update
91+
92+
```java
93+
var entity = Q.platforms()
94+
.filterById(id)
95+
.selectSelf()
96+
.comment("load for update")
97+
.purpose("edit entity")
98+
.executeForOne(userContext);
99+
100+
// Use updateXxx(...) methods for state changes.
101+
// entity.updateName("new value");
102+
entity.auditAs("Update entity properties").save(userContext);
103+
```
104+
105+
## Load Relations
106+
107+
Use generated selectors. Do not write a loop that queries children one row at a time. The examples below focus on the entities with the highest reverse relation counts because they are stronger aggregate-root candidates.
108+
109+
```java
110+
var list = Q.platforms()
111+
.selectWorkItemListWith(Q.workItems().selectSelf())
112+
.comment("load with workItemList")
113+
.purpose("fetch child workItemList")
114+
.executeForList(userContext);
115+
```
116+
117+
118+
## Delete
119+
120+
Use the generated TeaQL soft-delete API available on the entity/request class in this domain. If unsure, inspect the generated request class for the target entity and use the soft-delete operation it exposes.
121+
122+
Do not hard-delete rows. Do not write SQL `DELETE` or `UPDATE` statements. If the soft-delete API is not visible, stop and report that blocker instead of changing data through SQL.
123+
124+
## Common Mistakes
125+
126+
- Do not instantiate repositories directly in workspace business code.
127+
- Do not use SQL for any database operation.
128+
- Do not use deprecated `setXxx(...)` methods for updates. Use `updateXxx(...)`.
129+
- Do not return raw entities or lists from controller query methods. Return `WebResponse.of(entity)` or `WebResponse.of(list)`.
130+
- Do not forget `.executeForOne(userContext)` or `.executeForList(userContext)`.
131+
- Do not forget `.comment("...")` and `.purpose("...")` on queries.
132+
- Do not forget `.auditAs("...")` before calling `.save(context)` on entities.
133+
- Do not assume relations are loaded unless the query selected them.
134+
- Do not bypass `UserContext`; context carries logging, tenant, security, and repository resolution behavior.
135+
136+
## Entity Cheat Sheet
137+
138+
These entities are selected by reverse relation count, not by model declaration order.
139+
140+
- `Platform`: reverse relations `1`, query `Q.platforms()`, save `new Platform().auditAs("comment").save(userContext)`, request `com.teaql.runtimeexampleconformanceservice.platform.PlatformRequest`

0 commit comments

Comments
 (0)