DATAJDBC-130 - Polishing.
Formatting. Tiny fixes in JavaDoc. Fixed some type parameters. Replaced concrete classes with interfaces.
This commit is contained in:
committed by
Greg Turnquist
parent
f5de195768
commit
1603296385
@@ -15,12 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.jdbc.core;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.dao.NonTransientDataAccessException;
|
||||
@@ -40,6 +34,12 @@ import org.springframework.jdbc.support.GeneratedKeyHolder;
|
||||
import org.springframework.jdbc.support.KeyHolder;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
/**
|
||||
* The default {@link DataAccessStrategy} is to generate SQL statements based on meta data from the entity.
|
||||
*
|
||||
@@ -57,7 +57,7 @@ public class DefaultDataAccessStrategy implements DataAccessStrategy {
|
||||
private final DataAccessStrategy accessStrategy;
|
||||
|
||||
public DefaultDataAccessStrategy(SqlGeneratorSource sqlGeneratorSource, NamedParameterJdbcOperations operations,
|
||||
JdbcMappingContext context, DataAccessStrategy accessStrategy) {
|
||||
JdbcMappingContext context, DataAccessStrategy accessStrategy) {
|
||||
|
||||
this.sqlGeneratorSource = sqlGeneratorSource;
|
||||
this.operations = operations;
|
||||
@@ -70,7 +70,7 @@ public class DefaultDataAccessStrategy implements DataAccessStrategy {
|
||||
* Only suitable if this is the only access strategy in use.
|
||||
*/
|
||||
public DefaultDataAccessStrategy(SqlGeneratorSource sqlGeneratorSource, NamedParameterJdbcOperations operations,
|
||||
JdbcMappingContext context) {
|
||||
JdbcMappingContext context) {
|
||||
|
||||
this.sqlGeneratorSource = sqlGeneratorSource;
|
||||
this.operations = operations;
|
||||
@@ -97,7 +97,7 @@ public class DefaultDataAccessStrategy implements DataAccessStrategy {
|
||||
|
||||
boolean idValueDoesNotComeFromEntity = //
|
||||
idValue == null //
|
||||
|| additionalParameters.containsKey(idProperty.getColumnName());
|
||||
|| additionalParameters.containsKey(idProperty.getColumnName());
|
||||
|
||||
operations.update( //
|
||||
sql(domainType).getInsert(idValueDoesNotComeFromEntity, additionalParameters.keySet()), //
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
package org.springframework.data.jdbc.core;
|
||||
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.convert.ClassGeneratingEntityInstantiator;
|
||||
@@ -34,6 +31,9 @@ import org.springframework.data.mapping.model.ConvertingPropertyAccessor;
|
||||
import org.springframework.data.mapping.model.ParameterValueProvider;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Maps a ResultSet to an entity of type {@code T}, including entities referenced.
|
||||
*
|
||||
@@ -53,7 +53,7 @@ public class EntityRowMapper<T> implements RowMapper<T> {
|
||||
private final JdbcPersistentProperty idProperty;
|
||||
|
||||
public EntityRowMapper(JdbcPersistentEntity<T> entity, ConversionService conversions, JdbcMappingContext context,
|
||||
DataAccessStrategy accessStrategy) {
|
||||
DataAccessStrategy accessStrategy) {
|
||||
|
||||
this.entity = entity;
|
||||
this.conversions = conversions;
|
||||
@@ -137,9 +137,12 @@ public class EntityRowMapper<T> implements RowMapper<T> {
|
||||
|
||||
private static class ResultSetParameterValueProvider implements ParameterValueProvider<JdbcPersistentProperty> {
|
||||
|
||||
@NonNull private final ResultSet resultSet;
|
||||
@NonNull private final ConversionService conversionService;
|
||||
@NonNull private final String prefix;
|
||||
@NonNull
|
||||
private final ResultSet resultSet;
|
||||
@NonNull
|
||||
private final ConversionService conversionService;
|
||||
@NonNull
|
||||
private final String prefix;
|
||||
|
||||
private ResultSetParameterValueProvider(ResultSet resultSet, ConversionService conversionService, String prefix) {
|
||||
|
||||
@@ -149,7 +152,7 @@ public class EntityRowMapper<T> implements RowMapper<T> {
|
||||
}
|
||||
|
||||
public static ResultSetParameterValueProvider of(ResultSet resultSet, ConversionService conversionService,
|
||||
String prefix) {
|
||||
String prefix) {
|
||||
return new ResultSetParameterValueProvider(resultSet, conversionService, prefix);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,16 +15,16 @@
|
||||
*/
|
||||
package org.springframework.data.jdbc.core;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.convert.converter.ConditionalConverter;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* A converter for creating a {@link Map} from an {@link Iterable<Map.Entry>}.
|
||||
*
|
||||
@@ -36,7 +36,7 @@ class IterableOfEntryToMapConverter implements ConditionalConverter, Converter<I
|
||||
@Override
|
||||
public Map convert(Iterable source) {
|
||||
|
||||
HashMap result = new HashMap();
|
||||
Map result = new HashMap();
|
||||
|
||||
source.forEach(element -> {
|
||||
|
||||
|
||||
@@ -15,14 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.jdbc.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcMappingContext;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcPersistentEntity;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcPersistentProperty;
|
||||
@@ -33,6 +25,14 @@ import org.springframework.data.util.Lazy;
|
||||
import org.springframework.data.util.StreamUtils;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Generates SQL statements to be used by {@link SimpleJdbcRepository}
|
||||
*
|
||||
@@ -169,7 +169,7 @@ class SqlGenerator {
|
||||
if (!property.isEntity() //
|
||||
|| Collection.class.isAssignableFrom(property.getType()) //
|
||||
|| Map.class.isAssignableFrom(property.getType()) //
|
||||
) {
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ public class JdbcEntityWriter extends JdbcEntityWriterSupport {
|
||||
}
|
||||
|
||||
private void saveReferencedEntities(PropertyAndValue propertyAndValue, AggregateChange aggregateChange,
|
||||
JdbcPropertyPath propertyPath, DbAction dependingOn) {
|
||||
JdbcPropertyPath propertyPath, DbAction dependingOn) {
|
||||
|
||||
saveActions(propertyAndValue, propertyPath, dependingOn).forEach(a -> {
|
||||
|
||||
@@ -88,7 +88,7 @@ public class JdbcEntityWriter extends JdbcEntityWriterSupport {
|
||||
}
|
||||
|
||||
private Stream<DbAction> saveActions(PropertyAndValue propertyAndValue, JdbcPropertyPath propertyPath,
|
||||
DbAction dependingOn) {
|
||||
DbAction dependingOn) {
|
||||
|
||||
if (Map.Entry.class.isAssignableFrom(ClassUtils.getUserClass(propertyAndValue.value))) {
|
||||
return mapEntrySaveAction(propertyAndValue, propertyPath, dependingOn);
|
||||
@@ -98,7 +98,7 @@ public class JdbcEntityWriter extends JdbcEntityWriterSupport {
|
||||
}
|
||||
|
||||
private Stream<DbAction> mapEntrySaveAction(PropertyAndValue propertyAndValue, JdbcPropertyPath propertyPath,
|
||||
DbAction dependingOn) {
|
||||
DbAction dependingOn) {
|
||||
|
||||
Map.Entry<Object, Object> entry = (Map.Entry) propertyAndValue.value;
|
||||
|
||||
@@ -117,7 +117,7 @@ public class JdbcEntityWriter extends JdbcEntityWriterSupport {
|
||||
}
|
||||
|
||||
private void insertReferencedEntities(PropertyAndValue propertyAndValue, AggregateChange aggregateChange,
|
||||
JdbcPropertyPath propertyPath, DbAction dependingOn) {
|
||||
JdbcPropertyPath propertyPath, DbAction dependingOn) {
|
||||
|
||||
Insert<Object> insert;
|
||||
if (propertyAndValue.property.isQualified()) {
|
||||
@@ -143,7 +143,7 @@ public class JdbcEntityWriter extends JdbcEntityWriterSupport {
|
||||
.flatMap( //
|
||||
p -> referencedEntity(p, persistentEntity.getPropertyAccessor(o)) //
|
||||
.map(e -> new PropertyAndValue(p, e)) //
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
private Stream<Object> referencedEntity(JdbcPersistentProperty p, PersistentPropertyAccessor propertyAccessor) {
|
||||
@@ -174,7 +174,7 @@ public class JdbcEntityWriter extends JdbcEntityWriterSupport {
|
||||
}
|
||||
|
||||
private Stream<Object> collectionPropertyAsStream(JdbcPersistentProperty p,
|
||||
PersistentPropertyAccessor propertyAccessor) {
|
||||
PersistentPropertyAccessor propertyAccessor) {
|
||||
|
||||
Object property = propertyAccessor.getProperty(p);
|
||||
|
||||
|
||||
@@ -52,13 +52,13 @@ public class BasicJdbcPersistentProperty extends AnnotationBasedPersistentProper
|
||||
/**
|
||||
* Creates a new {@link AnnotationBasedPersistentProperty}.
|
||||
*
|
||||
* @param property must not be {@literal null}.
|
||||
* @param owner must not be {@literal null}.
|
||||
* @param property must not be {@literal null}.
|
||||
* @param owner must not be {@literal null}.
|
||||
* @param simpleTypeHolder must not be {@literal null}.
|
||||
* @param context must not be {@literal null}
|
||||
* @param context must not be {@literal null}
|
||||
*/
|
||||
public BasicJdbcPersistentProperty(Property property, PersistentEntity<?, JdbcPersistentProperty> owner,
|
||||
SimpleTypeHolder simpleTypeHolder, JdbcMappingContext context) {
|
||||
SimpleTypeHolder simpleTypeHolder, JdbcMappingContext context) {
|
||||
|
||||
super(property, owner, simpleTypeHolder);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user