Skip to content

Commit 794b031

Browse files
schaudermp911de
authored andcommitted
Prepared move of JdbcValue to mapping.
This is to avoid dependency cycles between mapping and conversion. Closes #1128
1 parent 09f78c4 commit 794b031

File tree

12 files changed

+84
-39
lines changed

12 files changed

+84
-39
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/BasicJdbcConverter.java

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.springframework.core.convert.converter.Converter;
3333
import org.springframework.data.convert.CustomConversions;
3434
import org.springframework.data.jdbc.core.mapping.AggregateReference;
35+
import org.springframework.data.jdbc.core.mapping.JdbcValue;
3536
import org.springframework.data.jdbc.support.JdbcUtil;
3637
import org.springframework.data.mapping.PersistentPropertyAccessor;
3738
import org.springframework.data.mapping.PersistentPropertyPath;

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.springframework.dao.OptimisticLockingFailureException;
3333
import org.springframework.data.domain.Pageable;
3434
import org.springframework.data.domain.Sort;
35+
import org.springframework.data.jdbc.core.mapping.JdbcValue;
3536
import org.springframework.data.jdbc.support.JdbcUtil;
3637
import org.springframework.data.mapping.PersistentProperty;
3738
import org.springframework.data.mapping.PersistentPropertyAccessor;

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/JdbcConverter.java

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.sql.ResultSet;
1919

20+
import org.springframework.data.jdbc.core.mapping.JdbcValue;
2021
import org.springframework.data.relational.core.conversion.RelationalConverter;
2122
import org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension;
2223
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/JdbcValue.java

+4-33
Original file line numberDiff line numberDiff line change
@@ -27,45 +27,16 @@
2727
*
2828
* @author Jens Schauder
2929
* @since 1.1
30+
* @deprecated use {@link org.springframework.data.jdbc.core.mapping.JdbcValue}
3031
*/
31-
public final class JdbcValue {
32-
33-
private final Object value;
34-
private final JDBCType jdbcType;
32+
@Deprecated
33+
public final class JdbcValue extends org.springframework.data.jdbc.core.mapping.JdbcValue {
3534

3635
private JdbcValue(@Nullable Object value, @Nullable JDBCType jdbcType) {
37-
38-
this.value = value;
39-
this.jdbcType = jdbcType;
36+
super(value, jdbcType);
4037
}
4138

4239
public static JdbcValue of(@Nullable Object value, @Nullable JDBCType jdbcType) {
4340
return new JdbcValue(value, jdbcType);
4441
}
45-
46-
@Nullable
47-
public Object getValue() {
48-
return this.value;
49-
}
50-
51-
@Nullable
52-
public JDBCType getJdbcType() {
53-
return this.jdbcType;
54-
}
55-
56-
@Override
57-
public boolean equals(Object o) {
58-
59-
if (this == o)
60-
return true;
61-
if (o == null || getClass() != o.getClass())
62-
return false;
63-
JdbcValue jdbcValue = (JdbcValue) o;
64-
return Objects.equals(value, jdbcValue.value) && jdbcType == jdbcValue.jdbcType;
65-
}
66-
67-
@Override
68-
public int hashCode() {
69-
return Objects.hash(value, jdbcType);
70-
}
7142
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.springframework.core.convert.converter.Converter;
2828
import org.springframework.data.convert.ReadingConverter;
2929
import org.springframework.data.convert.WritingConverter;
30-
import org.springframework.data.jdbc.core.convert.JdbcValue;
30+
import org.springframework.data.jdbc.core.mapping.JdbcValue;
3131
import org.springframework.data.relational.core.dialect.Db2Dialect;
3232
import org.springframework.data.relational.core.dialect.MySqlDialect;
3333
import org.springframework.data.relational.core.sql.IdentifierProcessing;

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/mapping/JdbcSimpleTypes.java

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import java.util.Set;
3232
import java.util.UUID;
3333

34-
import org.springframework.data.jdbc.core.convert.JdbcValue;
3534
import org.springframework.data.mapping.model.SimpleTypeHolder;
3635

3736
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright 2019-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.jdbc.core.mapping;
17+
18+
import java.sql.JDBCType;
19+
import java.util.Objects;
20+
21+
import org.springframework.lang.Nullable;
22+
23+
/**
24+
* Wraps a value with the JDBCType that should be used to pass it as a bind parameter to a
25+
* {@link java.sql.PreparedStatement}. Register a converter from any type to {@link JdbcValue} in order to control the
26+
* value and the {@link JDBCType} as which a value should get passed to the JDBC driver.
27+
*
28+
* @author Jens Schauder
29+
* @since 2.4
30+
*/
31+
public class JdbcValue {
32+
33+
private final Object value;
34+
private final JDBCType jdbcType;
35+
36+
protected JdbcValue(@Nullable Object value, @Nullable JDBCType jdbcType) {
37+
38+
this.value = value;
39+
this.jdbcType = jdbcType;
40+
}
41+
42+
public static JdbcValue of(@Nullable Object value, @Nullable JDBCType jdbcType) {
43+
return new JdbcValue(value, jdbcType);
44+
}
45+
46+
@Nullable
47+
public Object getValue() {
48+
return this.value;
49+
}
50+
51+
@Nullable
52+
public JDBCType getJdbcType() {
53+
return this.jdbcType;
54+
}
55+
56+
@Override
57+
public boolean equals(Object o) {
58+
59+
if (this == o)
60+
return true;
61+
if (o == null || getClass() != o.getClass())
62+
return false;
63+
JdbcValue jdbcValue = (JdbcValue) o;
64+
return Objects.equals(value, jdbcValue.value) && jdbcType == jdbcValue.jdbcType;
65+
}
66+
67+
@Override
68+
public int hashCode() {
69+
return Objects.hash(value, jdbcType);
70+
}
71+
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import org.springframework.data.domain.Sort;
2828
import org.springframework.data.jdbc.core.convert.JdbcConverter;
29-
import org.springframework.data.jdbc.core.convert.JdbcValue;
29+
import org.springframework.data.jdbc.core.mapping.JdbcValue;
3030
import org.springframework.data.mapping.PersistentPropertyAccessor;
3131
import org.springframework.data.mapping.PersistentPropertyPath;
3232
import org.springframework.data.mapping.PropertyPath;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.springframework.core.convert.converter.Converter;
2626
import org.springframework.data.jdbc.core.convert.JdbcColumnTypes;
2727
import org.springframework.data.jdbc.core.convert.JdbcConverter;
28-
import org.springframework.data.jdbc.core.convert.JdbcValue;
28+
import org.springframework.data.jdbc.core.mapping.JdbcValue;
2929
import org.springframework.data.jdbc.support.JdbcUtil;
3030
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
3131
import org.springframework.data.relational.repository.query.RelationalParameterAccessor;

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/BasicJdbcConverterUnitTests.java

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.springframework.data.annotation.Id;
4040
import org.springframework.data.jdbc.core.mapping.AggregateReference;
4141
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
42+
import org.springframework.data.jdbc.core.mapping.JdbcValue;
4243
import org.springframework.data.jdbc.support.JdbcUtil;
4344
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
4445
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/dialect/JdbcMySqlDialectUnitTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import org.junit.jupiter.api.Test;
2525
import org.springframework.data.jdbc.core.convert.JdbcCustomConversions;
26-
import org.springframework.data.jdbc.core.convert.JdbcValue;
26+
import org.springframework.data.jdbc.core.mapping.JdbcValue;
2727

2828
/**
2929
* Tests for {@link JdbcMySqlDialect}.

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryCustomConversionIntegrationTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import org.springframework.data.convert.ReadingConverter;
3636
import org.springframework.data.convert.WritingConverter;
3737
import org.springframework.data.jdbc.core.convert.JdbcCustomConversions;
38-
import org.springframework.data.jdbc.core.convert.JdbcValue;
38+
import org.springframework.data.jdbc.core.mapping.JdbcValue;
3939
import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory;
4040
import org.springframework.data.jdbc.testing.AssumeFeatureTestExecutionListener;
4141
import org.springframework.data.jdbc.testing.TestConfiguration;

0 commit comments

Comments
 (0)