Browse Source

Polishing.

Simplify PersistenceProvider by removing PresenceDetector interface. Refine presence detection to make present field final. Add warning suppressions as we know that we duplicate code (similar code) and that ANTLR doesn't generate methods with nullable annotations.

See #3170
Original pull request: #3176
pull/3187/head
Mark Paluch 2 years ago
parent
commit
1d49fe9271
No known key found for this signature in database
GPG Key ID: 4406B84C1661DCD1
  1. 17
      spring-data-jpa/src/main/java/org/springframework/data/jpa/provider/PersistenceProvider.java
  2. 27
      spring-data-jpa/src/main/java/org/springframework/data/jpa/provider/PresenceDetector.java
  3. 1
      spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/EqlQueryRenderer.java
  4. 1
      spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/HqlQueryRenderer.java
  5. 1
      spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpqlQueryRenderer.java

17
spring-data-jpa/src/main/java/org/springframework/data/jpa/provider/PersistenceProvider.java

@ -55,7 +55,7 @@ import org.springframework.util.ConcurrentReferenceHashMap; @@ -55,7 +55,7 @@ import org.springframework.util.ConcurrentReferenceHashMap;
* @author Greg Turnquist
* @author Yuriy Tsarkov
*/
public enum PersistenceProvider implements QueryExtractor, ProxyIdAccessor, QueryComment, PresenceDetector {
public enum PersistenceProvider implements QueryExtractor, ProxyIdAccessor, QueryComment {
/**
* Hibernate persistence provider.
@ -204,7 +204,7 @@ public enum PersistenceProvider implements QueryExtractor, ProxyIdAccessor, Quer @@ -204,7 +204,7 @@ public enum PersistenceProvider implements QueryExtractor, ProxyIdAccessor, Quer
private final Iterable<String> entityManagerClassNames;
private final Iterable<String> metamodelClassNames;
private boolean present;
private final boolean present;
/**
* Creates a new {@link PersistenceProvider}.
@ -218,12 +218,16 @@ public enum PersistenceProvider implements QueryExtractor, ProxyIdAccessor, Quer @@ -218,12 +218,16 @@ public enum PersistenceProvider implements QueryExtractor, ProxyIdAccessor, Quer
this.entityManagerClassNames = entityManagerClassNames;
this.metamodelClassNames = metamodelClassNames;
this.present = false;
entityManagerClassNames.forEach(entityManagerClassName -> {
boolean present = false;
for (String entityManagerClassName : entityManagerClassNames) {
if (ClassUtils.isPresent(entityManagerClassName, PersistenceProvider.class.getClassLoader())) {
this.present = true;
present = true;
break;
}
});
}
this.present = present;
}
/**
@ -340,7 +344,6 @@ public enum PersistenceProvider implements QueryExtractor, ProxyIdAccessor, Quer @@ -340,7 +344,6 @@ public enum PersistenceProvider implements QueryExtractor, ProxyIdAccessor, Quer
: value;
}
@Override
public boolean isPresent() {
return this.present;
}

27
spring-data-jpa/src/main/java/org/springframework/data/jpa/provider/PresenceDetector.java

@ -1,27 +0,0 @@ @@ -1,27 +0,0 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.jpa.provider;
/**
* Define operations needed to detect the presence of a given JPA provider.
*
* @author Greg Turnquist
* @since 3.2
*/
interface PresenceDetector {
boolean isPresent();
}

1
spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/EqlQueryRenderer.java

@ -26,6 +26,7 @@ import java.util.List; @@ -26,6 +26,7 @@ import java.util.List;
* @author Greg Turnquist
* @since 3.2
*/
@SuppressWarnings({ "ConstantConditions", "DuplicatedCode" })
class EqlQueryRenderer extends EqlBaseVisitor<List<JpaQueryParsingToken>> {
@Override

1
spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/HqlQueryRenderer.java

@ -26,6 +26,7 @@ import java.util.List; @@ -26,6 +26,7 @@ import java.util.List;
* @author Greg Turnquist
* @since 3.1
*/
@SuppressWarnings({ "ConstantConditions", "DuplicatedCode" })
class HqlQueryRenderer extends HqlBaseVisitor<List<JpaQueryParsingToken>> {
@Override

1
spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpqlQueryRenderer.java

@ -26,6 +26,7 @@ import java.util.List; @@ -26,6 +26,7 @@ import java.util.List;
* @author Greg Turnquist
* @since 3.1
*/
@SuppressWarnings({ "ConstantConditions", "DuplicatedCode" })
class JpqlQueryRenderer extends JpqlBaseVisitor<List<JpaQueryParsingToken>> {
@Override

Loading…
Cancel
Save