feat: [GH-139] Add findFirst and findFirstAny ordered single-match reads#141
Open
javierlores wants to merge 2 commits into
Open
feat: [GH-139] Add findFirst and findFirstAny ordered single-match reads#141javierlores wants to merge 2 commits into
javierlores wants to merge 2 commits into
Conversation
Add findFirst and its hierarchy-inclusive sibling findFirstAny to the read API as default methods on DatabaseInterface. Each returns the first Record matching a Criteria under a caller-supplied Order, or null when nothing matches, by pushing the Order plus a one-row page to the server so a single sorted row comes back rather than the full match set. - Four overloads each (core, +realms, +filter, +filter+realms), built inline from the Selection fluent API and routed through fetch(Selection), matching the surrounding find/findAny family. - null-on-no-match (consistent with findUnique/load); no duplicate detection, so strictly cheaper than findUnique and never throws DuplicateEntryException when more than one record matches. - Order is required. The filtered overloads apply the one-row limit after the client-side predicate (via the existing filter-plus-page path) so a rejected head row does not mask a later matching+passing record. - No-filter overloads omit .filter() to preserve the native order+limit-1 pushdown on capable servers; legacy servers fall back to the existing client-side sort/skip path. Foundation for the findFirstAndEdit family (GH-140), the atomic claim-and-update used by the cinchapi-server connector data-sync lock loop. Tests: parameterized FindFirstTest (bulkCommands matrix) covering ascending/descending first, null-on-no-match, sole match, no-throw-on-multiple, findFirstAny-includes-descendants, realms scoping, the filter-skips-head-row caveat, and the connector stale-lock claim. Tests written but not run (suite requires a live server).
3 tasks
- Add multi-page filter-ordering test exercising applyFilterAndPage's page-widening loop across page boundaries - Correct test-class Javadoc to describe the bulk vs incremental command-read paths (not the sorting/pagination branch) - Clarify rankPositive() helper Javadoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #139.
What
Adds
findFirstand its hierarchy-inclusive siblingfindFirstAnyasdefaultmethods onDatabaseInterface. Each returns the single firstRecordmatching aCriteriaunder a caller-suppliedOrder, ornullwhen nothing matches — pushing theOrderplus a one-rowPageto the server so a single sorted row comes back rather than the full match set.Surface — 8 default methods
Four overloads each (core,
+realms,+filter,+filter+realms), for bothfindFirstandfindFirstAny, built inline from theSelectionfluent API and routed throughfetch(Selection)— matching the surroundingfind/findAnyfamily.Contract
nullon no match (consistent withfindUnique/load); never an empty collection.findUnique(requests 1 row, not 2) and never throwsDuplicateEntryExceptionwhen more than one record matches.Orderis required — "first" is meaningless without it..filter()to preserve the native order+limit-1 pushdown.Tests
Parameterized
FindFirstTestover thebulkCommands={true,false}matrix (mirrorsPreventStaleWriteTest), four-section Javadoc on every@Test: ascending/descending first, null-on-no-match, sole match, no-throw-on-multiple (thefindUniquecontrast),findFirstAnyincludes descendants whilefindFirstexcludes them, realms scoping, the filter-skips-head-row caveat, and the connector stale-lock claim.Per repo policy, tests are written but not run (the suite needs a live Concourse server). Locally verified:
spotlessApplyclean andcompileJava/compileTestJavasucceed (no fabricated APIs).Notes
find/findAny/findUniquemethods and avoiding an uncheckedNO_FILTERcast. Behavior and API are identical.Scope / follow-ups
String-condition overload, order-less convenience overload, and the atomic claim-and-update.findFirstAndEdit) builds on for the atomic claim-and-update used by the cinchapi-server connector data-sync lock loop.Part of the connector data-sync locking initiative.