Browse Source

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>
pull/2065/head
mipo256 9 months ago committed by Mark Paluch
parent
commit
dcaef9c968
No known key found for this signature in database
GPG Key ID: 55BC6374BAA9D973
  1. 9
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/StringBasedJdbcQuery.java

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

@ -15,7 +15,7 @@
*/ */
package org.springframework.data.jdbc.repository.query; 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.Array;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
@ -27,8 +27,6 @@ import java.util.List;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier; 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.BeanInstantiationException;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
@ -75,8 +73,7 @@ import org.springframework.util.ObjectUtils;
public class StringBasedJdbcQuery extends AbstractJdbcQuery { 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 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 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 static final Log LOG = LogFactory.getLog(StringBasedJdbcQuery.class);
private final JdbcConverter converter; private final JdbcConverter converter;
private final RowMapperFactory rowMapperFactory; private final RowMapperFactory rowMapperFactory;
private final ValueExpressionQueryRewriter.ParsedQuery parsedQuery; private final ValueExpressionQueryRewriter.ParsedQuery parsedQuery;
@ -149,7 +146,7 @@ public class StringBasedJdbcQuery extends AbstractJdbcQuery {
this.query = query; this.query = query;
if (queryMethod.hasLockMode()) { if (queryMethod.hasLockMode()) {
LOG.warn(LOCKING_IS_NOT_SUPPORTED); throw new UnsupportedOperationException(LOCKING_IS_NOT_SUPPORTED + queryMethod);
} }
this.parsedQuery = rewriter.parse(this.query); this.parsedQuery = rewriter.parse(this.query);
this.delegate = delegate; this.delegate = delegate;

Loading…
Cancel
Save