Browse Source

Polishing.

Push JDBC-specific simple types into JdbcPostgresDialect instead of having these in the top-level dialect that shouldn't be tied to any driver technology.

Introduce profile to run Postgres tests only.
pull/1649/head
Mark Paluch 2 years ago committed by Jens Schauder
parent
commit
b57ee1af53
No known key found for this signature in database
GPG Key ID: 9537B67540F0A581
  1. 31
      spring-data-jdbc/pom.xml
  2. 3
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/aot/JdbcRuntimeHints.java
  3. 40
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/dialect/JdbcPostgresDialect.java
  4. 7
      spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/dialect/PostgresDialect.java
  5. 39
      spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/PostgresDialect.java

31
spring-data-jdbc/pom.xml

@ -273,6 +273,37 @@ @@ -273,6 +273,37 @@
<profiles>
<profile>
<id>postgres</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>postgres-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<includes>
<include>**/*IntegrationTests.java</include>
</includes>
<excludes>
<exclude>**/*HsqlIntegrationTests.java</exclude>
</excludes>
<systemPropertyVariables>
<spring.profiles.active>postgres</spring.profiles.active>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>all-dbs</id>
<build>

3
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/aot/JdbcRuntimeHints.java

@ -16,7 +16,6 @@ @@ -16,7 +16,6 @@
package org.springframework.data.jdbc.aot;
import java.util.Arrays;
import java.util.UUID;
import org.springframework.aot.hint.MemberCategory;
import org.springframework.aot.hint.RuntimeHints;
@ -63,7 +62,5 @@ class JdbcRuntimeHints implements RuntimeHintsRegistrar { @@ -63,7 +62,5 @@ class JdbcRuntimeHints implements RuntimeHintsRegistrar {
for (Class<?> simpleType : JdbcPostgresDialect.INSTANCE.simpleTypes()) {
hints.reflection().registerType(TypeReference.of(simpleType), MemberCategory.PUBLIC_CLASSES);
}
hints.reflection().registerType(TypeReference.of(UUID.class.getName()), MemberCategory.PUBLIC_CLASSES);
}
}

40
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/dialect/JdbcPostgresDialect.java

@ -23,9 +23,13 @@ import java.sql.Types; @@ -23,9 +23,13 @@ import java.sql.Types;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.function.Consumer;
import org.postgresql.core.Oid;
import org.postgresql.jdbc.TypeInfoCache;
@ -46,11 +50,47 @@ public class JdbcPostgresDialect extends PostgresDialect implements JdbcDialect @@ -46,11 +50,47 @@ public class JdbcPostgresDialect extends PostgresDialect implements JdbcDialect
private static final JdbcPostgresArrayColumns ARRAY_COLUMNS = new JdbcPostgresArrayColumns();
private static final Set<Class<?>> SIMPLE_TYPES;
static {
Set<Class<?>> simpleTypes = new HashSet<>(PostgresDialect.INSTANCE.simpleTypes());
List<String> simpleTypeNames = Arrays.asList( //
"org.postgresql.util.PGobject", //
"org.postgresql.geometric.PGpoint", //
"org.postgresql.geometric.PGbox", //
"org.postgresql.geometric.PGcircle", //
"org.postgresql.geometric.PGline", //
"org.postgresql.geometric.PGpath", //
"org.postgresql.geometric.PGpolygon", //
"org.postgresql.geometric.PGlseg" //
);
simpleTypeNames.forEach(name -> ifClassPresent(name, simpleTypes::add));
SIMPLE_TYPES = Collections.unmodifiableSet(simpleTypes);
}
@Override
public Set<Class<?>> simpleTypes() {
return SIMPLE_TYPES;
}
@Override
public JdbcArrayColumns getArraySupport() {
return ARRAY_COLUMNS;
}
/**
* If the class is present on the class path, invoke the specified consumer {@code action} with the class object,
* otherwise do nothing.
*
* @param action block to be executed if a value is present.
*/
private static void ifClassPresent(String className, Consumer<Class<?>> action) {
if (ClassUtils.isPresent(className, PostgresDialect.class.getClassLoader())) {
action.accept(ClassUtils.resolveClassName(className, PostgresDialect.class.getClassLoader()));
}
}
static class JdbcPostgresArrayColumns implements JdbcArrayColumns {
private static final boolean TYPE_INFO_PRESENT = ClassUtils.isPresent("org.postgresql.jdbc.TypeInfoCache",

7
spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/dialect/PostgresDialect.java

@ -2,18 +2,13 @@ package org.springframework.data.r2dbc.dialect; @@ -2,18 +2,13 @@ package org.springframework.data.r2dbc.dialect;
import io.r2dbc.postgresql.codec.Json;
import java.net.InetAddress;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.stream.Stream;
@ -51,7 +46,7 @@ public class PostgresDialect extends org.springframework.data.relational.core.di @@ -51,7 +46,7 @@ public class PostgresDialect extends org.springframework.data.relational.core.di
static {
Set<Class<?>> simpleTypes = new HashSet<>(
Arrays.asList(UUID.class, URL.class, URI.class, InetAddress.class, Map.class));
org.springframework.data.relational.core.dialect.PostgresDialect.INSTANCE.simpleTypes());
// conditional Postgres Geo support.
Stream.of("io.r2dbc.postgresql.codec.Box", //

39
spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/PostgresDialect.java

@ -15,13 +15,15 @@ @@ -15,13 +15,15 @@
*/
package org.springframework.data.relational.core.dialect;
import java.util.Arrays;
import java.net.InetAddress;
import java.net.URI;
import java.net.URL;
import java.rmi.server.UID;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import org.springframework.data.relational.core.sql.Functions;
import org.springframework.data.relational.core.sql.IdentifierProcessing;
@ -32,7 +34,6 @@ import org.springframework.data.relational.core.sql.SQL; @@ -32,7 +34,6 @@ import org.springframework.data.relational.core.sql.SQL;
import org.springframework.data.relational.core.sql.SimpleFunction;
import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.data.relational.core.sql.TableLike;
import org.springframework.util.ClassUtils;
/**
* An SQL dialect for Postgres.
@ -50,6 +51,9 @@ public class PostgresDialect extends AbstractDialect { @@ -50,6 +51,9 @@ public class PostgresDialect extends AbstractDialect {
*/
public static final PostgresDialect INSTANCE = new PostgresDialect();
private static final Set<Class<?>> POSTGRES_SIMPLE_TYPES = Set.of(UID.class, URL.class, URI.class, InetAddress.class,
Map.class);
protected PostgresDialect() {}
private static final LimitClause LIMIT_CLAUSE = new LimitClause() {
@ -152,32 +156,7 @@ public class PostgresDialect extends AbstractDialect { @@ -152,32 +156,7 @@ public class PostgresDialect extends AbstractDialect {
@Override
public Set<Class<?>> simpleTypes() {
Set<Class<?>> simpleTypes = new HashSet<>();
List<String> simpleTypeNames = Arrays.asList( //
"org.postgresql.util.PGobject", //
"org.postgresql.geometric.PGpoint", //
"org.postgresql.geometric.PGbox", //
"org.postgresql.geometric.PGcircle", //
"org.postgresql.geometric.PGline", //
"org.postgresql.geometric.PGpath", //
"org.postgresql.geometric.PGpolygon", //
"org.postgresql.geometric.PGlseg" //
);
simpleTypeNames.forEach(name -> ifClassPresent(name, simpleTypes::add));
return Collections.unmodifiableSet(simpleTypes);
}
/**
* If the class is present on the class path, invoke the specified consumer {@code action} with the class object,
* otherwise do nothing.
*
* @param action block to be executed if a value is present.
*/
private static void ifClassPresent(String className, Consumer<Class<?>> action) {
if (ClassUtils.isPresent(className, PostgresDialect.class.getClassLoader())) {
action.accept(ClassUtils.resolveClassName(className, PostgresDialect.class.getClassLoader()));
}
return POSTGRES_SIMPLE_TYPES;
}
@Override

Loading…
Cancel
Save