Commit Graph

60 Commits

Author SHA1 Message Date
Sam Brannen
3dcac0cf80 Clean up / Suppress warnings 2023-08-18 12:46:17 +02:00
Juergen Hoeller
0b99872704 Support for binding values from a source Map
See gh-27282
2023-08-16 10:55:26 +02:00
Juergen Hoeller
ae3bc378d6 Support for parameter/result records and beans on DatabaseClient
Includes a revision of BeanProperty/DataClassRowMapper with exclusively constructor-based configuration and without JDBC-inherited legacy settings.

Closes gh-27282
Closes gh-26021
2023-08-15 22:42:45 +02:00
Juergen Hoeller
3253d2de89 Introduce TransactionExecutionListener with begin/commit/rollback notifications
Includes ConfigurableTransactionManager interface for listener registration.
Includes additional introspection methods on TransactionExecution interface.
Includes default method declarations on TransactionStatus/SmartTransactionObject.

Closes gh-27479
2023-08-06 14:03:44 +02:00
Sam Brannen
16b9640af2 Merge branch '6.0.x' 2023-07-12 11:50:11 +02:00
Sam Brannen
68f2b0ca59 Rely on auto-boxing in tests 2023-07-12 11:49:02 +02:00
Sam Brannen
b9e972c248 Polishing 2023-06-06 16:11:40 +02:00
Juergen Hoeller
4fb4c95220 Merge branch '6.0.x' 2023-06-05 10:53:29 +02:00
Juergen Hoeller
974e10379a Add nested propagation support to R2dbcTransactionManager
Closes gh-30134
2023-06-05 10:45:47 +02:00
Sam Brannen
75466fee8d Merge branch '6.0.x' 2023-06-04 16:40:23 +02:00
Sam Brannen
24fa8793b1 Update copyright headers 2023-06-04 16:36:52 +02:00
Juergen Hoeller
2689bab652 Merge branch '6.0.x' 2023-06-03 17:19:06 +02:00
Juergen Hoeller
9751987dc1 Avoid unnecessary auto-commit check for proper transaction begin
Closes gh-30508
2023-06-03 17:17:47 +02:00
Juergen Hoeller
e82dd14f0f Merge branch '6.0.x'
# Conflicts:
#	spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java
2023-06-02 23:30:04 +02:00
Juergen Hoeller
4b8adf2dcc Polishing 2023-06-02 23:28:14 +02:00
Juergen Hoeller
1dba8f6add Polishing 2023-06-02 20:45:26 +02:00
Juergen Hoeller
322cbca0dc Support for async/reactive close methods (e.g. R2DBC)
Closes gh-26991
2023-06-02 20:40:55 +02:00
Simon Baslé
5977bb05ca Port BeanPropertyRowMapper and DataClassRowMapper for r2dbc
This commit ports and adapts spring-jdbc's `BeanPropertyRowMapper` and
`DataClassRowMapper` to spring-r2dbc, allowing to `map` rows or
outParameters to object instances, data classes or records.

See gh-26021
Closes gh-30530
2023-05-25 17:40:52 +02:00
Krzysztof Krasoń
1734deca1e Refactor AssertJ assertions into more idiomatic ones
This commit refactors some AssertJ assertions into more idiomatic and
readable ones. Using the dedicated assertion instead of a generic one
will produce more meaningful error messages. 

For instance, consider collection size:
```
// expected: 5 but was: 2
assertThat(collection.size()).equals(5);
// Expected size: 5 but was: 2 in: [1, 2]
assertThat(collection).hasSize(5);
```

Closes gh-30104
2023-04-04 17:34:07 +02:00
Simon Baslé
9b50c0d590 Ensure reactive transaction rollback on commit error
This change fixes a situation where error handling was skipped during
`processCommit()` in case the `doCommit()` failed. The error handling
was set up via an `onErrorResume` operator that was nested inside a
`then(...)`, applied to an inner `Mono.empty()`. As a consequence,
it would never receive an error signal (effectively decoupling the
onErrorResume from the main chain).

This change simply moves the error handling back one level up. It also
simplifies the `doCommit` code a bit by getting rid of the steps that
artificially introduce a `Mono<Object>` return type, which is not really
needed.

A pre-existing test was missing the fact that the rollback didn't occur,
which is now fixed. Another dedicated test is introduced building upon
the `ReactiveTestTransactionManager` class.

Closes gh-30096
2023-03-10 12:23:44 +01:00
Enric Sala
edf0ae77e5 Avoid rollback after a commit failure in TransactionalOperator
A failure to commit a reactive transaction will complete the
transaction and clean up resources. Executing a rollback at
that point is invalid, which causes an
IllegalTransactionStateException that masks the cause of the
commit failure.

This change restructures TransactionalOperatorImpl and
ReactiveTransactionSupport to avoid executing a rollback after
a failed commit. While there, the Mono transaction handling in
TransactionalOperator is simplified by moving it to a default
method on the interface.

Closes gh-27572
2023-03-06 10:05:59 +01:00
Johnny Lim
ce3be72e7f Polish 2023-02-15 22:22:58 +09:00
Juergen Hoeller
ca9439657e Detect MSSQL code 2601 as duplicate key (aligned with sql-error-codes.xml)
Closes gh-29950
2023-02-09 14:59:09 +01:00
danu
e050c37158 Release R2DBC connection when cleanup fails in transaction
When using R2dbcTransactionManager, connection will not be released if
it encounters error while doing `afterCleanup` steps. As `afterCleanup`
can use a database connection when doing `setAutoCommit(true)`, it can
fail under some conditions where the connection is not reliable.

This leads to the Connection not being released.

This commit ensures that inner steps of the `doCleanupAfterCompletion`
are protected against errors, logging the errors and continuing the
cleanup until the last step, which releases the connection.

Closes gh-29703

Co-authored-by: Simon Baslé <sbasle@vmware.com>
2023-02-03 17:33:55 +01:00
Simon Baslé
d72df5ace4 DatabaseClient uses SQL Supplier more lazily
This commit modifies the `DefaultDatabaseClient` implementation in order
to ensure lazier usage of the `Supplier<String>` passed to the sql
method (`DatabaseClient#sql(Supplier)`).

Since technically `DatabaseClient` is an interface that could have 3rd
party implementations, the lazyness expectation is only hinted at in the
`DatabaseClient#sql` javadoc.

Possible caveat: some log statements attempt to reflect the now lazily
resolved SQL string. Similarly, some exceptions can capture the SQL that
caused the issue if known. We expect that these always occur after the
execution of the statement has been attempted (see `ResultFunction`).
At this point the SQL string will be accessible and logs and exceptions
should reflect it as before. Keep an eye out for such strings turning
into `null` after this change, which would indicate the opposite.

Closes gh-29367
2023-01-26 14:35:31 +01:00
Sam Brannen
0502d18e3d Update copyright headers 2023-01-19 16:20:03 +01:00
Sam Brannen
c4c786596f Migrate to Mockito.mock(T...) where feasible 2023-01-19 16:20:02 +01:00
Juergen Hoeller
a644245e0e Check well-known database error codes in case of generic SQL state 23000
Closes gh-29699
2022-12-23 15:13:29 +01:00
Juergen Hoeller
4c69892f39 Detect SQL state 23505/40001 as DuplicateKeyException/CannotAcquireLockException
Favors PessimisticLockingFailureException over plain ConcurrencyFailureException.
Deprecates CannotSerializeTransactionException and DeadlockLoserDataAccessException.

Closes gh-29511
Closes gh-29675
2022-12-13 11:07:13 +01:00
Juergen Hoeller
d4fac82d68 Preserve square brackets for index/key expressions
Closes gh-27925
2022-10-18 22:39:53 +02:00
Sam Brannen
0fb9de5d0e Merge branch '5.3.x' 2022-07-13 16:36:01 +02:00
Marc Wrobel
bd3499671c Fix typos in test code
This commit fixes typos in test class names, test method names, and
test variable names.

Closes gh-28807
2022-07-13 16:24:11 +02:00
Sam Brannen
ddd11610cf Merge branch '5.3.x'
# Conflicts:
#	spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DriverManagerDataSource.java
#	spring-orm/src/main/java/org/springframework/orm/jpa/JpaVendorAdapter.java
2022-07-13 13:46:34 +02:00
Marc Wrobel
cfb39acc97 Fix and improve Javadoc in spring-r2dbc
See gh-28796
2022-07-13 13:42:16 +02:00
Juergen Hoeller
7055ddb489 Upgrade to R2DBC 1.0
Includes Reactor 2022.0.0-M4, Netty 4.1.79, Jetty 11.0.11, Undertow 2.2.18, Hibernate ORM 5.6.10, Checkstyle 10.3.1

Closes gh-28787
2022-07-13 10:23:51 +02:00
Juergen Hoeller
4e1b9f1492 Replace deep exception message nesting with custom inclusion of cause messages
Includes deprecation of NestedServletException, whereas NestedCheckedException and NestedRuntimeException remain as base classes with several convenience methods.

Closes gh-25162
2022-06-14 14:00:28 +02:00
Sam Brannen
3da7a48a17 Explicitly close ApplicationContexts and clean up warnings in tests 2022-03-20 13:19:25 +01:00
Mark Paluch
a3781a45d6 Align with R2DBC 0.9 API changes
Adopt to R2DBC Parameter type, deprecate our own one in favor of the R2DBC type.
Add support for extensible transaction definitions and support to consume Readable and result segments.
Return Long instead of Integer in DatabaseClient update in preparation for R2DBC 1.0 changes.
2022-03-16 19:27:14 +01:00
Sam Brannen
8c5a407a7d Suppress deprecation warnings in tests in build 2022-02-18 16:22:43 +01:00
Juergen Hoeller
e5af4aa608 Initial upgrade to R2DBC Borca
See gh-27976
2022-02-04 21:09:02 +01:00
Sam Brannen
12342d7f8e Sync ScriptUtilsUnitTests implementations 2022-02-03 15:20:54 +01:00
Sam Brannen
7769ded887 Merge branch '5.3.x' 2022-01-07 14:31:32 +01:00
Henning Poettker
ed4e2289cd Support H2 1.4 & 2.0 in H2SequenceMaxValueIncrementer
Prior to this commit, H2SequenceMaxValueIncrementer only supported H2
database 1.4.

This commit updates H2SequenceMaxValueIncrementer's getSequenceQuery()
method so that the syntax used supports version 1.4 and 2.0 of the H2
database.

This commit also updates several test schemas so that they work with H2
1.4 and 2.0 as well as HSQL.

Closes gh-27870
2022-01-07 10:09:27 +01:00
Juergen Hoeller
64b6beed5b Consistent support for square brackets around named parameter
See gh-27716
2021-12-14 11:34:48 +01:00
Anton Naydenov
86eda279c8 Support SQUARE brackets [] around NAMED parameter 2021-12-14 11:24:38 +01:00
Sanghyuk Jung
ac72277258 Fix duplicate "the" in Javadoc and XSD
See gh-27291
2021-08-19 08:44:03 +02:00
Sam Brannen
fab7b1cebe Polish ScriptUtils internals in spring-r2dbc
See gh-26947
2021-05-18 14:29:18 +02:00
Sam Brannen
7f5904c68b Remove internal APIs from ScriptUtils in spring-r2dbc
Prior to this commit, many of the utility methods in ScriptUtils in
spring-r2dbc were public by accident: they were copied from ScriptUtils
in spring-jdbc without changing the visibility when spring-r2dbc was
introduced in Spring Framework. 5.3 GA.

This commit corrects this mistake by removing internal APIs from
ScriptUtils in spring-r2dbc from the public contract.

See gh-26947
2021-05-17 12:15:30 +02:00
Sam Brannen
c80c4e001a Add missing author tags and sync SQL script support for JDBC & R2DBC 2021-05-16 17:18:56 +02:00
Sam Brannen
569ce840cf Ignore comments when searching for statement delimiter in ScriptUtils
Prior to this commit, the implementations of
ScriptUtils.containsSqlScriptDelimiters() in spring-jdbc and
spring-r2dbc did not ignore comments when searching for the statement
delimiter within an SQL script. This resulted in subtle bugs if a
comment contained a single single-quote or single double-quote, since
the absence of the closing single-quote or double-quote led the
algorithm to believe that it was still "within a text literal". Similar
issues could arise if a comment contained the sought statement
delimiter but the rest of the script did not contain the sought
statement delimiter. In such cases, the algorithms in ScriptUtils could
erroneously choose an incorrect statement delimiter -- for example,
using the fallback statement delimiter instead of the delimiter
specified by the user.

This commit avoids such bugs by ignoring single-line comments and block
comments when searching for the statement delimiter within an SQL
script.

Closes gh-26911
2021-05-14 14:23:27 +02:00