DATAJDBC-189 - Polishing.
Removed DefaultNamingStrategy since we don't have GA release breaking APIs is still ok. Introduced an instance of NamingStrategy so we don't have to create a new class whereever we just want the default implementation. JavaDoc. Formatting Original pull request: #36.
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright 2017-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.mapping.model;
|
||||
|
||||
/**
|
||||
* Basic implementation of {@link NamingStrategy} with no schema, table based on {@link Class} and
|
||||
* column name based on {@link JdbcPersistentProperty}.
|
||||
*
|
||||
* NOTE: Can also be used as an adapter. Create an anonymous subclass and override any settings to implement
|
||||
* a different strategy on the fly.
|
||||
*
|
||||
* @author Greg Turnquist
|
||||
* @author Michael Simons
|
||||
* @deprecated Use {@link NamingStrategy} for a default implementation and implement methods as needed
|
||||
*/
|
||||
public class DefaultNamingStrategy implements NamingStrategy {
|
||||
}
|
||||
@@ -22,14 +22,14 @@ import org.springframework.data.util.ParsingUtils;
|
||||
* column name based on {@link JdbcPersistentProperty}. The default delimiter is '_', resulting in snake case.
|
||||
*
|
||||
* @author Kazuki Shimizu
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
public class DelimiterNamingStrategy extends DefaultNamingStrategy {
|
||||
public class DelimiterNamingStrategy implements NamingStrategy {
|
||||
|
||||
private final String delimiter;
|
||||
|
||||
/**
|
||||
* Construct a instance with '_' as delimiter.
|
||||
* This results in a snake case naming strategy.
|
||||
* Construct a instance with '_' as delimiter. This results in a snake case naming strategy.
|
||||
*/
|
||||
public DelimiterNamingStrategy() {
|
||||
this("_");
|
||||
@@ -49,7 +49,7 @@ public class DelimiterNamingStrategy extends DefaultNamingStrategy {
|
||||
*/
|
||||
@Override
|
||||
public String getTableName(Class<?> type) {
|
||||
return ParsingUtils.reconcatenateCamelCase(super.getTableName(type), delimiter);
|
||||
return ParsingUtils.reconcatenateCamelCase(NamingStrategy.super.getTableName(type), delimiter);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,7 +57,7 @@ public class DelimiterNamingStrategy extends DefaultNamingStrategy {
|
||||
*/
|
||||
@Override
|
||||
public String getColumnName(JdbcPersistentProperty property) {
|
||||
return ParsingUtils.reconcatenateCamelCase(super.getColumnName(property), delimiter);
|
||||
return ParsingUtils.reconcatenateCamelCase(NamingStrategy.super.getColumnName(property), delimiter);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -71,7 +71,7 @@ public class JdbcMappingContext extends AbstractMappingContext<JdbcPersistentEnt
|
||||
}
|
||||
|
||||
public JdbcMappingContext(NamedParameterJdbcOperations template) {
|
||||
this(new DefaultNamingStrategy(), template, __ -> {});
|
||||
this(NamingStrategy.INSTANCE, template, __ -> {});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,21 +16,28 @@
|
||||
package org.springframework.data.jdbc.mapping.model;
|
||||
|
||||
/**
|
||||
* Interface and default implementation of a naming strategy. Defaults to no schema,
|
||||
* table name based on {@link Class} and column name based on {@link JdbcPersistentProperty}.
|
||||
*
|
||||
* NOTE: Can also be used as an adapter. Create a lambda or an anonymous subclass and
|
||||
* override any settings to implement a different strategy on the fly.
|
||||
* Interface and default implementation of a naming strategy. Defaults to no schema, table name based on {@link Class}
|
||||
* and column name based on {@link JdbcPersistentProperty}.
|
||||
* <p>
|
||||
* NOTE: Can also be used as an adapter. Create a lambda or an anonymous subclass and override any settings to implement
|
||||
* a different strategy on the fly.
|
||||
*
|
||||
* @author Greg Turnquist
|
||||
* @author Michael Simons
|
||||
*/
|
||||
public interface NamingStrategy {
|
||||
|
||||
/**
|
||||
* Empty implementation of the interface utilizing only the default implementation.
|
||||
* <p>
|
||||
* Using this avoids creating essentially the same class over and over again.
|
||||
*/
|
||||
NamingStrategy INSTANCE = new NamingStrategy() {};
|
||||
|
||||
/**
|
||||
* Defaults to no schema.
|
||||
*
|
||||
* @return No schema
|
||||
* @return Empty String representing no schema
|
||||
*/
|
||||
default String getSchema() {
|
||||
return "";
|
||||
@@ -58,17 +65,19 @@ public interface NamingStrategy {
|
||||
* For a reference A -> B this is the name in the table for B which references A.
|
||||
*
|
||||
* @param property The property who's column name in the owner table is required
|
||||
* @return a column name.
|
||||
* @return a column name. Must not be {@code null}.
|
||||
*/
|
||||
default String getReverseColumnName(JdbcPersistentProperty property) {
|
||||
return property.getOwner().getTableName();
|
||||
}
|
||||
|
||||
/**
|
||||
* For a map valued reference A -> Map>X,B< this is the name of the column in the tabel for B holding the key of the map.
|
||||
* @return
|
||||
* For a map valued reference A -> Map>X,B< this is the name of the column in the table for B holding the key of
|
||||
* the map.
|
||||
*
|
||||
* @return name of the key column. Must not be {@code null}.
|
||||
*/
|
||||
default String getKeyColumn(JdbcPersistentProperty property){
|
||||
default String getKeyColumn(JdbcPersistentProperty property) {
|
||||
return getReverseColumnName(property) + "_key";
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.Optional;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.jdbc.mapping.model.ConversionCustomizer;
|
||||
import org.springframework.data.jdbc.mapping.model.DefaultNamingStrategy;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcMappingContext;
|
||||
import org.springframework.data.jdbc.mapping.model.NamingStrategy;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
@@ -35,9 +34,9 @@ public class JdbcConfiguration {
|
||||
|
||||
@Bean
|
||||
JdbcMappingContext jdbcMappingContext(NamedParameterJdbcTemplate template, Optional<NamingStrategy> namingStrategy,
|
||||
Optional<ConversionCustomizer> conversionCustomizer) {
|
||||
Optional<ConversionCustomizer> conversionCustomizer) {
|
||||
|
||||
return new JdbcMappingContext(
|
||||
namingStrategy.orElse(new DefaultNamingStrategy()), template, conversionCustomizer.orElse(conversionService -> {}));
|
||||
return new JdbcMappingContext(namingStrategy.orElse(NamingStrategy.INSTANCE), template,
|
||||
conversionCustomizer.orElse(conversionService -> {}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ import java.util.HashMap;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.jdbc.mapping.model.DefaultNamingStrategy;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcMappingContext;
|
||||
import org.springframework.data.jdbc.mapping.model.NamingStrategy;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
|
||||
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
|
||||
import org.springframework.jdbc.support.KeyHolder;
|
||||
@@ -42,7 +42,7 @@ public class DefaultDataAccessStrategyUnitTests {
|
||||
public static final long ORIGINAL_ID = 4711L;
|
||||
|
||||
NamedParameterJdbcOperations jdbcOperations = mock(NamedParameterJdbcOperations.class);
|
||||
JdbcMappingContext context = new JdbcMappingContext(new DefaultNamingStrategy(), jdbcOperations, __ -> {});
|
||||
JdbcMappingContext context = new JdbcMappingContext(NamingStrategy.INSTANCE, jdbcOperations, __ -> {});
|
||||
HashMap<String, Object> additionalParameters = new HashMap<>();
|
||||
ArgumentCaptor<SqlParameterSource> paramSourceCaptor = ArgumentCaptor.forClass(SqlParameterSource.class);
|
||||
|
||||
|
||||
@@ -27,9 +27,9 @@ import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.jdbc.core.conversion.DbAction;
|
||||
import org.springframework.data.jdbc.core.conversion.DbAction.Insert;
|
||||
import org.springframework.data.jdbc.core.conversion.JdbcPropertyPath;
|
||||
import org.springframework.data.jdbc.mapping.model.DefaultNamingStrategy;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcMappingContext;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcPersistentProperty;
|
||||
import org.springframework.data.jdbc.mapping.model.NamingStrategy;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
|
||||
|
||||
/**
|
||||
@@ -42,7 +42,7 @@ public class DefaultJdbcInterpreterUnitTests {
|
||||
static final long CONTAINER_ID = 23L;
|
||||
static final String BACK_REFERENCE = "back-reference";
|
||||
|
||||
JdbcMappingContext context = new JdbcMappingContext(new DefaultNamingStrategy() {
|
||||
JdbcMappingContext context = new JdbcMappingContext(new NamingStrategy() {
|
||||
@Override
|
||||
public String getReverseColumnName(JdbcPersistentProperty property) {
|
||||
return BACK_REFERENCE;
|
||||
|
||||
@@ -15,23 +15,12 @@
|
||||
*/
|
||||
package org.springframework.data.jdbc.core;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.junit.Test;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.core.convert.support.GenericConversionService;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.convert.Jsr310Converters;
|
||||
import org.springframework.data.jdbc.mapping.model.DefaultNamingStrategy;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcMappingContext;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcPersistentEntity;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcPersistentProperty;
|
||||
import org.springframework.data.jdbc.mapping.model.NamingStrategy;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
|
||||
import org.springframework.util.Assert;
|
||||
import static java.util.Arrays.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import javax.naming.OperationNotSupportedException;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
@@ -42,9 +31,21 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Arrays.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import javax.naming.OperationNotSupportedException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.core.convert.support.GenericConversionService;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.convert.Jsr310Converters;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcMappingContext;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcPersistentEntity;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcPersistentProperty;
|
||||
import org.springframework.data.jdbc.mapping.model.NamingStrategy;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Tests the extraction of entities from a {@link ResultSet} by the {@link EntityRowMapper}.
|
||||
@@ -56,10 +57,10 @@ public class EntityRowMapperUnitTests {
|
||||
public static final long ID_FOR_ENTITY_REFERENCING_MAP = 42L;
|
||||
public static final long ID_FOR_ENTITY_REFERENCING_LIST = 4711L;
|
||||
public static final long ID_FOR_ENTITY_NOT_REFERENCING_MAP = 23L;
|
||||
public static final DefaultNamingStrategy X_APPENDING_NAMINGSTRATEGY = new DefaultNamingStrategy() {
|
||||
public static final NamingStrategy X_APPENDING_NAMINGSTRATEGY = new NamingStrategy() {
|
||||
@Override
|
||||
public String getColumnName(JdbcPersistentProperty property) {
|
||||
return super.getColumnName(property) + "x";
|
||||
return NamingStrategy.super.getColumnName(property) + "x";
|
||||
}
|
||||
};
|
||||
|
||||
@@ -169,7 +170,7 @@ public class EntityRowMapperUnitTests {
|
||||
}
|
||||
|
||||
private <T> EntityRowMapper<T> createRowMapper(Class<T> type) {
|
||||
return createRowMapper(type, new DefaultNamingStrategy());
|
||||
return createRowMapper(type, NamingStrategy.INSTANCE);
|
||||
}
|
||||
|
||||
private <T> EntityRowMapper<T> createRowMapper(Class<T> type, NamingStrategy namingStrategy) {
|
||||
@@ -177,15 +178,14 @@ public class EntityRowMapperUnitTests {
|
||||
JdbcMappingContext context = new JdbcMappingContext( //
|
||||
namingStrategy, //
|
||||
mock(NamedParameterJdbcOperations.class), //
|
||||
__ -> {
|
||||
} //
|
||||
__ -> {} //
|
||||
);
|
||||
|
||||
DataAccessStrategy accessStrategy = mock(DataAccessStrategy.class);
|
||||
|
||||
// the ID of the entity is used to determine what kind of ResultSet is needed for subsequent selects.
|
||||
doReturn(new HashSet<>(asList(new Trivial(), new Trivial()))).when(accessStrategy).findAllByProperty(eq(ID_FOR_ENTITY_NOT_REFERENCING_MAP),
|
||||
any(JdbcPersistentProperty.class));
|
||||
doReturn(new HashSet<>(asList(new Trivial(), new Trivial()))).when(accessStrategy)
|
||||
.findAllByProperty(eq(ID_FOR_ENTITY_NOT_REFERENCING_MAP), any(JdbcPersistentProperty.class));
|
||||
|
||||
doReturn(new HashSet<>(asList( //
|
||||
new SimpleEntry("one", new Trivial()), //
|
||||
@@ -202,8 +202,8 @@ public class EntityRowMapperUnitTests {
|
||||
DefaultConversionService.addDefaultConverters(conversionService);
|
||||
Jsr310Converters.getConvertersToRegister().forEach(conversionService::addConverter);
|
||||
|
||||
return new EntityRowMapper<>((JdbcPersistentEntity<T>) context.getRequiredPersistentEntity(type),
|
||||
context, accessStrategy);
|
||||
return new EntityRowMapper<>((JdbcPersistentEntity<T>) context.getRequiredPersistentEntity(type), context,
|
||||
accessStrategy);
|
||||
}
|
||||
|
||||
private static ResultSet mockResultSet(List<String> columns, Object... values) {
|
||||
@@ -215,7 +215,7 @@ public class EntityRowMapperUnitTests {
|
||||
"Number of values [%d] must be a multiple of the number of columns [%d]", //
|
||||
values.length, //
|
||||
columns.size() //
|
||||
) //
|
||||
) //
|
||||
);
|
||||
|
||||
List<Map<String, Object>> result = convertValues(columns, values);
|
||||
@@ -291,7 +291,8 @@ public class EntityRowMapperUnitTests {
|
||||
|
||||
Map<String, Object> rowMap = values.get(index);
|
||||
|
||||
Assert.isTrue(rowMap.containsKey(column), String.format("Trying to access a column (%s) that does not exist", column));
|
||||
Assert.isTrue(rowMap.containsKey(column),
|
||||
String.format("Trying to access a column (%s) that does not exist", column));
|
||||
|
||||
return rowMap.get(column);
|
||||
}
|
||||
@@ -306,46 +307,40 @@ public class EntityRowMapperUnitTests {
|
||||
@RequiredArgsConstructor
|
||||
static class TrivialImmutable {
|
||||
|
||||
@Id
|
||||
private final Long id;
|
||||
@Id private final Long id;
|
||||
private final String name;
|
||||
}
|
||||
|
||||
static class Trivial {
|
||||
|
||||
@Id
|
||||
Long id;
|
||||
@Id Long id;
|
||||
String name;
|
||||
}
|
||||
|
||||
static class OneToOne {
|
||||
|
||||
@Id
|
||||
Long id;
|
||||
@Id Long id;
|
||||
String name;
|
||||
Trivial child;
|
||||
}
|
||||
|
||||
static class OneToSet {
|
||||
|
||||
@Id
|
||||
Long id;
|
||||
@Id Long id;
|
||||
String name;
|
||||
Set<Trivial> children;
|
||||
}
|
||||
|
||||
static class OneToMap {
|
||||
|
||||
@Id
|
||||
Long id;
|
||||
@Id Long id;
|
||||
String name;
|
||||
Map<String, Trivial> children;
|
||||
}
|
||||
|
||||
static class OneToList {
|
||||
|
||||
@Id
|
||||
Long id;
|
||||
@Id Long id;
|
||||
String name;
|
||||
List<Trivial> children;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ 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.mapping.model.DefaultNamingStrategy;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcMappingContext;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcPersistentEntity;
|
||||
import org.springframework.data.jdbc.mapping.model.NamingStrategy;
|
||||
@@ -33,10 +32,9 @@ import org.springframework.data.mapping.PropertyPath;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
|
||||
|
||||
/**
|
||||
* Unit tests to verify a contextual {@link NamingStrategy} implementation that customizes using a user-centric {@link ThreadLocal}.
|
||||
*
|
||||
* NOTE: Due to the need to verify SQL generation and {@link SqlGenerator}'s package-private status suggests
|
||||
* this unit test exist in this package, not {@literal org.springframework.data.jdbc.mappings.model}.
|
||||
* Unit tests to verify a contextual {@link NamingStrategy} implementation that customizes using a user-centric
|
||||
* {@link ThreadLocal}. NOTE: Due to the need to verify SQL generation and {@link SqlGenerator}'s package-private status
|
||||
* suggests this unit test exist in this package, not {@literal org.springframework.data.jdbc.mappings.model}.
|
||||
*
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
@@ -45,9 +43,10 @@ public class SqlGeneratorContextBasedNamingStrategyUnitTests {
|
||||
private final ThreadLocal<String> userHandler = new ThreadLocal<>();
|
||||
|
||||
/**
|
||||
* Use a {@link DefaultNamingStrategy}, but override the schema with a {@link ThreadLocal}-based setting.
|
||||
* Use a {@link NamingStrategy}, but override the schema with a {@link ThreadLocal}-based setting.
|
||||
*/
|
||||
private final NamingStrategy contextualNamingStrategy = new DefaultNamingStrategy() {
|
||||
private final NamingStrategy contextualNamingStrategy = new NamingStrategy() {
|
||||
|
||||
@Override
|
||||
public String getSchema() {
|
||||
return userHandler.get();
|
||||
@@ -65,12 +64,12 @@ public class SqlGeneratorContextBasedNamingStrategyUnitTests {
|
||||
|
||||
SoftAssertions softAssertions = new SoftAssertions();
|
||||
softAssertions.assertThat(sql) //
|
||||
.startsWith("SELECT") //
|
||||
.contains(user + ".DummyEntity.id AS id,") //
|
||||
.contains(user + ".DummyEntity.name AS name,") //
|
||||
.contains("ref.l1id AS ref_l1id") //
|
||||
.contains("ref.content AS ref_content") //
|
||||
.contains("FROM " + user + ".DummyEntity");
|
||||
.startsWith("SELECT") //
|
||||
.contains(user + ".DummyEntity.id AS id,") //
|
||||
.contains(user + ".DummyEntity.name AS name,") //
|
||||
.contains("ref.l1id AS ref_l1id") //
|
||||
.contains("ref.content AS ref_content") //
|
||||
.contains("FROM " + user + ".DummyEntity");
|
||||
softAssertions.assertAll();
|
||||
});
|
||||
}
|
||||
@@ -84,8 +83,7 @@ public class SqlGeneratorContextBasedNamingStrategyUnitTests {
|
||||
|
||||
String sql = sqlGenerator.createDeleteByPath(PropertyPath.from("ref", DummyEntity.class));
|
||||
|
||||
assertThat(sql).isEqualTo(
|
||||
"DELETE FROM " + user + ".ReferencedEntity WHERE " + user + ".DummyEntity = :rootId");
|
||||
assertThat(sql).isEqualTo("DELETE FROM " + user + ".ReferencedEntity WHERE " + user + ".DummyEntity = :rootId");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import static org.mockito.Mockito.*;
|
||||
import org.assertj.core.api.SoftAssertions;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.jdbc.mapping.model.DefaultNamingStrategy;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcMappingContext;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcPersistentEntity;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcPersistentProperty;
|
||||
@@ -37,7 +36,7 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
|
||||
*/
|
||||
public class SqlGeneratorFixedNamingStrategyUnitTests {
|
||||
|
||||
final NamingStrategy fixedCustomTablePrefixStrategy = new DefaultNamingStrategy() {
|
||||
final NamingStrategy fixedCustomTablePrefixStrategy = new NamingStrategy() {
|
||||
|
||||
@Override
|
||||
public String getSchema() {
|
||||
@@ -55,7 +54,7 @@ public class SqlGeneratorFixedNamingStrategyUnitTests {
|
||||
}
|
||||
};
|
||||
|
||||
final NamingStrategy upperCaseLowerCaseStrategy = new DefaultNamingStrategy() {
|
||||
final NamingStrategy upperCaseLowerCaseStrategy = new NamingStrategy() {
|
||||
|
||||
@Override
|
||||
public String getTableName(Class<?> type) {
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.assertj.core.api.SoftAssertions;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.jdbc.mapping.model.DefaultNamingStrategy;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcMappingContext;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcPersistentEntity;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcPersistentProperty;
|
||||
@@ -186,11 +185,11 @@ public class SqlGeneratorUnitTests {
|
||||
String content;
|
||||
}
|
||||
|
||||
private static class PrefixingNamingStrategy extends DefaultNamingStrategy {
|
||||
private static class PrefixingNamingStrategy implements NamingStrategy {
|
||||
|
||||
@Override
|
||||
public String getColumnName(JdbcPersistentProperty property) {
|
||||
return "x_" + super.getColumnName(property);
|
||||
return "x_" + NamingStrategy.super.getColumnName(property);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,7 +29,10 @@ import org.springframework.lang.Nullable;
|
||||
*/
|
||||
public class BasicJdbcPersistentEntityInformationUnitTests {
|
||||
|
||||
JdbcMappingContext context = new JdbcMappingContext(new DefaultNamingStrategy(), mock(NamedParameterJdbcOperations.class), cs -> {});
|
||||
JdbcMappingContext context = new JdbcMappingContext( //
|
||||
NamingStrategy.INSTANCE, //
|
||||
mock(NamedParameterJdbcOperations.class), //
|
||||
cs -> {});
|
||||
private DummyEntity dummyEntity = new DummyEntity();
|
||||
private PersistableDummyEntity persistableDummyEntity = new PersistableDummyEntity();
|
||||
|
||||
|
||||
@@ -15,14 +15,14 @@
|
||||
*/
|
||||
package org.springframework.data.jdbc.mapping.model;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.mapping.PropertyPath;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.mapping.PropertyPath;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link JdbcMappingContext}.
|
||||
@@ -31,7 +31,7 @@ import static org.mockito.Mockito.*;
|
||||
*/
|
||||
public class JdbcMappingContextUnitTests {
|
||||
|
||||
NamingStrategy namingStrategy = new DefaultNamingStrategy();
|
||||
NamingStrategy namingStrategy = NamingStrategy.INSTANCE;
|
||||
NamedParameterJdbcOperations jdbcTemplate = mock(NamedParameterJdbcOperations.class);
|
||||
ConversionCustomizer customizer = mock(ConversionCustomizer.class);
|
||||
|
||||
@@ -47,7 +47,7 @@ public class JdbcMappingContextUnitTests {
|
||||
.containsExactly( //
|
||||
"one.two", //
|
||||
"one" //
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-142
|
||||
@@ -64,7 +64,7 @@ public class JdbcMappingContextUnitTests {
|
||||
.containsExactly( //
|
||||
"one.two", //
|
||||
"one" //
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
private static class DummyEntity {
|
||||
@@ -81,4 +81,4 @@ public class JdbcMappingContextUnitTests {
|
||||
private static class LevelTwo {
|
||||
String someValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.jdbc.repository;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Value;
|
||||
@@ -31,7 +31,6 @@ import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.jdbc.mapping.model.DefaultNamingStrategy;
|
||||
import org.springframework.data.jdbc.mapping.model.NamingStrategy;
|
||||
import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories;
|
||||
import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory;
|
||||
@@ -134,7 +133,7 @@ public class JdbcRepositoryIdGenerationIntegrationTests {
|
||||
*/
|
||||
@Bean
|
||||
NamingStrategy namingStrategy() {
|
||||
return new DefaultNamingStrategy() {
|
||||
return new NamingStrategy() {
|
||||
@Override
|
||||
public String getTableName(Class<?> type) {
|
||||
return type.getSimpleName().toUpperCase();
|
||||
|
||||
@@ -31,7 +31,6 @@ import org.springframework.data.jdbc.core.DefaultDataAccessStrategy;
|
||||
import org.springframework.data.jdbc.core.DelegatingDataAccessStrategy;
|
||||
import org.springframework.data.jdbc.core.SqlGeneratorSource;
|
||||
import org.springframework.data.jdbc.mapping.model.ConversionCustomizer;
|
||||
import org.springframework.data.jdbc.mapping.model.DefaultNamingStrategy;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcMappingContext;
|
||||
import org.springframework.data.jdbc.mapping.model.NamingStrategy;
|
||||
import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory;
|
||||
@@ -59,7 +58,7 @@ public class TestConfiguration {
|
||||
|
||||
NamedParameterJdbcTemplate jdbcTemplate = namedParameterJdbcTemplate();
|
||||
|
||||
final JdbcMappingContext context = new JdbcMappingContext(new DefaultNamingStrategy(), jdbcTemplate, __ -> {});
|
||||
final JdbcMappingContext context = new JdbcMappingContext(NamingStrategy.INSTANCE, jdbcTemplate, __ -> {});
|
||||
|
||||
return new JdbcRepositoryFactory( //
|
||||
publisher, //
|
||||
@@ -102,7 +101,7 @@ public class TestConfiguration {
|
||||
Optional<ConversionCustomizer> conversionCustomizer) {
|
||||
|
||||
return new JdbcMappingContext( //
|
||||
namingStrategy.orElse(new DefaultNamingStrategy()), //
|
||||
namingStrategy.orElse(NamingStrategy.INSTANCE), //
|
||||
template, //
|
||||
conversionCustomizer.orElse(conversionService -> {}) //
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user