Skip to content

Clarify the @Lock on String-based queries #2008

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
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;
Expand Down Expand Up @@ -78,6 +80,8 @@
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";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to reword the second part from a repetition to something actionable? I.e. "…include the database-specific locking hints in your query…"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, I agree with you, @mp911de. I'll provide the PR with exception thrown for 4th major release shortly, and I'll apply your suggestion, what do you think?

private static final Log LOG = LogFactory.getLog(StringBasedJdbcQuery.class);
private final JdbcConverter converter;
private final RowMapperFactory rowMapperFactory;
private final ValueExpressionQueryRewriter.ParsedQuery parsedQuery;
Expand Down Expand Up @@ -187,6 +191,10 @@ public StringBasedJdbcQuery(String query, JdbcQueryMethod queryMethod, NamedPara
(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;
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/antora/modules/ROOT/pages/jdbc/transactions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
----
Expand Down
Loading