Skip to content

Commit

Permalink
Cleanup no longer required code.
Browse files Browse the repository at this point in the history
  • Loading branch information
mp911de committed Sep 20, 2023
1 parent 88efea0 commit a9f8680
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 401 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@
*/
package org.springframework.data.jdbc.core.convert;

import java.sql.Array;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

import org.springframework.data.relational.core.mapping.AggregatePath;
import org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.domain.RowDocument;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.lang.Nullable;

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

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

RowDocument document = toRowDocument(resultSet);
RowDocument document = RowDocumentResultSetExtractor.toRowDocument(resultSet);

// TODO: Remove mapRow methods.
if (true) {
return path == null //
? converter.readAndResolve(entity.getType(), document) //
: converter.readAndResolve(entity.getType(), document, identifier);
}

return path == null //
? converter.mapRow(entity, resultSet, rowNumber) //
: converter.mapRow(path, resultSet, identifier, rowNumber);
return identifier == null //
? converter.readAndResolve(entity.getType(), document) //
: converter.readAndResolve(entity.getType(), document, identifier);
}

/**
* Create a {@link RowDocument} from the current {@link ResultSet} row.
*
* @param resultSet must not be {@literal null}.
* @return
* @throws SQLException
*/
static RowDocument toRowDocument(ResultSet resultSet) throws SQLException {

ResultSetMetaData md = resultSet.getMetaData();
int columnCount = md.getColumnCount();
RowDocument document = new RowDocument(columnCount);

for (int i = 0; i < columnCount; i++) {
Object rsv = JdbcUtils.getResultSetValue(resultSet, i + 1);
String columnName = md.getColumnLabel(i + 1);
document.put(columnName, rsv instanceof Array a ? a.getArray() : rsv);
}

return document;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
package org.springframework.data.jdbc.core.convert;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLType;

import org.springframework.data.jdbc.core.mapping.JdbcValue;
import org.springframework.data.projection.EntityProjection;
import org.springframework.data.relational.core.conversion.RelationalConverter;
import org.springframework.data.relational.core.mapping.AggregatePath;
import org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
Expand Down Expand Up @@ -58,8 +57,16 @@ public interface JdbcConverter extends RelationalConverter {
* @param key primary key.
* @param <T>
* @return
* @deprecated since 3.2, use {@link #readAndResolve(Class, RowDocument, Identifier)} instead.
*/
<T> T mapRow(RelationalPersistentEntity<T> entity, ResultSet resultSet, Object key);
@Deprecated(since = "3.2")
default <T> T mapRow(RelationalPersistentEntity<T> entity, ResultSet resultSet, Object key) {
try {
return readAndResolve(entity.getType(), RowDocumentResultSetExtractor.toRowDocument(resultSet));
} catch (SQLException e) {
throw new RuntimeException(e);
}
}

/**
* Read the current row from {@link ResultSet} to an {@link PersistentPropertyPathExtension#getActualType() entity}.
Expand All @@ -70,39 +77,19 @@ public interface JdbcConverter extends RelationalConverter {
* @param key primary key.
* @param <T>
* @return
* @deprecated use {@link #mapRow(AggregatePath, ResultSet, Identifier, Object)} instead.
* @deprecated use {@link #readAndResolve(Class, RowDocument, Identifier)} instead.
*/
@SuppressWarnings("unchecked")
@Deprecated(since = "3.2", forRemoval = true)
default <T> T mapRow(PersistentPropertyPathExtension path, ResultSet resultSet, Identifier identifier, Object key) {
return mapRow(path.getAggregatePath(), resultSet, identifier, key);
try {
return (T) readAndResolve(path.getRequiredLeafEntity().getType(),
RowDocumentResultSetExtractor.toRowDocument(resultSet), identifier);
} catch (SQLException e) {
throw new RuntimeException(e);
}
};

/**
* Read the current row from {@link ResultSet} to an {@link AggregatePath#getLeafEntity()} entity}.
*
* @param path path to the owning property.
* @param resultSet the {@link ResultSet} to read from.
* @param identifier entity identifier.
* @param key primary key.
* @param <T>
* @return
*/
<T> T mapRow(AggregatePath path, ResultSet resultSet, Identifier identifier, Object key);

/**
* Apply a projection to {@link RowDocument} and return the projection return type {@code R}.
* {@link EntityProjection#isProjection() Non-projecting} descriptors fall back to {@link #read(Class, RowDocument)
* regular object materialization}.
*
* @param descriptor the projection descriptor, must not be {@literal null}.
* @param document must not be {@literal null}.
* @param <R>
* @return a new instance of the projection return type {@code R}.
* @since 3.2
* @see #project(EntityProjection, RowDocument)
*/
<R> R projectAndResolve(EntityProjection<R, ?> descriptor, RowDocument document);

/**
* Read a {@link RowDocument} into the requested {@link Class aggregate type} and resolve references by looking these
* up from {@link RelationResolver}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,11 @@ public Map.Entry<Object, T> mapRow(ResultSet rs, int rowNum) throws SQLException
return new HashMap.SimpleEntry<>(key, mapEntity(rs, key));
}

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

if (true) {
RowDocument document = EntityRowMapper.toRowDocument(resultSet);
return (T) converter.readAndResolve(path.getLeafEntity().getType(), document,
identifier.withPart(keyColumn, key, Object.class));
}

return converter.mapRow(path, resultSet, identifier, key);
RowDocument document = RowDocumentResultSetExtractor.toRowDocument(resultSet);
return (T) converter.readAndResolve(path.getLeafEntity().getType(), document,
identifier.withPart(keyColumn, key, Object.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@ class RowDocumentResultSetExtractor {
this.propertyToColumn = propertyToColumn;
}

/**
* Create a {@link RowDocument} from the current {@link ResultSet} row.
*
* @param resultSet must not be {@literal null}.
* @return
* @throws SQLException
*/
static RowDocument toRowDocument(ResultSet resultSet) throws SQLException {

ResultSetMetaData md = resultSet.getMetaData();
int columnCount = md.getColumnCount();
RowDocument document = new RowDocument(columnCount);

for (int i = 0; i < columnCount; i++) {
Object rsv = JdbcUtils.getResultSetValue(resultSet, i + 1);
String columnName = md.getColumnLabel(i + 1);
document.put(columnName, rsv instanceof Array a ? a.getArray() : rsv);
}

return document;
}

/**
* Adapter to extract values and column metadata from a {@link ResultSet}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.springframework.data.mapping.model.ParameterValueProvider;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.projection.EntityProjection;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
Expand Down Expand Up @@ -133,11 +132,6 @@ public <M, D> EntityProjection<M, D> introspectProjection(Class<M> resultType, C
throw new UnsupportedOperationException();
}

@Override
public ProjectionFactory getProjectionFactory() {
throw new UnsupportedOperationException();
}

@Override
public <R> R project(EntityProjection<R, ?> descriptor, RowDocument document) {
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,6 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
this.projectionFactory.setBeanClassLoader(applicationContext.getClassLoader());
}

@Override
public ProjectionFactory getProjectionFactory() {
return this.projectionFactory;
}

/**
* Creates a new {@link ConversionContext}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.springframework.data.mapping.model.ParameterValueProvider;
import org.springframework.data.projection.EntityProjection;
import org.springframework.data.projection.EntityProjectionIntrospector;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.domain.RowDocument;
Expand Down Expand Up @@ -57,14 +56,6 @@ public interface RelationalConverter {
*/
ConversionService getConversionService();

/**
* Returns the {@link ProjectionFactory} for this converter.
*
* @return will never be {@literal null}.
* @since 3.2
*/
ProjectionFactory getProjectionFactory();

/**
* Introspect the given {@link Class result type} in the context of the {@link Class entity type} whether the returned
* type is a projection and what property paths are participating in the projection.
Expand Down

0 comments on commit a9f8680

Please sign in to comment.