mybatis-3 icon indicating copy to clipboard operation
mybatis-3 copied to clipboard

101: Add support for immutable collection constructor creation

Open epochcoder opened this issue 11 months ago • 24 comments

#101 Add support for constructor collection injection

It is now possible to create completely immutable objects (including nested collections) with MyBatis.

This has been done by keeping another meta object in memory until it is ready for creation, the detection for this is based on CacheKey.

This functionality is fully hidden behind a configuration flag called experimentalConstructorCollectionMapping, the idea is that MyBatis will have exactly the same (current) behaviour when this flag is not set (default false) and the community can enable this to test different use cases and report possible issues.

This would allow us to integrate this behaviour while gathering community feedback while not affecting any current workloads.

New functionality is tested in src/test/java/org/apache/ibatis/immutable/ImmutableConstructorTest.java.

I added debug symbols as an additional patch which really helps understanding what is happening.

~~What still needs needs to be done~~

  • [x] Documentation
  • [x] Testing with more than two levels of nesting (currently Blog -> Post > [Comment + Tag])
    • See ImmutableCollectionConstructorTest.java - House -> Room -> Furniture -> Defect
  • [x] Testing result ordering
    • We cannot reliably determine when to build the final object if the results are not ordered, so we require this attribute
  • [x] Testing with multiple result sets (throwing exception now)
    • Descoping this for now. could create follow up.
  • [x] Testing with mixed mappings (including nestedQuery)
    • See postForConstructorInit in BoundBlogMapper.xml
  • [x] Testing with very large resultSets (performance)

epochcoder avatar Mar 08 '24 12:03 epochcoder