Browse Source

Clarify lack of @Lock support for String-based queries.

Original pull request #2008

Signed-off-by: mipo256 <mikhailpolivakha@gmail.com>

Commit message edited.
pull/1956/head
mipo256 9 months ago committed by Jens Schauder
parent
commit
1c15a8bade
No known key found for this signature in database
GPG Key ID: 74F6C554AE971567
  1. 8
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/StringBasedJdbcQuery.java
  2. 4
      src/main/antora/modules/ROOT/pages/jdbc/transactions.adoc

8
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/StringBasedJdbcQuery.java

@ -27,6 +27,8 @@ import java.util.List; @@ -27,6 +27,8 @@ import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeanInstantiationException;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.BeanFactory;
@ -78,6 +80,8 @@ import org.springframework.util.ObjectUtils; @@ -78,6 +80,8 @@ import org.springframework.util.ObjectUtils;
public class StringBasedJdbcQuery extends AbstractJdbcQuery {
private static final String PARAMETER_NEEDS_TO_BE_NAMED = "For queries with named parameters you need to provide names for method parameters; Use @Param for query method parameters, or use the javac flag -parameters";
private final static String LOCKING_IS_NOT_SUPPORTED = "Currently, @Lock is supported only on derived queries. In other words, for queries created with @Query, the locking condition specified with @Lock does nothing";
private static final Log LOG = LogFactory.getLog(StringBasedJdbcQuery.class);
private final JdbcConverter converter;
private final RowMapperFactory rowMapperFactory;
private final ValueExpressionQueryRewriter.ParsedQuery parsedQuery;
@ -187,6 +191,10 @@ public class StringBasedJdbcQuery extends AbstractJdbcQuery { @@ -187,6 +191,10 @@ public class StringBasedJdbcQuery extends AbstractJdbcQuery {
(counter, expression) -> String.format("__$synthetic$__%d", counter + 1), String::concat);
this.query = query;
if (queryMethod.hasLockMode()) {
LOG.warn(LOCKING_IS_NOT_SUPPORTED);
}
this.parsedQuery = rewriter.parse(this.query);
this.delegate = delegate;
}

4
src/main/antora/modules/ROOT/pages/jdbc/transactions.adoc

@ -101,6 +101,10 @@ The required value of type `LockMode` offers two values: `PESSIMISTIC_READ` whic @@ -101,6 +101,10 @@ The required value of type `LockMode` offers two values: `PESSIMISTIC_READ` whic
Some databases do not make this distinction.
In that cases both modes are equivalent of `PESSIMISTIC_WRITE`.
NOTE: It is worth stating explicitly, that `@Lock` currently is not supported on string-based queries. It means,
that queries in the repository, created with `@Query`, will ignore the locking information provided by the `@Lock`,
Using `@Lock` on string-based queries will result in the warning in logs.
.Using @Lock on derived query method
[source,java]
----

Loading…
Cancel
Save