DATAJDBC-272 - Split Spring Data JDBC project into modules.

This commit is contained in:
Mark Paluch
2018-10-11 16:13:25 +02:00
committed by Jens Schauder
parent 44fbba42ee
commit 6a60c53602
199 changed files with 989 additions and 210 deletions

130
pom.xml
View File

@@ -5,11 +5,12 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jdbc</artifactId>
<artifactId>spring-data-relational-parent</artifactId>
<version>1.1.0.BUILD-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Spring Data JDBC</name>
<description>Spring Data module for JDBC repositories.</description>
<name>Spring Data Relational</name>
<description>Spring Data module for Relational repositories.</description>
<url>http://projects.spring.io/spring-data-jdbc</url>
<parent>
@@ -40,6 +41,11 @@
<inceptionYear>2017</inceptionYear>
<modules>
<module>spring-data-relational</module>
<module>spring-data-jdbc</module>
</modules>
<developers>
<developer>
<id>schauder</id>
@@ -167,124 +173,6 @@
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>spring-data-commons</artifactId>
<version>${springdata.commons}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${mybatis-spring.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>${hsqldb.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj-core.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-connector-java.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>${mariadb-java-client.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.schauderhaft.degraph</groupId>
<artifactId>degraph-check</artifactId>
<version>${degraph-check.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mysql</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mariadb</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>

207
spring-data-jdbc/pom.xml Normal file
View File

@@ -0,0 +1,207 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-data-jdbc</artifactId>
<version>1.1.0.BUILD-SNAPSHOT</version>
<name>Spring Data JDBC</name>
<description>Spring Data module for JDBC repositories.</description>
<url>http://projects.spring.io/spring-data-jdbc</url>
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>1.1.0.BUILD-SNAPSHOT</version>
</parent>
<properties>
<dist.key>DATAJDBC</dist.key>
<springdata.commons>2.2.0.BUILD-SNAPSHOT</springdata.commons>
<java-module-name>spring.data.jdbc</java-module-name>
<hsqldb.version>2.2.8</hsqldb.version>
<mybatis.version>3.4.6</mybatis.version>
<mybatis-spring.version>1.3.2</mybatis-spring.version>
<mysql-connector-java.version>5.1.41</mysql-connector-java.version>
<postgresql.version>42.0.0</postgresql.version>
<mariadb-java-client.version>2.2.3</mariadb-java-client.version>
</properties>
<inceptionYear>2017</inceptionYear>
<developers>
<developer>
<id>schauder</id>
<name>Jens Schauder</name>
<email>jschauder(at)pivotal.io</email>
<organization>Pivotal Software, Inc.</organization>
<organizationUrl>https://pivotal.io</organizationUrl>
<roles>
<role>Project Lead</role>
</roles>
<timezone>+1</timezone>
</developer>
<developer>
<id>gregturn</id>
<name>Greg L. Turnquist</name>
<email>gturnquist(at)pivotal.io</email>
<organization>Pivotal Software, Inc.</organization>
<organizationUrl>https://pivotal.io</organizationUrl>
<roles>
<role>Project Contributor</role>
</roles>
<timezone>-6</timezone>
</developer>
<developer>
<id>ogierke</id>
<name>Oliver Gierke</name>
<email>ogierke(at)pivotal.io</email>
<organization>Pivotal Software, Inc.</organization>
<organizationUrl>https://pivotal.io</organizationUrl>
<roles>
<role>Project Contributor</role>
</roles>
<timezone>+1</timezone>
</developer>
<developer>
<id>mpaluch</id>
<name>Mark Paluch</name>
<email>mpaluch(at)pivotal.io</email>
<organization>Pivotal Software, Inc.</organization>
<organizationUrl>https://pivotal.io</organizationUrl>
<roles>
<role>Project Contributor</role>
</roles>
<timezone>+1</timezone>
</developer>
</developers>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>spring-data-relational</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>spring-data-commons</artifactId>
<version>${springdata.commons}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${mybatis-spring.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>${hsqldb.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj-core.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-connector-java.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>${mariadb-java-client.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.schauderhaft.degraph</groupId>
<artifactId>degraph-check</artifactId>
<version>${degraph-check.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mysql</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mariadb</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,109 @@
/*
* Copyright 2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.jdbc.core.convert;
import org.springframework.data.convert.CustomConversions;
import org.springframework.data.jdbc.core.mapping.AggregateReference;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.relational.core.conversion.BasicRelationalConverter;
import org.springframework.data.relational.core.conversion.RelationalConverter;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
/**
* {@link RelationalConverter} that uses a {@link MappingContext} to apply basic conversion of relational values to
* property values.
* <p>
* Conversion is configurable by providing a customized {@link CustomConversions}.
*
* @author Mark Paluch
* @author Jens Schauder
* @see MappingContext
* @see SimpleTypeHolder
* @see CustomConversions
*/
public class BasicJdbcConverter extends BasicRelationalConverter {
/**
* Creates a new {@link BasicRelationalConverter} given {@link MappingContext}.
*
* @param context must not be {@literal null}. org.springframework.data.jdbc.core.DefaultDataAccessStrategyUnitTests
*/
public BasicJdbcConverter(
MappingContext<? extends RelationalPersistentEntity<?>, ? extends RelationalPersistentProperty> context) {
super(context);
}
/**
* Creates a new {@link BasicRelationalConverter} given {@link MappingContext} and {@link CustomConversions}.
*
* @param context must not be {@literal null}.
* @param conversions must not be {@literal null}.
*/
public BasicJdbcConverter(
MappingContext<? extends RelationalPersistentEntity<?>, ? extends RelationalPersistentProperty> context,
CustomConversions conversions) {
super(context, conversions);
}
/*
* (non-Javadoc)
* @see org.springframework.data.relational.core.conversion.RelationalConverter#readValue(java.lang.Object, org.springframework.data.util.TypeInformation)
*/
@Override
@Nullable
public Object readValue(@Nullable Object value, TypeInformation<?> type) {
if (null == value) {
return null;
}
if (getConversions().hasCustomReadTarget(value.getClass(), type.getType())) {
return getConversionService().convert(value, type.getType());
}
if (AggregateReference.class.isAssignableFrom(type.getType())) {
TypeInformation<?> idType = type.getSuperTypeInformation(AggregateReference.class).getTypeArguments().get(1);
return AggregateReference.to(readValue(value, idType));
}
return super.readValue(value, type);
}
/*
* (non-Javadoc)
* @see org.springframework.data.relational.core.conversion.RelationalConverter#writeValue(java.lang.Object, org.springframework.data.util.TypeInformation)
*/
@Override
@Nullable
public Object writeValue(@Nullable Object value, TypeInformation<?> type) {
if (value == null) {
return null;
}
if (AggregateReference.class.isAssignableFrom(value.getClass())) {
return writeValue(((AggregateReference) value).getId(), type);
}
return super.writeValue(value, type);
}
}

View File

@@ -0,0 +1,54 @@
/*
* Copyright 2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.jdbc.core.mapping;
import org.springframework.data.jdbc.support.JdbcUtil;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.model.Property;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.relational.core.mapping.BasicRelationalPersistentProperty;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
/**
* @author Mark Paluch
*/
public class BasicJdbcPersistentProperty extends BasicRelationalPersistentProperty {
/**
* Creates a new {@link BasicJdbcPersistentProperty}.
*
* @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}
*/
public BasicJdbcPersistentProperty(Property property, PersistentEntity<?, RelationalPersistentProperty> owner,
SimpleTypeHolder simpleTypeHolder, RelationalMappingContext context) {
super(property, owner, simpleTypeHolder, context);
}
@Override
public int getSqlType() {
return JdbcUtil.sqlTypeFor(getColumnType());
}
@Override
public boolean isReference() {
return AggregateReference.class.isAssignableFrom(getRawType());
}
}

View File

@@ -0,0 +1,68 @@
/*
* Copyright 2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.jdbc.core.mapping;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.model.Property;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.relational.core.mapping.NamingStrategy;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.util.TypeInformation;
/**
* {@link MappingContext} implementation for JDBC.
*
* @author Jens Schauder
* @author Greg Turnquist
* @author Kazuki Shimizu
* @author Oliver Gierke
* @author Mark Paluch
*/
public class JdbcMappingContext extends RelationalMappingContext {
/**
* Creates a new {@link JdbcMappingContext}.
*/
public JdbcMappingContext() {
super();
}
/**
* Creates a new {@link JdbcMappingContext} using the given {@link NamingStrategy}.
*
* @param namingStrategy must not be {@literal null}.
*/
public JdbcMappingContext(NamingStrategy namingStrategy) {
super(namingStrategy);
}
/*
* (non-Javadoc)
* @see org.springframework.data.mapping.context.AbstractMappingContext#createPersistentProperty(org.springframework.data.mapping.model.Property, org.springframework.data.mapping.model.MutablePersistentEntity, org.springframework.data.mapping.model.SimpleTypeHolder)
*/
@Override
protected RelationalPersistentProperty createPersistentProperty(Property property,
RelationalPersistentEntity<?> owner, SimpleTypeHolder simpleTypeHolder) {
return new BasicJdbcPersistentProperty(property, owner, simpleTypeHolder, this);
}
@Override
protected boolean shouldCreatePersistentEntityFor(TypeInformation<?> type) {
return super.shouldCreatePersistentEntityFor(type) && !AggregateReference.class.isAssignableFrom(type.getType());
}
}

View File

@@ -20,7 +20,9 @@ import java.util.Optional;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.jdbc.core.convert.BasicJdbcConverter;
import org.springframework.data.jdbc.core.convert.JdbcCustomConversions;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.relational.core.conversion.BasicRelationalConverter;
import org.springframework.data.relational.core.conversion.RelationalConverter;
import org.springframework.data.relational.core.mapping.NamingStrategy;
@@ -45,9 +47,9 @@ public class JdbcConfiguration {
* @return must not be {@literal null}.
*/
@Bean
protected RelationalMappingContext jdbcMappingContext(Optional<NamingStrategy> namingStrategy) {
protected JdbcMappingContext jdbcMappingContext(Optional<NamingStrategy> namingStrategy) {
RelationalMappingContext mappingContext = new RelationalMappingContext(
JdbcMappingContext mappingContext = new JdbcMappingContext(
namingStrategy.orElse(NamingStrategy.INSTANCE));
mappingContext.setSimpleTypeHolder(jdbcCustomConversions().getSimpleTypeHolder());
@@ -64,7 +66,7 @@ public class JdbcConfiguration {
*/
@Bean
protected RelationalConverter relationalConverter(RelationalMappingContext mappingContext) {
return new BasicRelationalConverter(mappingContext, jdbcCustomConversions());
return new BasicJdbcConverter(mappingContext, jdbcCustomConversions());
}
/**

View File

@@ -33,6 +33,7 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.convert.ReadingConverter;
import org.springframework.data.convert.WritingConverter;
import org.springframework.data.jdbc.core.convert.JdbcCustomConversions;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.relational.core.conversion.BasicRelationalConverter;
import org.springframework.data.relational.core.conversion.RelationalConverter;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
@@ -52,7 +53,7 @@ public class DefaultDataAccessStrategyUnitTests {
public static final long ORIGINAL_ID = 4711L;
NamedParameterJdbcOperations jdbcOperations = mock(NamedParameterJdbcOperations.class);
RelationalMappingContext context = new RelationalMappingContext();
RelationalMappingContext context = new JdbcMappingContext();
RelationalConverter converter = new BasicRelationalConverter(context, new JdbcCustomConversions());
HashMap<String, Object> additionalParameters = new HashMap<>();
ArgumentCaptor<SqlParameterSource> paramSourceCaptor = ArgumentCaptor.forClass(SqlParameterSource.class);

View File

@@ -25,6 +25,7 @@ import java.util.Map;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.springframework.data.annotation.Id;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.relational.core.conversion.DbAction.Insert;
import org.springframework.data.relational.core.conversion.DbAction.InsertRoot;
import org.springframework.data.relational.core.mapping.NamingStrategy;
@@ -41,7 +42,7 @@ public class DefaultJdbcInterpreterUnitTests {
static final long CONTAINER_ID = 23L;
static final String BACK_REFERENCE = "back-reference";
RelationalMappingContext context = new RelationalMappingContext(new NamingStrategy() {
RelationalMappingContext context = new JdbcMappingContext(new NamingStrategy() {
@Override
public String getReverseColumnName(RelationalPersistentProperty property) {
return BACK_REFERENCE;

View File

@@ -42,6 +42,7 @@ import org.mockito.stubbing.Answer;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.jdbc.core.convert.JdbcCustomConversions;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.relational.core.conversion.BasicRelationalConverter;
import org.springframework.data.relational.core.conversion.RelationalConverter;
import org.springframework.data.relational.core.mapping.NamingStrategy;
@@ -207,7 +208,7 @@ public class EntityRowMapperUnitTests {
private <T> EntityRowMapper<T> createRowMapper(Class<T> type, NamingStrategy namingStrategy) {
RelationalMappingContext context = new RelationalMappingContext(namingStrategy);
RelationalMappingContext context = new JdbcMappingContext(namingStrategy);
DataAccessStrategy accessStrategy = mock(DataAccessStrategy.class);

View File

@@ -26,6 +26,7 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.jdbc.mybatis.MyBatisContext;
import org.springframework.data.jdbc.mybatis.MyBatisDataAccessStrategy;
import org.springframework.data.mapping.PersistentPropertyPath;
@@ -39,7 +40,7 @@ import org.springframework.data.relational.core.mapping.RelationalPersistentProp
*/
public class MyBatisDataAccessStrategyUnitTests {
RelationalMappingContext context = new RelationalMappingContext();
RelationalMappingContext context = new JdbcMappingContext();
SqlSession session = mock(SqlSession.class);
ArgumentCaptor<MyBatisContext> captor = ArgumentCaptor.forClass(MyBatisContext.class);

View File

@@ -25,6 +25,7 @@ import java.util.function.Consumer;
import org.assertj.core.api.SoftAssertions;
import org.junit.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.jdbc.core.mapping.PersistentPropertyPathTestUtils;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.relational.core.mapping.NamingStrategy;
@@ -41,7 +42,7 @@ import org.springframework.data.relational.core.mapping.RelationalPersistentProp
*/
public class SqlGeneratorContextBasedNamingStrategyUnitTests {
RelationalMappingContext context = new RelationalMappingContext();
RelationalMappingContext context = new JdbcMappingContext();
ThreadLocal<String> userHandler = new ThreadLocal<>();
/**
@@ -207,7 +208,7 @@ public class SqlGeneratorContextBasedNamingStrategyUnitTests {
*/
private SqlGenerator configureSqlGenerator(NamingStrategy namingStrategy) {
RelationalMappingContext context = new RelationalMappingContext(namingStrategy);
RelationalMappingContext context = new JdbcMappingContext(namingStrategy);
RelationalPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(DummyEntity.class);
return new SqlGenerator(context, persistentEntity, new SqlGeneratorSource(context));

View File

@@ -20,13 +20,13 @@ import static org.assertj.core.api.Assertions.*;
import org.assertj.core.api.SoftAssertions;
import org.junit.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.jdbc.core.mapping.PersistentPropertyPathTestUtils;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.mapping.PropertyPath;
import org.springframework.data.relational.core.mapping.NamingStrategy;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.core.mapping.NamingStrategy;
/**
* Unit tests the {@link SqlGenerator} with a fixed {@link NamingStrategy} implementation containing a hard wired
@@ -67,7 +67,7 @@ public class SqlGeneratorFixedNamingStrategyUnitTests {
}
};
private RelationalMappingContext context = new RelationalMappingContext();
private RelationalMappingContext context = new JdbcMappingContext();
@Test // DATAJDBC-107
public void findOneWithOverriddenFixedTableName() {
@@ -187,7 +187,7 @@ public class SqlGeneratorFixedNamingStrategyUnitTests {
*/
private SqlGenerator configureSqlGenerator(NamingStrategy namingStrategy) {
RelationalMappingContext context = new RelationalMappingContext(namingStrategy);
RelationalMappingContext context = new JdbcMappingContext(namingStrategy);
RelationalPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(DummyEntity.class);
return new SqlGenerator(context, persistentEntity, new SqlGeneratorSource(context));
}

View File

@@ -26,6 +26,7 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.jdbc.core.mapping.AggregateReference;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.jdbc.core.mapping.PersistentPropertyPathTestUtils;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.relational.core.mapping.NamingStrategy;
@@ -42,7 +43,7 @@ import org.springframework.data.relational.core.mapping.RelationalPersistentProp
public class SqlGeneratorUnitTests {
private SqlGenerator sqlGenerator;
private RelationalMappingContext context = new RelationalMappingContext();
private RelationalMappingContext context = new JdbcMappingContext();
@Before
public void setUp() {
@@ -53,7 +54,7 @@ public class SqlGeneratorUnitTests {
SqlGenerator createSqlGenerator(Class<?> type) {
NamingStrategy namingStrategy = new PrefixingNamingStrategy();
RelationalMappingContext context = new RelationalMappingContext(namingStrategy);
RelationalMappingContext context = new JdbcMappingContext(namingStrategy);
RelationalPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(type);
return new SqlGenerator(context, persistentEntity, new SqlGeneratorSource(context));

View File

@@ -13,17 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.relational.core.conversion;
package org.springframework.data.jdbc.core.convert;
import static org.assertj.core.api.Assertions.*;
import org.assertj.core.api.Assertions;
import org.assertj.core.api.SoftAssertions;
import org.junit.Test;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.data.annotation.Id;
import org.springframework.data.jdbc.core.mapping.AggregateReference;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.relational.core.conversion.RelationalConverter;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.util.ClassTypeInformation;
@@ -40,8 +42,8 @@ public class BasicRelationalConverterAggregateReferenceUnitTests {
ConversionService conversionService = new DefaultConversionService();
RelationalMappingContext context = new RelationalMappingContext();
RelationalConverter converter = new BasicRelationalConverter(context);
JdbcMappingContext context = new JdbcMappingContext();
RelationalConverter converter = new BasicJdbcConverter(context);
RelationalPersistentEntity<?> entity = context.getRequiredPersistentEntity(DummyEntity.class);
@@ -52,7 +54,7 @@ public class BasicRelationalConverterAggregateReferenceUnitTests {
Object readValue = converter.readValue(23, property.getTypeInformation());
assertThat(readValue).isInstanceOf(AggregateReference.class);
Assertions.assertThat(readValue).isInstanceOf(AggregateReference.class);
assertThat(((AggregateReference<DummyEntity, Long>) readValue).getId()).isEqualTo(23L);
}
@@ -65,7 +67,7 @@ public class BasicRelationalConverterAggregateReferenceUnitTests {
Object writeValue = converter.writeValue(reference, ClassTypeInformation.from(property.getColumnType()));
assertThat(writeValue).isEqualTo(23L);
Assertions.assertThat(writeValue).isEqualTo(23L);
}
private static class DummyEntity {

View File

@@ -0,0 +1,163 @@
/*
* Copyright 2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.jdbc.core.mapping;
import static org.assertj.core.api.Assertions.*;
import lombok.Data;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import org.assertj.core.api.SoftAssertions;
import org.junit.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.mapping.PropertyHandler;
import org.springframework.data.relational.core.mapping.BasicRelationalPersistentProperty;
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
/**
* Unit tests for the {@link BasicRelationalPersistentProperty}.
*
* @author Jens Schauder
* @author Oliver Gierke
* @author Florian Lüdiger
*/
public class BasicJdbcPersistentPropertyUnitTests {
RelationalMappingContext context = new JdbcMappingContext();
RelationalPersistentEntity<?> entity = context.getRequiredPersistentEntity(DummyEntity.class);
@Test // DATAJDBC-104
public void enumGetsStoredAsString() {
RelationalPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(DummyEntity.class);
entity.doWithProperties((PropertyHandler<RelationalPersistentProperty>) p -> {
switch (p.getName()) {
case "someEnum":
assertThat(p.getColumnType()).isEqualTo(String.class);
break;
case "localDateTime":
assertThat(p.getColumnType()).isEqualTo(Date.class);
break;
case "zonedDateTime":
assertThat(p.getColumnType()).isEqualTo(String.class);
break;
default:
}
});
}
@Test // DATAJDBC-104, DATAJDBC-1384
public void testTargetTypesForPropertyType() {
SoftAssertions softly = new SoftAssertions();
RelationalPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(DummyEntity.class);
checkTargetType(softly, persistentEntity, "someEnum", String.class);
checkTargetType(softly, persistentEntity, "localDateTime", Date.class);
checkTargetType(softly, persistentEntity, "zonedDateTime", String.class);
checkTargetType(softly, persistentEntity, "uuid", UUID.class);
softly.assertAll();
}
@Test // DATAJDBC-106
public void detectsAnnotatedColumnName() {
RelationalPersistentEntity<?> entity = context.getRequiredPersistentEntity(DummyEntity.class);
assertThat(entity.getRequiredPersistentProperty("name").getColumnName()).isEqualTo("dummy_name");
assertThat(entity.getRequiredPersistentProperty("localDateTime").getColumnName())
.isEqualTo("dummy_last_updated_at");
}
@Test // DATAJDBC-218
public void detectsAnnotatedColumnAndKeyName() {
RelationalPersistentProperty listProperty = context //
.getRequiredPersistentEntity(DummyEntity.class) //
.getRequiredPersistentProperty("someList");
assertThat(listProperty.getReverseColumnName()).isEqualTo("dummy_column_name");
assertThat(listProperty.getKeyColumn()).isEqualTo("dummy_key_column_name");
}
@Test // DATAJDBC-221
public void referencesAreNotEntitiesAndGetStoredAsTheirId() {
SoftAssertions softly = new SoftAssertions();
RelationalPersistentProperty reference = entity.getRequiredPersistentProperty("reference");
softly.assertThat(reference.isEntity()).isFalse();
softly.assertThat(reference.getColumnType()).isEqualTo(Long.class);
softly.assertAll();
}
private void checkTargetType(SoftAssertions softly, RelationalPersistentEntity<?> persistentEntity,
String propertyName, Class<?> expected) {
RelationalPersistentProperty property = persistentEntity.getRequiredPersistentProperty(propertyName);
softly.assertThat(property.getColumnType()).describedAs(propertyName).isEqualTo(expected);
}
@Data
@SuppressWarnings("unused")
private static class DummyEntity {
@Id private final Long id;
private final SomeEnum someEnum;
private final LocalDateTime localDateTime;
private final ZonedDateTime zonedDateTime;
private final AggregateReference<DummyEntity, Long> reference;
private final List<String> listField;
private final UUID uuid;
@Column(value = "dummy_column_name", keyColumn = "dummy_key_column_name") private List<Integer> someList;
// DATACMNS-106
private @Column("dummy_name") String name;
@Column("dummy_last_updated_at")
public LocalDateTime getLocalDateTime() {
return localDateTime;
}
public void setListSetter(Integer integer) {
}
public List<Date> getListGetter() {
return null;
}
}
@SuppressWarnings("unused")
private enum SomeEnum {
ALPHA
}
}

View File

@@ -24,8 +24,8 @@ import java.util.List;
import org.junit.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.relational.core.mapping.NamingStrategy;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
/**
@@ -40,7 +40,7 @@ public class NamingStrategyUnitTests {
private final NamingStrategy target = NamingStrategy.INSTANCE;
private final RelationalPersistentEntity<?> persistentEntity = //
new RelationalMappingContext(target).getRequiredPersistentEntity(DummyEntity.class);
new JdbcMappingContext(target).getRequiredPersistentEntity(DummyEntity.class);
@Test // DATAJDBC-184
public void getTableName() {

View File

@@ -16,6 +16,7 @@
package org.springframework.data.jdbc.mybatis;
import lombok.experimental.Wither;
import org.apache.ibatis.type.Alias;
import org.springframework.data.annotation.Id;

View File

@@ -19,8 +19,8 @@ import static org.assertj.core.api.Assertions.*;
import lombok.Data;
import lombok.Value;
import lombok.experimental.FieldDefaults;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

View File

@@ -28,7 +28,6 @@ import java.util.List;
import java.util.Random;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

View File

@@ -24,7 +24,6 @@ import lombok.RequiredArgsConstructor;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import org.junit.ClassRule;

View File

@@ -15,9 +15,16 @@
*/
package org.springframework.data.jdbc.repository;
import static org.assertj.core.api.Assertions.*;
import junit.framework.AssertionFailedError;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
@@ -35,12 +42,6 @@ import org.springframework.test.context.junit4.rules.SpringClassRule;
import org.springframework.test.context.junit4.rules.SpringMethodRule;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import static org.assertj.core.api.Assertions.*;
/**
* Very simple use cases for creation and usage of JdbcRepositories for Entities that contain {@link List}s.
*

View File

@@ -25,12 +25,12 @@ import static org.mockito.Mockito.*;
import junit.framework.AssertionFailedError;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import lombok.experimental.Wither;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import lombok.experimental.Wither;
import org.assertj.core.groups.Tuple;
import org.junit.Before;
import org.junit.Test;
@@ -40,6 +40,7 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.jdbc.core.DefaultDataAccessStrategy;
import org.springframework.data.jdbc.core.SqlGeneratorSource;
import org.springframework.data.jdbc.core.convert.JdbcCustomConversions;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory;
import org.springframework.data.jdbc.repository.support.SimpleJdbcRepository;
import org.springframework.data.relational.core.conversion.BasicRelationalConverter;
@@ -74,7 +75,7 @@ public class SimpleJdbcRepositoryEventsUnitTests {
@Before
public void before() {
RelationalMappingContext context = new RelationalMappingContext();
RelationalMappingContext context = new JdbcMappingContext();
RelationalConverter converter = new BasicRelationalConverter(context, new JdbcCustomConversions());
NamedParameterJdbcOperations operations = createIdGeneratingOperations();

View File

@@ -17,6 +17,8 @@ package org.springframework.data.jdbc.repository.query;
import static org.assertj.core.api.Assertions.*;
import lombok.Value;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.Date;
@@ -24,7 +26,6 @@ import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import lombok.Value;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

View File

@@ -16,7 +16,7 @@
package org.springframework.data.jdbc.repository.support;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import java.lang.reflect.Method;

View File

@@ -28,6 +28,7 @@ import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.annotation.Id;
import org.springframework.data.jdbc.core.DataAccessStrategy;
import org.springframework.data.jdbc.core.DefaultDataAccessStrategy;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.jdbc.repository.RowMapperMap;
import org.springframework.data.relational.core.conversion.BasicRelationalConverter;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
@@ -56,7 +57,7 @@ public class JdbcRepositoryFactoryBeanUnitTests {
@Before
public void setUp() {
this.mappingContext = new RelationalMappingContext();
this.mappingContext = new JdbcMappingContext();
// Setup standard configuration
factoryBean = new JdbcRepositoryFactoryBean<>(DummyEntityRepository.class);

View File

@@ -15,7 +15,10 @@
*/
package org.springframework.data.jdbc.repository.support;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.*;
import java.sql.ResultSet;

View File

@@ -16,7 +16,7 @@
package org.springframework.data.jdbc.repository.support;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import org.junit.Test;

View File

@@ -29,9 +29,10 @@ import org.springframework.data.convert.CustomConversions;
import org.springframework.data.jdbc.core.DataAccessStrategy;
import org.springframework.data.jdbc.core.DefaultDataAccessStrategy;
import org.springframework.data.jdbc.core.SqlGeneratorSource;
import org.springframework.data.jdbc.core.convert.BasicJdbcConverter;
import org.springframework.data.jdbc.core.convert.JdbcCustomConversions;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory;
import org.springframework.data.relational.core.conversion.BasicRelationalConverter;
import org.springframework.data.relational.core.conversion.RelationalConverter;
import org.springframework.data.relational.core.mapping.NamingStrategy;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
@@ -78,11 +79,10 @@ public class TestConfiguration {
}
@Bean
RelationalMappingContext jdbcMappingContext(NamedParameterJdbcOperations template,
Optional<NamingStrategy> namingStrategy, CustomConversions conversions) {
JdbcMappingContext jdbcMappingContext(NamedParameterJdbcOperations template, Optional<NamingStrategy> namingStrategy,
CustomConversions conversions) {
RelationalMappingContext mappingContext = new RelationalMappingContext(
namingStrategy.orElse(NamingStrategy.INSTANCE));
JdbcMappingContext mappingContext = new JdbcMappingContext(namingStrategy.orElse(NamingStrategy.INSTANCE));
mappingContext.setSimpleTypeHolder(conversions.getSimpleTypeHolder());
return mappingContext;
}
@@ -94,6 +94,6 @@ public class TestConfiguration {
@Bean
RelationalConverter relationalConverter(RelationalMappingContext mappingContext, CustomConversions conversions) {
return new BasicRelationalConverter(mappingContext, conversions);
return new BasicJdbcConverter(mappingContext, conversions);
}
}

Some files were not shown because too many files have changed in this diff Show More