Commit 948ed09
feat: ESPI 4.0 Schema Compliance - Phase 16c: UsagePoint Repository Cleanup (#85)
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 <[email protected]>1 parent 0b91686 commit 948ed09
File tree
2 files changed
+35
-104
lines changed- openespi-common/src
- main/java/org/greenbuttonalliance/espi/common/repositories/usage
- test/java/org/greenbuttonalliance/espi/common/repositories/usage
2 files changed
+35
-104
lines changedLines changed: 28 additions & 29 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
38 | 45 | | |
39 | 46 | | |
40 | 47 | | |
41 | 48 | | |
42 | 49 | | |
43 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
44 | 56 | | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
| 57 | + | |
53 | 58 | | |
54 | 59 | | |
55 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
56 | 65 | | |
57 | 66 | | |
58 | 67 | | |
59 | 68 | | |
60 | 69 | | |
61 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
62 | 75 | | |
63 | | - | |
64 | | - | |
| 76 | + | |
65 | 77 | | |
66 | 78 | | |
67 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
68 | 84 | | |
69 | 85 | | |
70 | 86 | | |
71 | 87 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
| 88 | + | |
| 89 | + | |
91 | 90 | | |
Lines changed: 7 additions & 75 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
| 290 | + | |
308 | 291 | | |
309 | 292 | | |
310 | 293 | | |
| |||
355 | 338 | | |
356 | 339 | | |
357 | 340 | | |
358 | | - | |
| 341 | + | |
359 | 342 | | |
360 | 343 | | |
361 | 344 | | |
| |||
386 | 369 | | |
387 | 370 | | |
388 | 371 | | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
443 | 375 | | |
444 | 376 | | |
445 | 377 | | |
446 | 378 | | |
447 | | - | |
| 379 | + | |
448 | 380 | | |
449 | | - | |
450 | 381 | | |
451 | 382 | | |
| 383 | + | |
452 | 384 | | |
453 | 385 | | |
454 | 386 | | |
| |||
0 commit comments