Conversation
…leanup This PR implements Phase 16c of the UsagePoint schema compliance work, cleaning up the repository to remove non-indexed queries and convert to Spring Data JPA derived query methods for optimal performance. ## Changes in Phase 16c ### Repository Query Optimization Removed methods that query non-indexed columns or perform full table scans: - **Removed `findByResourceUri(String uri)`** - Queries `uri` field which is NOT indexed and is a legacy field NOT in ESPI 4.0 XSD - **Removed `findAllIds()`** - Full table scan without WHERE clause (performance risk) - **Removed `existsByUuid(UUID uuid)`** - Use built-in `existsById(UUID id)` instead - **Removed `deleteByUuid(UUID uuid)`** - Use built-in `deleteById(UUID id)` instead ### Spring Data JPA Derived Queries Converted `@Query` annotations to Spring Data JPA derived query methods: - **`findAllByRetailCustomerId(Long retailCustomerId)`** - Uses indexed `retail_customer_id` - **`findAllByUpdatedAfter(LocalDateTime lastUpdate)`** - Uses indexed `updated` column ### Retained Methods (All Use Indexed Columns) - `findByRelatedHref(String href)` - Uses indexed relationship table - `findAllByRetailCustomerId(Long retailCustomerId)` - Uses indexed `retail_customer_id` - `findAllByUpdatedAfter(LocalDateTime lastUpdate)` - Uses indexed `updated` - `findAllIdsByRetailCustomerId(Long retailCustomerId)` - Uses indexed `retail_customer_id` ### Database Index Analysis Current indexed columns on `usage_points` table: - `kind` - Indexed but NOT in ESPI 4.0 XSD (legacy field, no queries use it) - `status` - Indexed (no queries currently use it) - `retail_customer_id` - Indexed ✅ USED by queries - `service_delivery_point_id` - Indexed (no queries currently use it) - `local_time_parameters_id` - Indexed (no queries currently use it) - `created` - Indexed (no queries currently use it) - `updated` - Indexed ✅ USED by queries ### Test Updates - Removed 4 test methods for deleted repository methods: - `shouldFindUsagePointByResourceUri()` - `shouldFindAllUsagePointIds()` - `shouldCheckIfUsagePointExistsByUuid()` - `shouldDeleteUsagePointByUuid()` - Updated `shouldHandleEmptyResultsGracefully()` to test only retained methods - Updated method call from `findAllUpdatedAfter()` to `findAllByUpdatedAfter()` ## Technical Details ### Performance Benefits All remaining queries use indexed columns: - Eliminates full table scans (removed `findAllIds`) - Uses database indexes for O(log n) lookups instead of O(n) scans - Removes queries on non-indexed legacy field (`uri`) ### Spring Data JPA Patterns - Derived query methods (e.g., `findAllByRetailCustomerId`) are automatically implemented by Spring Data JPA at runtime - Reduces custom JPQL code and improves maintainability - Type-safe method names reduce query errors ### Legacy Field Review **`kind` field** (NOT in ESPI 4.0 XSD): - Has database index but is NOT used by any queries - Field exists in entity but not in XSD specification - No repository methods query this field - Consider for removal in future phase **`uri` field** (NOT in ESPI 4.0 XSD): - Legacy field documented in Phase 16b - No longer queryable (removed `findByResourceUri`) - Consider for removal in future phase ## Test Results ``` Tests run: 580, Failures: 0, Errors: 0, Skipped: 0 BUILD SUCCESS ``` *Note: Was 584 tests, now 580 (removed 4 tests for deleted methods)* ## Related - Issue #28 - Phase 16: UsagePoint - PR #83 - Phase 16a: Add Missing Boolean/String Fields (merged) - PR #84 - Phase 16b: Add Enum Fields & Reorder (merged) - Part 3 of 5 sub-phases for complete UsagePoint compliance ## Next Steps (Phase 16d) - Mapper bidirectional updates - Update Entity-to-DTO mappings - Update DTO-to-Entity mappings - Handle all embedded SummaryMeasurement mappings Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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.
Summary
This PR implements Phase 16c of the UsagePoint schema compliance work, cleaning up the repository to remove non-indexed queries and convert to Spring Data JPA derived query methods for optimal performance.
Phase 16 Strategy
Phase 16 (UsagePoint) is being split into sub-phases:
Changes in Phase 16c
🗑️ Removed Methods (Non-Indexed or Redundant)
findByResourceUri(String uri)urifield which is NOT indexed AND is a legacy field NOT in ESPI 4.0 XSDfindAllIds()existsByUuid(UUID uuid)existsById(UUID id)insteaddeleteByUuid(UUID uuid)deleteById(UUID id)instead✅ Retained Methods (All Use Indexed Columns)
findAllByRetailCustomerId(Long)retail_customer_idfindAllByUpdatedAfter(LocalDateTime)updatedfindByRelatedHref(String)usage_point_related_links(usage_point_id)findAllIdsByRetailCustomerId(Long)retail_customer_id📊 Database Index Analysis
Current indexed columns on
usage_pointstable:kindstatusretail_customer_idservice_delivery_point_idlocal_time_parameters_idcreatedupdatedKey Findings:
kindfield: Indexed but NOT in ESPI 4.0 XSD (legacy field, no queries use it)urifield: Not indexed, NOT in ESPI 4.0 XSD (legacy field, removed from queries)🧪 Test Updates
Removed 4 test methods for deleted repository methods:
shouldFindUsagePointByResourceUri()shouldFindAllUsagePointIds()shouldCheckIfUsagePointExistsByUuid()shouldDeleteUsagePointByUuid()Updated tests:
shouldHandleEmptyResultsGracefully()- Removed references to deleted methodsshouldFindAllUsagePointsUpdatedAfterTimestamp()- Updated method call tofindAllByUpdatedAfter()Technical Details
Performance Benefits
findAllIds)uri)Spring Data JPA Patterns
findAllByRetailCustomerId) are automatically implemented by Spring Data JPA at runtimefindAllByRetailCustomerId→ Spring generatesSELECT ... WHERE retail_customer_id = ?Repository Documentation
Added comprehensive JavaDoc to repository interface explaining:
Test Results
Note: Was 584 tests, now 580 (removed 4 tests for deleted methods)
Migration Impact
The following public repository methods have been removed:
findByResourceUri(String uri)- Use alternative approach or migrate away from legacyurifieldfindAllIds()- UsefindAll()and extract IDs, orfindAllIdsByRetailCustomerId()for filtered IDsexistsByUuid(UUID uuid)- Use built-inexistsById(UUID id)insteaddeleteByUuid(UUID uuid)- Use built-indeleteById(UUID id)instead✅ No Service Layer Changes Required
Checked all usages in service layer:
UsagePointServiceImplusesfindAllIdsByRetailCustomerId()- Still available ✅Related
Next Steps (Phase 16d)
🤖 Generated with Claude Code