Skip to content

[Refactor] Architecture, contracts and ergonomics audit (Part 2: Query API & Repository) (#643) - #646

Merged
remiceres merged 2 commits into
feature/corese-nextfrom
refactor/643-query-architecture-audit
Oct 23, 2026
Merged

remiceres merged 2 commits into
feature/corese-nextfrom
refactor/643-query-architecture-audit

Conversation

@remiceres

Copy link
Copy Markdown
Contributor

Summary

This PR addresses Part 2 of the architecture, Single Responsibility Principle (SRP), and contracts audit on core.next (#643), focusing on the query module, repository ergonomics, and execution contracts.

Key Changes

1. Repository Ergonomics & Shortcuts (Repository.java, Repositories.java)

  • Semantic Alias: Added construct(String sparqlConstruct) as a direct alias for graph(sparqlConstruct) aligning with standard SPARQL 1.1 terminology.
  • Functional Projection: Added mapped query shortcut select(String, Function<BindingSet, T>) to map solutions to objects/strings directly without managing manual cursor loops.
  • Direct Statement Operations: Added size(Resource...), hasStatement(Resource, IRI, Value, Resource...), and add(Statement...) on Repository with automatic connection lifecycle management.
  • Factory Convenience: Added Repositories.createFrom(Path) and Repositories.createFrom(InputStream, RDFFormat) for quick testing and loading.
  • Scoped Execution: Added Repositories.withMemory(Consumer) and Repositories.computeWithMemory(Function) guaranteeing deterministic repository closure.

2. Dataset Factory & Builder Enhancements (Dataset.java)

  • Added static factory Dataset.of(IRI... defaultGraphs).
  • Added collection-based builder methods defaultGraphs(Collection<IRI>) and namedGraphs(Collection<IRI>).
  • Formally documented dataset override semantics: contrast between Dataset.empty() (empty override) and passing null (resetting to query text clauses).

3. Materialized Result Integrity & Thread Safety (MaterializedResults.java)

  • Guaranteed deterministic projection order: replaced Map.copyOf with Collections.unmodifiableMap(new LinkedHashMap<>(values)) in ImmutableBindingSet.
  • Enforced cross-thread close visibility: declared volatile boolean closed in TupleResult and GraphResult.

4. Stream & Concurrency Lifecycle Documentation

  • Formalized stream() lifecycle in TupleQueryResult: explicit documentation that closing the stream triggers close(), while terminal stream operations do not auto-close.
  • Substantially enhanced package documentation across query, query.api, query.api.repository, query.api.result, and query.api.dataset.

Verification & Quality

  • 100% passing tests across core.next.query.* and NextModuleBoundaryTest.
  • 0 SonarLint issues across all scanned files.
  • 100% backwards-compatible (purely additive shortcuts, no breaking changes).

Part of #643

… contract javadoc (#643)

- Add Repository shortcuts: construct() alias, mapped select(), size(), hasStatement(), and add()
- Add Repositories convenience factories: createFrom(Path/Stream) and withMemory/computeWithMemory
- Add Dataset.of(IRI...) and collection-based builder methods
- Guarantee binding variable projection order in MaterializedResults
- Formalize stream lifecycle, thread confinement, and dataset override contracts in Javadoc
- Add comprehensive test coverage in RepositoriesTest, DatasetTest, and CoreseRepositoryTest
@github-actions

Copy link
Copy Markdown
Overall Project 57.97% -0.01% 🍏
Files changed 86.81% 🍏

File Coverage
TupleQueryResult.java 100% 🍏
Repository.java 89.24% 🍏
MaterializedResults.java 80.23% 🍏
Dataset.java 78.38% 🍏
Repositories.java 71.82% -28.18% ❌

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Test Results

  418 files    418 suites   35s ⏱️
3 380 tests 3 380 ✅ 0 💤 0 ❌
3 414 runs  3 414 ✅ 0 💤 0 ❌

Results for commit b31de15.

♻️ This comment has been updated with latest results.

- Enforce batch atomicity in Repository.add(Statement...) via conn.add(Iterable)
- Use Collections.unmodifiableList in Repository.select mapper and document eager projection
- Adopt Collection<? extends IRI> (PECS) in Dataset.Builder
- Deduplicate createAndLoad in Repositories
- Enforce deterministic variable projection ordering across all tuple results and binding sets
- Add regression assertions in RepositoriesTest, DatasetTest, and CoreseRepositoryTest
@github-actions

Copy link
Copy Markdown
Overall Project 57.98% -0.01% 🍏
Files changed 92% 🍏

File Coverage
TupleQueryResult.java 100% 🍏
CoreseBindingSet.java 95.77% 🍏
StreamingTupleQueryResult.java 95.65% 🍏
CoreseTupleQueryResult.java 92.42% 🍏
Repository.java 88.56% 🍏
MaterializedResults.java 80.87% 🍏
Repositories.java 80% -20% 🍏
Dataset.java 78.38% 🍏

@remiceres
remiceres merged commit c99e7de into feature/corese-next Oct 23, 2026
2 checks passed
@remiceres
remiceres deleted the refactor/643-query-architecture-audit branch October 23, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant