-
Notifications
You must be signed in to change notification settings - Fork 16
SpecialCompatibility
GangCheng edited this page Sep 28, 2024
·
5 revisions
- When using
useGeneratedKeys="true"
ininsert
label of mapper-xml, thekeyColumns="xxxx"
must be set. - The
JDBC driver
'sConnection
only provides a method defined asPreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException;
, the second parameter of this method indicates whether auto returns generatedKeys - The
R2DBC driver
'sStatement
does not provide any method to return generatedKeys automatically, the Statement only provides a method defined asStatement returnGeneratedValues(String... columns)
to return generatedKeys, the columns is not nullable , so the key column name must be configured. - Reference:
- Related Mapper XML
- Since r2dbc only return single
Result
(ResultSet
in JDBC) each segment, so I change theresultOrdered
process for hold result data for nested result mapping in order to reduce the cache generated when nested-result-map processing as much as possible - When using
resultOrdered="true"
inselect
label of mapper-xml, theDefaultReactiveResultHandler
only hold the related result data for nested result mapping. - When using
resultOrdered="false"
inselect
label of mapper-xml (by default), theDefaultReactiveResultHandler
hold all related result data for nested result mapping. resultOrdered="false"
Related TestresultOrdered="true"
Related Test
-
To implement transaction operations:
- When using
mybatis-r2dbc
withoutSpringFramework
- the configuration of
R2dbcConfiguration
-->R2dbcEnvironment
-->usingDefaultTransactionProxy
must be true.
R2dbcEnvironment r2dbcEnvironment = new R2dbcEnvironment.Builder("ENV-NAME") .withDefaultTransactionProxy(true) // this should be true .connectionFactory(connectionFactory) .build(); r2dbcMybatisConfiguration.setR2dbcEnvironment(r2dbcEnvironment);
- the configuration of
- When using
mybatis-r2dbc
withSpringFramework
- the transaction operation should be controlled by Spring's
R2dbcTransactionManager
- the transaction operation should be controlled by Spring's
- When using
-
Manual transaction operation:
- To using transaction , the execution should work with ReactiveSqlSessionOperator
ReactiveSqlSessionOperator reactiveSqlSessionOperator = new DefaultReactiveSqlSessionOperator( reactiveSqlSessionFactory ); // execute with specific ReactiveSqlSessionProfile to specify isolation level reactiveSqlSessionOperator.executeThenClose(ReactiveSqlSessionProfile.of(IsolationLevel.READ_UNCOMMITTED), (session, profile) -> { DeleteMapper deleteMapper = session.getMapper(DeleteMapper.class); // profile.forceToRollback(); // if execution required a rollback return deleteMapper.deleteByDeptNo(4L); } ); // execute mono with default profile reactiveSqlSessionOperator.executeMonoThenClose( (session, profile) -> { DeleteMapper deleteMapper = session.getMapper(DeleteMapper.class); // profile.forceToRollback(); // if execution required a rollback return deleteMapper.deleteByDeptNo(4L); } ); // execute flux with default profile reactiveSqlSessionOperator.executeManyAndCommit( (session, profile) -> { DeleteMapper deleteMapper = session.getMapper(DeleteMapper.class); // profile.forceToRollback(); // if execution required a rollback return deleteMapper.deleteByDeptNo(4L); } );
- If the execution runs with given ReactiveSqlSession, you should use
ReactiveSqlSessionOperator
's static method like below:
ReactiveSqlSession reactiveSqlSession = reactiveSqlSessionFactory.openSession(ReactiveSqlSessionProfile.of(IsolationLevel.READ_UNCOMMITTED)); ReactiveSqlSessionOperator.executeMonoThenClose(reactiveSqlSession, (session, profile) -> { DeleteMapper deleteMapper = session.getMapper(DeleteMapper.class); // profile.forceToRollback(); // if execution required a rollback return deleteMapper.deleteByDeptNo(4L); } );
- Mapper Method's return type could be
Flux<T>
/Mono<T>
/Mono<Void>
/Flux<Void>
, andvoid
is not allowed.
- Associated Concept
- Basic Operation Instruction
- Integration with Spring Framework