-
-
Notifications
You must be signed in to change notification settings - Fork 98
Support interface entity types with EntityDecorator #1183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. Comment |
- Modified Reflector to detect and handle interface properties via getter methods - Created InterfacePropertyHolder to store metadata for synthetic fields - Updated EntityDecoratorScanner and AnnotationScanner to use property metadata - Fixed Android compatibility by using getParameterTypes().length instead of getParameterCount() - Added test case for interface entity support Co-authored-by: anidotnet <[email protected]>
- Created FieldAccessHelper to handle get/set operations on both regular and interface property fields - Modified RepositoryOperations to use FieldAccessHelper for field access - This fixes field access issues when using EntityDecorator with interface types - All existing tests still pass (1623 tests) Co-authored-by: anidotnet <[email protected]>
- Added null/empty checks for propertyName to prevent StringIndexOutOfBoundsException - Added support for 'is' prefix in getter method lookup for boolean properties - Extracted capitalizePropertyName helper method to eliminate code duplication - Created findGetterMethod to handle both 'get' and 'is' prefixed getters - All tests still pass (1623 tests) Co-authored-by: anidotnet <[email protected]>
nitrite/src/test/java/org/dizitart/no2/repository/InterfaceEntityTest.java
Show resolved
Hide resolved
nitrite/src/main/java/org/dizitart/no2/repository/FieldAccessHelper.java
Show resolved
Hide resolved
nitrite/src/main/java/org/dizitart/no2/repository/FieldAccessHelper.java
Outdated
Show resolved
Hide resolved
nitrite/src/main/java/org/dizitart/no2/repository/FieldAccessHelper.java
Outdated
Show resolved
Hide resolved
nitrite/src/main/java/org/dizitart/no2/repository/FieldAccessHelper.java
Show resolved
Hide resolved
nitrite/src/main/java/org/dizitart/no2/repository/FieldAccessHelper.java
Outdated
Show resolved
Hide resolved
nitrite/src/main/java/org/dizitart/no2/repository/FieldAccessHelper.java
Outdated
Show resolved
Hide resolved
nitrite/src/main/java/org/dizitart/no2/repository/FieldAccessHelper.java
Outdated
Show resolved
Hide resolved
- Reduced complexity of isCompatiblePrimitive method by using single return statement - Refactored setAccessible usage to check isAccessible first before calling setAccessible - Added comprehensive tests with multiple concrete implementations (Dog, Cat, Bird) - Added edge case tests for null/empty property names - Added test for boolean properties with 'is' prefix - Added test verifying multiple classes work with same interface - All 1628 tests pass Co-authored-by: anidotnet <[email protected]>
- Upgraded Android API level from 24 (Android 7.0) to 30 (Android 11) - Replaced setAccessible usage with MethodHandles API for improved security - Uses unreflectGetter/unreflectSetter/unreflect with invokeWithArguments (Android API 26+) - Updated documentation (README.md, copilot-instructions.md) to reflect API 30 - Updated pom.xml with correct Android API 30 signature (11_r3) - All 1628 tests pass with Android API 30 compatibility Co-authored-by: anidotnet <[email protected]>
Lowered the minimum supported Android API level from 30 to 26 in documentation and build configuration. Updated references and dependencies to reflect the new minimum API level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for interface entity types in Nitrite repositories by enhancing the reflection infrastructure to handle interface properties defined as getter methods. Previously, using interface types with EntityDecorator failed because Reflector.getField() only looked for declared fields, which don't exist on interfaces. The solution creates synthetic field representations for interface properties and uses MethodHandles for secure field access.
Key changes:
- Enhanced reflection to detect and handle interface properties via getter methods
- Upgraded Android API compatibility from 24 to 26 to support MethodHandles
- Added comprehensive test coverage for interface entity support
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| pom.xml | Updated Android API level from 24 to 26 for MethodHandles support |
| InterfaceEntityTest.java | Added comprehensive tests for interface entity support with multiple implementations |
| RepositoryOperations.java | Updated to use FieldAccessHelper and InterfacePropertyHolder for field access |
| Reflector.java | Enhanced to detect interface properties from getter methods and create synthetic fields |
| InterfacePropertyHolder.java | New class storing metadata mapping between synthetic fields and interface properties |
| FieldAccessHelper.java | New helper class handling field access using MethodHandles API for security |
| EntityDecoratorScanner.java | Updated validators to use property metadata for correct type/name information |
| AnnotationScanner.java | Updated validators to use property metadata for correct type/name information |
| README.md | Updated Android API compatibility documentation from 24 to 26 |
| .github/copilot-instructions.md | Updated Android API compatibility documentation from 24 to 26 |
nitrite/src/main/java/org/dizitart/no2/repository/FieldAccessHelper.java
Show resolved
Hide resolved
nitrite/src/main/java/org/dizitart/no2/repository/FieldAccessHelper.java
Show resolved
Hide resolved
nitrite/src/main/java/org/dizitart/no2/repository/Reflector.java
Outdated
Show resolved
Hide resolved
nitrite/src/main/java/org/dizitart/no2/repository/Reflector.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Added comments to explain that setAccessible is still required to bypass access checks when using MethodHandles for field access, providing more context on the security and compatibility considerations.
…com:dizitart/nitrite-database into copilot/migrate-mongo-repository-to-nitrite
Deleted the unused 'idField' variable from the testEdgeCaseEmptyPropertyName method in InterfaceEntityTest to clean up the code.
Implementation: Interface Entity Support in Repositories ✅
Problem: Nitrite could not use interface types as entity types in repositories because the
Reflector.getField()method only looked for declared fields, which don't exist on interfaces.Solution: Enhanced the reflection infrastructure to detect and handle interface properties defined as getter methods.
Changes Made:
Reflectorclass to understand all usagesReflector.getField()to support interface properties via getter methodsReflector.getEmbeddedField()to support interface propertiesReflector.getAllFields()to support interface propertiesInterfacePropertyHolderhelper class to store synthetic field metadataFieldAccessHelperto handle get/set on interface property fieldsEntityDecoratorScannerto use property metadata for validationAnnotationScannerto use property metadata for validationRepositoryOperationsto use FieldAccessHelper for field accessTechnical Implementation:
Reflectorto detect getter methods on interfaces and create synthetic Field representationsInterfacePropertyHolderto store mapping between synthetic fields and actual property informationFieldAccessHelperthat uses MethodHandles API for secure field/method accessAndroid API Upgrade:
Code Quality Improvements:
isCompatiblePrimitiveusing single return statement (reduced NPath complexity from 256 to acceptable levels)unreflectGetter,unreflectSetter, andunreflectwithinvokeWithArgumentsTest Coverage:
Documentation Updates:
<issue_title>Migration from Mongo: repositories of interface entities</issue_title>
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.