Fail on annotated query methods with @Lock.

Query methods that are not derived methods now cause an exception, when they are annotated with `@Lock`, since this combination is not supported.

Before they just logged a warning.

Comment edited by Jens Schauder

Signed-off-by: mipo256 <mikhailpolivakha@gmail.com>
This commit is contained in:
mipo256
2025-04-01 08:48:03 +03:00
committed by Mark Paluch
parent 8225d692f6
commit dcaef9c968

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.jdbc.repository.query;
import static org.springframework.data.jdbc.repository.query.JdbcQueryExecution.*;
import static org.springframework.data.jdbc.repository.query.JdbcQueryExecution.ResultProcessingConverter;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
@@ -27,8 +27,6 @@ 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;
@@ -75,8 +73,7 @@ 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 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. Offending method: ";
private final JdbcConverter converter;
private final RowMapperFactory rowMapperFactory;
private final ValueExpressionQueryRewriter.ParsedQuery parsedQuery;
@@ -149,7 +146,7 @@ public class StringBasedJdbcQuery extends AbstractJdbcQuery {
this.query = query;
if (queryMethod.hasLockMode()) {
LOG.warn(LOCKING_IS_NOT_SUPPORTED);
throw new UnsupportedOperationException(LOCKING_IS_NOT_SUPPORTED + queryMethod);
}
this.parsedQuery = rewriter.parse(this.query);
this.delegate = delegate;