Skip to content

Commit b57ee1a

Browse files
mp911deschauder
authored andcommitted
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.
1 parent a5ccc04 commit b57ee1a

File tree

5 files changed

+81
-39
lines changed

5 files changed

+81
-39
lines changed

spring-data-jdbc/pom.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,37 @@
273273

274274

275275
<profiles>
276+
<profile>
277+
<id>postgres</id>
278+
<build>
279+
<plugins>
280+
<plugin>
281+
<groupId>org.apache.maven.plugins</groupId>
282+
<artifactId>maven-surefire-plugin</artifactId>
283+
<executions>
284+
<execution>
285+
<id>postgres-test</id>
286+
<phase>test</phase>
287+
<goals>
288+
<goal>test</goal>
289+
</goals>
290+
<configuration>
291+
<includes>
292+
<include>**/*IntegrationTests.java</include>
293+
</includes>
294+
<excludes>
295+
<exclude>**/*HsqlIntegrationTests.java</exclude>
296+
</excludes>
297+
<systemPropertyVariables>
298+
<spring.profiles.active>postgres</spring.profiles.active>
299+
</systemPropertyVariables>
300+
</configuration>
301+
</execution>
302+
</executions>
303+
</plugin>
304+
</plugins>
305+
</build>
306+
</profile>
276307
<profile>
277308
<id>all-dbs</id>
278309
<build>

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.springframework.data.jdbc.aot;
1717

1818
import java.util.Arrays;
19-
import java.util.UUID;
2019

2120
import org.springframework.aot.hint.MemberCategory;
2221
import org.springframework.aot.hint.RuntimeHints;
@@ -63,7 +62,5 @@ public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader)
6362
for (Class<?> simpleType : JdbcPostgresDialect.INSTANCE.simpleTypes()) {
6463
hints.reflection().registerType(TypeReference.of(simpleType), MemberCategory.PUBLIC_CLASSES);
6564
}
66-
67-
hints.reflection().registerType(TypeReference.of(UUID.class.getName()), MemberCategory.PUBLIC_CLASSES);
6865
}
6966
}

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@
2323
import java.util.Arrays;
2424
import java.util.Collections;
2525
import java.util.HashMap;
26+
import java.util.HashSet;
2627
import java.util.Iterator;
28+
import java.util.List;
2729
import java.util.Map;
30+
import java.util.Set;
2831
import java.util.UUID;
32+
import java.util.function.Consumer;
2933

3034
import org.postgresql.core.Oid;
3135
import org.postgresql.jdbc.TypeInfoCache;
@@ -46,11 +50,47 @@ public class JdbcPostgresDialect extends PostgresDialect implements JdbcDialect
4650

4751
private static final JdbcPostgresArrayColumns ARRAY_COLUMNS = new JdbcPostgresArrayColumns();
4852

53+
private static final Set<Class<?>> SIMPLE_TYPES;
54+
55+
static {
56+
57+
Set<Class<?>> simpleTypes = new HashSet<>(PostgresDialect.INSTANCE.simpleTypes());
58+
List<String> simpleTypeNames = Arrays.asList( //
59+
"org.postgresql.util.PGobject", //
60+
"org.postgresql.geometric.PGpoint", //
61+
"org.postgresql.geometric.PGbox", //
62+
"org.postgresql.geometric.PGcircle", //
63+
"org.postgresql.geometric.PGline", //
64+
"org.postgresql.geometric.PGpath", //
65+
"org.postgresql.geometric.PGpolygon", //
66+
"org.postgresql.geometric.PGlseg" //
67+
);
68+
simpleTypeNames.forEach(name -> ifClassPresent(name, simpleTypes::add));
69+
SIMPLE_TYPES = Collections.unmodifiableSet(simpleTypes);
70+
}
71+
72+
@Override
73+
public Set<Class<?>> simpleTypes() {
74+
return SIMPLE_TYPES;
75+
}
76+
4977
@Override
5078
public JdbcArrayColumns getArraySupport() {
5179
return ARRAY_COLUMNS;
5280
}
5381

82+
/**
83+
* If the class is present on the class path, invoke the specified consumer {@code action} with the class object,
84+
* otherwise do nothing.
85+
*
86+
* @param action block to be executed if a value is present.
87+
*/
88+
private static void ifClassPresent(String className, Consumer<Class<?>> action) {
89+
if (ClassUtils.isPresent(className, PostgresDialect.class.getClassLoader())) {
90+
action.accept(ClassUtils.resolveClassName(className, PostgresDialect.class.getClassLoader()));
91+
}
92+
}
93+
5494
static class JdbcPostgresArrayColumns implements JdbcArrayColumns {
5595

5696
private static final boolean TYPE_INFO_PRESENT = ClassUtils.isPresent("org.postgresql.jdbc.TypeInfoCache",

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@
22

33
import io.r2dbc.postgresql.codec.Json;
44

5-
import java.net.InetAddress;
6-
import java.net.URI;
7-
import java.net.URL;
85
import java.util.ArrayList;
96
import java.util.Arrays;
107
import java.util.Collection;
118
import java.util.Collections;
129
import java.util.HashSet;
1310
import java.util.List;
14-
import java.util.Map;
1511
import java.util.Set;
16-
import java.util.UUID;
1712
import java.util.function.Consumer;
1813
import java.util.stream.Stream;
1914

@@ -51,7 +46,7 @@ public class PostgresDialect extends org.springframework.data.relational.core.di
5146
static {
5247

5348
Set<Class<?>> simpleTypes = new HashSet<>(
54-
Arrays.asList(UUID.class, URL.class, URI.class, InetAddress.class, Map.class));
49+
org.springframework.data.relational.core.dialect.PostgresDialect.INSTANCE.simpleTypes());
5550

5651
// conditional Postgres Geo support.
5752
Stream.of("io.r2dbc.postgresql.codec.Box", //

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

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
*/
1616
package org.springframework.data.relational.core.dialect;
1717

18-
import java.util.Arrays;
18+
import java.net.InetAddress;
19+
import java.net.URI;
20+
import java.net.URL;
21+
import java.rmi.server.UID;
1922
import java.util.Collection;
2023
import java.util.Collections;
21-
import java.util.HashSet;
2224
import java.util.List;
25+
import java.util.Map;
2326
import java.util.Set;
24-
import java.util.function.Consumer;
2527

2628
import org.springframework.data.relational.core.sql.Functions;
2729
import org.springframework.data.relational.core.sql.IdentifierProcessing;
@@ -32,7 +34,6 @@
3234
import org.springframework.data.relational.core.sql.SimpleFunction;
3335
import org.springframework.data.relational.core.sql.SqlIdentifier;
3436
import org.springframework.data.relational.core.sql.TableLike;
35-
import org.springframework.util.ClassUtils;
3637

3738
/**
3839
* An SQL dialect for Postgres.
@@ -50,6 +51,9 @@ public class PostgresDialect extends AbstractDialect {
5051
*/
5152
public static final PostgresDialect INSTANCE = new PostgresDialect();
5253

54+
private static final Set<Class<?>> POSTGRES_SIMPLE_TYPES = Set.of(UID.class, URL.class, URI.class, InetAddress.class,
55+
Map.class);
56+
5357
protected PostgresDialect() {}
5458

5559
private static final LimitClause LIMIT_CLAUSE = new LimitClause() {
@@ -152,32 +156,7 @@ public IdentifierProcessing getIdentifierProcessing() {
152156

153157
@Override
154158
public Set<Class<?>> simpleTypes() {
155-
156-
Set<Class<?>> simpleTypes = new HashSet<>();
157-
List<String> simpleTypeNames = Arrays.asList( //
158-
"org.postgresql.util.PGobject", //
159-
"org.postgresql.geometric.PGpoint", //
160-
"org.postgresql.geometric.PGbox", //
161-
"org.postgresql.geometric.PGcircle", //
162-
"org.postgresql.geometric.PGline", //
163-
"org.postgresql.geometric.PGpath", //
164-
"org.postgresql.geometric.PGpolygon", //
165-
"org.postgresql.geometric.PGlseg" //
166-
);
167-
simpleTypeNames.forEach(name -> ifClassPresent(name, simpleTypes::add));
168-
return Collections.unmodifiableSet(simpleTypes);
169-
}
170-
171-
/**
172-
* If the class is present on the class path, invoke the specified consumer {@code action} with the class object,
173-
* otherwise do nothing.
174-
*
175-
* @param action block to be executed if a value is present.
176-
*/
177-
private static void ifClassPresent(String className, Consumer<Class<?>> action) {
178-
if (ClassUtils.isPresent(className, PostgresDialect.class.getClassLoader())) {
179-
action.accept(ClassUtils.resolveClassName(className, PostgresDialect.class.getClassLoader()));
180-
}
159+
return POSTGRES_SIMPLE_TYPES;
181160
}
182161

183162
@Override

0 commit comments

Comments
 (0)