Skip to content

Commit 4e5ea41

Browse files
committed
Cleanup no longer required code.
1 parent 8beebdd commit 4e5ea41

File tree

8 files changed

+78
-401
lines changed

8 files changed

+78
-401
lines changed

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

+28-307
Large diffs are not rendered by default.

Diff for: spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/EntityRowMapper.java

+6-36
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,15 @@
1515
*/
1616
package org.springframework.data.jdbc.core.convert;
1717

18-
import java.sql.Array;
1918
import java.sql.ResultSet;
20-
import java.sql.ResultSetMetaData;
2119
import java.sql.SQLException;
2220

2321
import org.springframework.data.relational.core.mapping.AggregatePath;
2422
import org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension;
2523
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
2624
import org.springframework.data.relational.domain.RowDocument;
2725
import org.springframework.jdbc.core.RowMapper;
28-
import org.springframework.jdbc.support.JdbcUtils;
26+
import org.springframework.lang.Nullable;
2927

3028
/**
3129
* Maps a {@link ResultSet} to an entity of type {@code T}, including entities referenced. This {@link RowMapper} might
@@ -43,7 +41,7 @@ public class EntityRowMapper<T> implements RowMapper<T> {
4341
private final RelationalPersistentEntity<T> entity;
4442
private final AggregatePath path;
4543
private final JdbcConverter converter;
46-
private final Identifier identifier;
44+
private final @Nullable Identifier identifier;
4745

4846
/**
4947
* @deprecated use {@link EntityRowMapper#EntityRowMapper(AggregatePath, JdbcConverter, Identifier)} instead
@@ -78,39 +76,11 @@ public EntityRowMapper(RelationalPersistentEntity<T> entity, JdbcConverter conve
7876
@Override
7977
public T mapRow(ResultSet resultSet, int rowNumber) throws SQLException {
8078

81-
RowDocument document = toRowDocument(resultSet);
79+
RowDocument document = RowDocumentResultSetExtractor.toRowDocument(resultSet);
8280

83-
// TODO: Remove mapRow methods.
84-
if (true) {
85-
return path == null //
86-
? converter.readAndResolve(entity.getType(), document) //
87-
: converter.readAndResolve(entity.getType(), document, identifier);
88-
}
89-
90-
return path == null //
91-
? converter.mapRow(entity, resultSet, rowNumber) //
92-
: converter.mapRow(path, resultSet, identifier, rowNumber);
81+
return identifier == null //
82+
? converter.readAndResolve(entity.getType(), document) //
83+
: converter.readAndResolve(entity.getType(), document, identifier);
9384
}
9485

95-
/**
96-
* Create a {@link RowDocument} from the current {@link ResultSet} row.
97-
*
98-
* @param resultSet must not be {@literal null}.
99-
* @return
100-
* @throws SQLException
101-
*/
102-
static RowDocument toRowDocument(ResultSet resultSet) throws SQLException {
103-
104-
ResultSetMetaData md = resultSet.getMetaData();
105-
int columnCount = md.getColumnCount();
106-
RowDocument document = new RowDocument(columnCount);
107-
108-
for (int i = 0; i < columnCount; i++) {
109-
Object rsv = JdbcUtils.getResultSetValue(resultSet, i + 1);
110-
String columnName = md.getColumnLabel(i + 1);
111-
document.put(columnName, rsv instanceof Array a ? a.getArray() : rsv);
112-
}
113-
114-
return document;
115-
}
11686
}

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

+18-31
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
package org.springframework.data.jdbc.core.convert;
1717

1818
import java.sql.ResultSet;
19+
import java.sql.SQLException;
1920
import java.sql.SQLType;
2021

2122
import org.springframework.data.jdbc.core.mapping.JdbcValue;
22-
import org.springframework.data.projection.EntityProjection;
2323
import org.springframework.data.relational.core.conversion.RelationalConverter;
24-
import org.springframework.data.relational.core.mapping.AggregatePath;
2524
import org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension;
2625
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
2726
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
@@ -58,8 +57,16 @@ public interface JdbcConverter extends RelationalConverter {
5857
* @param key primary key.
5958
* @param <T>
6059
* @return
60+
* @deprecated since 3.2, use {@link #readAndResolve(Class, RowDocument, Identifier)} instead.
6161
*/
62-
<T> T mapRow(RelationalPersistentEntity<T> entity, ResultSet resultSet, Object key);
62+
@Deprecated(since = "3.2")
63+
default <T> T mapRow(RelationalPersistentEntity<T> entity, ResultSet resultSet, Object key) {
64+
try {
65+
return readAndResolve(entity.getType(), RowDocumentResultSetExtractor.toRowDocument(resultSet));
66+
} catch (SQLException e) {
67+
throw new RuntimeException(e);
68+
}
69+
}
6370

6471
/**
6572
* Read the current row from {@link ResultSet} to an {@link PersistentPropertyPathExtension#getActualType() entity}.
@@ -70,39 +77,19 @@ public interface JdbcConverter extends RelationalConverter {
7077
* @param key primary key.
7178
* @param <T>
7279
* @return
73-
* @deprecated use {@link #mapRow(AggregatePath, ResultSet, Identifier, Object)} instead.
80+
* @deprecated use {@link #readAndResolve(Class, RowDocument, Identifier)} instead.
7481
*/
82+
@SuppressWarnings("unchecked")
7583
@Deprecated(since = "3.2", forRemoval = true)
7684
default <T> T mapRow(PersistentPropertyPathExtension path, ResultSet resultSet, Identifier identifier, Object key) {
77-
return mapRow(path.getAggregatePath(), resultSet, identifier, key);
85+
try {
86+
return (T) readAndResolve(path.getRequiredLeafEntity().getType(),
87+
RowDocumentResultSetExtractor.toRowDocument(resultSet), identifier);
88+
} catch (SQLException e) {
89+
throw new RuntimeException(e);
90+
}
7891
};
7992

80-
/**
81-
* Read the current row from {@link ResultSet} to an {@link AggregatePath#getLeafEntity()} entity}.
82-
*
83-
* @param path path to the owning property.
84-
* @param resultSet the {@link ResultSet} to read from.
85-
* @param identifier entity identifier.
86-
* @param key primary key.
87-
* @param <T>
88-
* @return
89-
*/
90-
<T> T mapRow(AggregatePath path, ResultSet resultSet, Identifier identifier, Object key);
91-
92-
/**
93-
* Apply a projection to {@link RowDocument} and return the projection return type {@code R}.
94-
* {@link EntityProjection#isProjection() Non-projecting} descriptors fall back to {@link #read(Class, RowDocument)
95-
* regular object materialization}.
96-
*
97-
* @param descriptor the projection descriptor, must not be {@literal null}.
98-
* @param document must not be {@literal null}.
99-
* @param <R>
100-
* @return a new instance of the projection return type {@code R}.
101-
* @since 3.2
102-
* @see #project(EntityProjection, RowDocument)
103-
*/
104-
<R> R projectAndResolve(EntityProjection<R, ?> descriptor, RowDocument document);
105-
10693
/**
10794
* Read a {@link RowDocument} into the requested {@link Class aggregate type} and resolve references by looking these
10895
* up from {@link RelationResolver}.

Diff for: spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/MapEntityRowMapper.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,11 @@ public Map.Entry<Object, T> mapRow(ResultSet rs, int rowNum) throws SQLException
5555
return new HashMap.SimpleEntry<>(key, mapEntity(rs, key));
5656
}
5757

58+
@SuppressWarnings("unchecked")
5859
private T mapEntity(ResultSet resultSet, Object key) throws SQLException {
5960

60-
if (true) {
61-
RowDocument document = EntityRowMapper.toRowDocument(resultSet);
62-
return (T) converter.readAndResolve(path.getLeafEntity().getType(), document,
63-
identifier.withPart(keyColumn, key, Object.class));
64-
}
65-
66-
return converter.mapRow(path, resultSet, identifier, key);
61+
RowDocument document = RowDocumentResultSetExtractor.toRowDocument(resultSet);
62+
return (T) converter.readAndResolve(path.getLeafEntity().getType(), document,
63+
identifier.withPart(keyColumn, key, Object.class));
6764
}
6865
}

Diff for: spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/RowDocumentResultSetExtractor.java

+22
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,28 @@ class RowDocumentResultSetExtractor {
5151
this.propertyToColumn = propertyToColumn;
5252
}
5353

54+
/**
55+
* Create a {@link RowDocument} from the current {@link ResultSet} row.
56+
*
57+
* @param resultSet must not be {@literal null}.
58+
* @return
59+
* @throws SQLException
60+
*/
61+
static RowDocument toRowDocument(ResultSet resultSet) throws SQLException {
62+
63+
ResultSetMetaData md = resultSet.getMetaData();
64+
int columnCount = md.getColumnCount();
65+
RowDocument document = new RowDocument(columnCount);
66+
67+
for (int i = 0; i < columnCount; i++) {
68+
Object rsv = JdbcUtils.getResultSetValue(resultSet, i + 1);
69+
String columnName = md.getColumnLabel(i + 1);
70+
document.put(columnName, rsv instanceof Array a ? a.getArray() : rsv);
71+
}
72+
73+
return document;
74+
}
75+
5476
/**
5577
* Adapter to extract values and column metadata from a {@link ResultSet}.
5678
*/

Diff for: spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/BasicRelationalConverter.java

-6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import org.springframework.data.mapping.model.ParameterValueProvider;
4141
import org.springframework.data.mapping.model.SimpleTypeHolder;
4242
import org.springframework.data.projection.EntityProjection;
43-
import org.springframework.data.projection.ProjectionFactory;
4443
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
4544
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
4645
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
@@ -133,11 +132,6 @@ public <M, D> EntityProjection<M, D> introspectProjection(Class<M> resultType, C
133132
throw new UnsupportedOperationException();
134133
}
135134

136-
@Override
137-
public ProjectionFactory getProjectionFactory() {
138-
throw new UnsupportedOperationException();
139-
}
140-
141135
@Override
142136
public <R> R project(EntityProjection<R, ?> descriptor, RowDocument document) {
143137
throw new UnsupportedOperationException();

Diff for: spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/MappingRelationalConverter.java

-5
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,6 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
124124
this.projectionFactory.setBeanClassLoader(applicationContext.getClassLoader());
125125
}
126126

127-
@Override
128-
public ProjectionFactory getProjectionFactory() {
129-
return this.projectionFactory;
130-
}
131-
132127
/**
133128
* Creates a new {@link ConversionContext}.
134129
*

Diff for: spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/RelationalConverter.java

-9
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.springframework.data.mapping.model.ParameterValueProvider;
2828
import org.springframework.data.projection.EntityProjection;
2929
import org.springframework.data.projection.EntityProjectionIntrospector;
30-
import org.springframework.data.projection.ProjectionFactory;
3130
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
3231
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
3332
import org.springframework.data.relational.domain.RowDocument;
@@ -57,14 +56,6 @@ public interface RelationalConverter {
5756
*/
5857
ConversionService getConversionService();
5958

60-
/**
61-
* Returns the {@link ProjectionFactory} for this converter.
62-
*
63-
* @return will never be {@literal null}.
64-
* @since 3.2
65-
*/
66-
ProjectionFactory getProjectionFactory();
67-
6859
/**
6960
* Introspect the given {@link Class result type} in the context of the {@link Class entity type} whether the returned
7061
* type is a projection and what property paths are participating in the projection.

0 commit comments

Comments
 (0)