DATAJDBC-107 - Polishing.
Code formatting. Added @author tag. Tiny code simplifications.
This commit is contained in:
@@ -26,12 +26,14 @@ import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty;
|
||||
import org.springframework.data.mapping.model.Property;
|
||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* Meta data about a property to be used by repository implementations.
|
||||
*
|
||||
* @author Jens Schauder
|
||||
* @author Greg Turnquist
|
||||
* @since 2.0
|
||||
*/
|
||||
public class BasicJdbcPersistentProperty extends AnnotationBasedPersistentProperty<JdbcPersistentProperty>
|
||||
@@ -52,11 +54,15 @@ public class BasicJdbcPersistentProperty extends AnnotationBasedPersistentProper
|
||||
* @param property must not be {@literal null}.
|
||||
* @param owner must not be {@literal null}.
|
||||
* @param simpleTypeHolder must not be {@literal null}.
|
||||
* @param context
|
||||
* @param context must not be {@literal null}
|
||||
*/
|
||||
public BasicJdbcPersistentProperty(Property property, PersistentEntity<?, JdbcPersistentProperty> owner,
|
||||
SimpleTypeHolder simpleTypeHolder, JdbcMappingContext context) {
|
||||
|
||||
super(property, owner, simpleTypeHolder);
|
||||
|
||||
Assert.notNull(context, "context must not be null.");
|
||||
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.springframework.data.util.TypeInformation;
|
||||
* {@link MappingContext} implementation for JDBC.
|
||||
*
|
||||
* @author Jens Schauder
|
||||
* @author Greg Turnquist
|
||||
* @since 2.0
|
||||
*/
|
||||
public class JdbcMappingContext extends AbstractMappingContext<JdbcPersistentEntity<?>, JdbcPersistentProperty> {
|
||||
@@ -63,8 +64,6 @@ public class JdbcMappingContext extends AbstractMappingContext<JdbcPersistentEnt
|
||||
Class<?> currentType = path == null ? rootType : PropertyPaths.getLeafType(path);
|
||||
JdbcPersistentEntity<?> persistentEntity = getRequiredPersistentEntity(currentType);
|
||||
|
||||
String rootPrefix = path == null ? "" : path.toDotPath() + ".";
|
||||
|
||||
for (JdbcPersistentProperty property : persistentEntity) {
|
||||
if (property.isEntity()) {
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.data.util.TypeInformation;
|
||||
* Meta data a repository might need for implementing persistence operations for instances of type {@code T}
|
||||
*
|
||||
* @author Jens Schauder
|
||||
* @author Greg Turnquist
|
||||
* @since 2.0
|
||||
*/
|
||||
class JdbcPersistentEntityImpl<T> extends BasicPersistentEntity<T, JdbcPersistentProperty>
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
|
||||
|
||||
/**
|
||||
* @author Jens Schauder
|
||||
* @author Greg Turnquist
|
||||
* @since 2.0
|
||||
*/
|
||||
public class JdbcRepositoryFactory extends RepositoryFactorySupport {
|
||||
@@ -39,7 +40,8 @@ public class JdbcRepositoryFactory extends RepositoryFactorySupport {
|
||||
private final NamedParameterJdbcOperations jdbcOperations;
|
||||
private final ApplicationEventPublisher publisher;
|
||||
|
||||
public JdbcRepositoryFactory(NamedParameterJdbcOperations namedParameterJdbcOperations, ApplicationEventPublisher publisher, NamingStrategy namingStrategy) {
|
||||
public JdbcRepositoryFactory(NamedParameterJdbcOperations namedParameterJdbcOperations,
|
||||
ApplicationEventPublisher publisher, NamingStrategy namingStrategy) {
|
||||
|
||||
this.jdbcOperations = namedParameterJdbcOperations;
|
||||
this.publisher = publisher;
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
* repository factories via Spring configuration.
|
||||
*
|
||||
* @author Jens Schauder
|
||||
* @author Greg Turnquist
|
||||
* @since 2.0
|
||||
*/
|
||||
public class JdbcRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable> //
|
||||
@@ -47,8 +48,6 @@ public class JdbcRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extend
|
||||
"No unique NamedParameterJdbcOperation could be found, " //
|
||||
+ "nor JdbcOperations or DataSource to construct one from.";
|
||||
|
||||
private static final String NO_NAMING_STRATEGY_ERROR_MESSAGE = "No unique NamingStrategy could be found.";
|
||||
|
||||
private static final String NAMED_PARAMETER_JDBC_OPERATIONS_BEAN_NAME = "namedParameterJdbcTemplate";
|
||||
private static final String JDBC_OPERATIONS_BEAN_NAME = "jdbcTemplate";
|
||||
private static final String DATA_SOURCE_BEAN_NAME = "dataSource";
|
||||
@@ -67,23 +66,21 @@ public class JdbcRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extend
|
||||
|
||||
@Override
|
||||
protected RepositoryFactorySupport doCreateRepositoryFactory() {
|
||||
return new JdbcRepositoryFactory(findOrCreateJdbcOperations(), applicationEventPublisher, findOrCreateNamingStrategy());
|
||||
return new JdbcRepositoryFactory(findOrCreateJdbcOperations(), applicationEventPublisher,
|
||||
findOrCreateNamingStrategy());
|
||||
}
|
||||
|
||||
private NamedParameterJdbcOperations findOrCreateJdbcOperations() {
|
||||
|
||||
return Optionals
|
||||
.firstNonEmpty( //
|
||||
this::getNamedParameterJdbcOperations, //
|
||||
() -> getJdbcOperations().map(NamedParameterJdbcTemplate::new), //
|
||||
() -> getDataSource().map(NamedParameterJdbcTemplate::new)) //
|
||||
return Optionals.firstNonEmpty( //
|
||||
this::getNamedParameterJdbcOperations, //
|
||||
() -> getJdbcOperations().map(NamedParameterJdbcTemplate::new), //
|
||||
() -> getDataSource().map(NamedParameterJdbcTemplate::new)) //
|
||||
.orElseThrow(() -> new IllegalStateException(NO_NAMED_PARAMETER_JDBC_OPERATION_ERROR_MESSAGE));
|
||||
}
|
||||
|
||||
private NamingStrategy findOrCreateNamingStrategy() {
|
||||
|
||||
return getNamingStrategy()
|
||||
.orElse(new DefaultNamingStrategy());
|
||||
return getNamingStrategy().orElse(new DefaultNamingStrategy());
|
||||
}
|
||||
|
||||
private Optional<NamedParameterJdbcOperations> getNamedParameterJdbcOperations() {
|
||||
|
||||
Reference in New Issue
Block a user