Skip to content

Replace and remove legacy SimpleQuery with repository-backed query resolution #33

Description

@eviltester

Summary

SimpleQuery is now a deprecated legacy ERInstanceData-backed query engine. It should be replaced by repository-backed query resolution and eventually removed once runtime API paths, compatibility paths, and tests have migrated.

The core problem is that SimpleQuery traverses ERInstanceData and EntityInstanceCollection directly. For SQLite-backed repositories, that can force compatibility snapshot hydration and defeat the memory-efficiency benefits of using SQLite.

Current State

  • SimpleQuery lives in ercoremodel under core/query.
  • It depends on ERInstanceData and collection traversal.
  • It is still used by Thingifier REST handlers for some fallback and relationship write paths.
  • It is heavily used by legacy ER-core query/filter tests.
  • RepositoryBackedSimpleQuery now handles common repository-backed read paths, including simple entity GETs and common relationship GET traversal.
  • SimpleQuery should remain available temporarily for compatibility and tests, but new runtime paths should not be added to it.

Why Replace It

SimpleQuery predates the formal repository abstraction. It assumes the live in-memory model is the source of truth. That assumption is no longer valid for SQLite-backed repositories, where the database should be the source of truth and rows should be materialized only when needed.

Leaving SimpleQuery in runtime paths creates risks:

  • unintentional SQLite compatibility snapshot hydration;
  • large datasets being loaded into memory;
  • inconsistent behavior between in-memory and SQLite repositories;
  • relationship writes using legacy path resolution before repository operations;
  • harder migration to file-backed durable databases.

Proposed Plan

  1. Inventory all usages
  • Classify each SimpleQuery usage as:
    • runtime GET path;
    • runtime POST/DELETE relationship write path;
    • admin/export/debug compatibility path;
    • test-only coverage;
    • legacy query engine behavior test.
  • Record the classification in the repository migration audit notes.
  1. Define repository-backed query/resolution replacements
  • Keep or extend RepositoryBackedSimpleQuery for read-only query paths.
  • Add a repository-backed relationship write resolver for paths such as:
    • POST /project/{id}/tasks;
    • POST /todo/{id}/task-of;
    • DELETE /project/{id}/tasks/{taskId};
    • DELETE /todo/{id}/task-of/{projectId}.
  • The resolver should return structured results, not rely on ERInstanceData traversal.
  • The resolver should identify:
    • parent entity definition;
    • parent instance;
    • relationship name/vector;
    • optional child entity definition;
    • optional child instance;
    • intended operation shape.
  1. Move Thingifier runtime handlers off SimpleQuery
  • Update GET fallback paths where possible to use repository-backed resolution.
  • Update relationship POST creation to resolve parent/relationship/child via repository APIs.
  • Update relationship DELETE to resolve parent/relationship/child via repository APIs.
  • Preserve current response status codes and response bodies for existing Todo Manager behavior.
  • Keep fallback only for explicitly documented compatibility paths.
  1. Migrate tests
  • Add repository-backed equivalents for legacy query tests where behavior is still desired.
  • Keep a small set of SimpleQuery tests while it remains available, but mark them legacy/compatibility tests.
  • Add SQLite-specific tests proving relationship write path resolution does not hydrate compatibility snapshots.
  1. Deprecation and removal path
  • Keep SimpleQuery annotated as deprecated while callers migrate.
  • Add no new runtime usages of SimpleQuery.
  • Once runtime paths are migrated, restrict SimpleQuery to tests/compatibility only.
  • Remove SimpleQuery in a later breaking cleanup if no public compatibility requirement remains.

Acceptance Criteria

  • No normal Thingifier API runtime path uses SimpleQuery for repository-backed apps.
  • Relationship GET, POST, and DELETE route resolution work through repository-backed resolvers.
  • SQLite relationship write paths do not hydrate the compatibility ERInstanceData snapshot just to resolve URLs.
  • Current Todo Manager relationship behavior remains source-compatible and response-compatible.
  • In-memory repository behavior remains compatible.
  • Legacy SimpleQuery tests are either migrated to repository-backed tests or clearly marked as legacy compatibility coverage.
  • Repository migration audit notes identify any remaining SimpleQuery usage and why it remains.
  • Targeted tests pass for in-memory and SQLite repository modes.

Suggested Verification

mvn -pl ercoremodel,thingifier -am "-Dtest=TodoManagerQueryEngineTest,ThingRepositoryContractTest,RelationshipApiNonHttpTest,RelationshipApiSqliteRepositoryTest" -DfailIfNoTests=false test
mvn -pl standAloneTodoListManagerRestApiAuto -am test
mvn -pl standAloneTodoListManagerRestApiAuto -am "-Dstandalone.todo.manager.app=sqlite-memory" test

Non-Goals

  • Removing Java-side validation.
  • Removing compatibility snapshot/export APIs.
  • Rewriting the entire query system as a general-purpose query language in one step.
  • Changing Challenger-specific paths in the first replacement slice.
  • Removing SimpleQuery before all runtime behavior has a repository-backed replacement.

Notes

This issue is the explicit follow-up to the repository-backed SQLite migration. SimpleQuery can remain as a legacy compatibility class during migration, but it should not be the path normal repository-backed runtime behavior depends on.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions