Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.0-1993-force-quoting-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data Relational Parent</name>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-jdbc-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.0-1993-force-quoting-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
4 changes: 2 additions & 2 deletions spring-data-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-jdbc</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.0-1993-force-quoting-SNAPSHOT</version>

<name>Spring Data JDBC</name>
<description>Spring Data module for JDBC repositories.</description>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.0-1993-force-quoting-SNAPSHOT</version>
</parent>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,61 @@ public JdbcMappingContext(NamingStrategy namingStrategy) {
setSimpleTypeHolder(JdbcSimpleTypes.HOLDER);
}

/**
* Create a new {@code JdbcMappingContext} using {@link #setForceQuote(boolean) plain identifiers}. Plain
* {@link org.springframework.data.relational.core.sql.SqlIdentifier identifiers} (i.e. table and column names) are
* typically not case-sensitive (case-sensitivity can be still enforced by specific database configurations).
*
* @return a new {@code JdbcMappingContext} using plain identifiers.
* @since 4.0
*/
public static JdbcMappingContext forPlainIdentifiers() {
JdbcMappingContext context = forQuotedIdentifiers();
context.setForceQuote(false);
return context;
}

/**
* Create a new {@code JdbcMappingContext} using {@link #setForceQuote(boolean) plain identifiers} and the given
* {@link NamingStrategy}. Plain {@link org.springframework.data.relational.core.sql.SqlIdentifier identifiers} (i.e.
* table and column names) are typically not case-sensitive (case-sensitivity can be still enforced by specific
* database configurations).
*
* @param namingStrategy must not be {@literal null}.
* @return a new {@code JdbcMappingContext} using plain identifiers.
* @since 4.0
*/
public static JdbcMappingContext forPlainIdentifiers(NamingStrategy namingStrategy) {
JdbcMappingContext context = forQuotedIdentifiers(namingStrategy);
context.setForceQuote(false);
return context;
}

/**
* Create a new {@code JdbcMappingContext} using {@link #setForceQuote(boolean) quoted identifiers} (default
* behavior). Quoted {@link org.springframework.data.relational.core.sql.SqlIdentifier identifiers} (i.e. table and
* column names) are typically case-sensitive.
*
* @return a new {@code JdbcMappingContext} using quoted identifiers.
* @since 4.0
*/
public static JdbcMappingContext forQuotedIdentifiers() {
return new JdbcMappingContext();
}

/**
* Create a new {@code JdbcMappingContext} using {@link #setForceQuote(boolean) quoted identifiers} (default behavior)
* and the given {@link NamingStrategy}. Quoted {@link org.springframework.data.relational.core.sql.SqlIdentifier
* identifiers} (i.e. table and column names) are typically case-sensitive.
*
* @param namingStrategy must not be {@literal null}.
* @return a new {@code JdbcMappingContext} using quoted identifiers.
* @since 4.0
*/
public static JdbcMappingContext forQuotedIdentifiers(NamingStrategy namingStrategy) {
return new JdbcMappingContext(namingStrategy);
}

@Override
protected RelationalPersistentProperty createPersistentProperty(Property property,
RelationalPersistentEntity<?> owner, SimpleTypeHolder simpleTypeHolder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ public RelationalManagedTypes jdbcManagedTypes() throws ClassNotFoundException {
public JdbcMappingContext jdbcMappingContext(Optional<NamingStrategy> namingStrategy,
JdbcCustomConversions customConversions, RelationalManagedTypes jdbcManagedTypes) {

JdbcMappingContext mappingContext = new JdbcMappingContext(namingStrategy.orElse(DefaultNamingStrategy.INSTANCE));
JdbcMappingContext mappingContext = JdbcMappingContext
.forQuotedIdentifiers(namingStrategy.orElse(DefaultNamingStrategy.INSTANCE));
mappingContext.setSimpleTypeHolder(customConversions.getSimpleTypeHolder());
mappingContext.setManagedTypes(jdbcManagedTypes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ private <T> EntityRowMapper<T> createRowMapper(Class<T> type) {
@SuppressWarnings("unchecked")
private <T> EntityRowMapper<T> createRowMapper(Class<T> type, NamingStrategy namingStrategy) {

RelationalMappingContext context = new JdbcMappingContext(namingStrategy);
RelationalMappingContext context = JdbcMappingContext.forQuotedIdentifiers(namingStrategy);

DataAccessStrategy accessStrategy = mock(DataAccessStrategy.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*/
class JdbcIdentifierBuilderUnitTests {

JdbcMappingContext context = new JdbcMappingContext();
JdbcMappingContext context = JdbcMappingContext.forQuotedIdentifiers();
JdbcConverter converter = new MappingJdbcConverter(context, (identifier, path) -> {
throw new UnsupportedOperationException();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void accessesCorrectValuesForOneToOneRelationshipWithIdenticallyNamedIdPropertie
@Test // GH-1750
void readByteArrayToNestedUuidWithCustomConverter() {

JdbcMappingContext context = new JdbcMappingContext();
JdbcMappingContext context = JdbcMappingContext.forQuotedIdentifiers();
StubbedJdbcTypeFactory typeFactory = new StubbedJdbcTypeFactory();
Converter<byte[], UUID> customConverter = new ByteArrayToUuid();
MappingJdbcConverter converter = new MappingJdbcConverter( //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
*/
public class RowDocumentResultSetExtractorUnitTests {

RelationalMappingContext context = new JdbcMappingContext(new DefaultNamingStrategy());
RelationalMappingContext context = JdbcMappingContext.forQuotedIdentifiers(new DefaultNamingStrategy());

private final PathToColumnMapping column = new PathToColumnMapping() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private void threadedTest(String user, CountDownLatch latch, Consumer<String> te
*/
private SqlGenerator configureSqlGenerator(NamingStrategy namingStrategy) {

RelationalMappingContext context = new JdbcMappingContext(namingStrategy);
RelationalMappingContext context = JdbcMappingContext.forQuotedIdentifiers(namingStrategy);
JdbcConverter converter = new MappingJdbcConverter(context, (identifier, path) -> {
throw new UnsupportedOperationException();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,14 @@
*/
class SqlGeneratorEmbeddedUnitTests {

private RelationalMappingContext context = new JdbcMappingContext();
private RelationalMappingContext context = JdbcMappingContext.forPlainIdentifiers();
private JdbcConverter converter = new MappingJdbcConverter(context, (identifier, path) -> {
throw new UnsupportedOperationException();
});
private SqlGenerator sqlGenerator;

@BeforeEach
void setUp() {
this.context.setForceQuote(false);
this.sqlGenerator = createSqlGenerator(DummyEntity.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private PersistentPropertyPath<RelationalPersistentProperty> getPath(String path
*/
private SqlGenerator configureSqlGenerator(NamingStrategy namingStrategy) {

context = new JdbcMappingContext(namingStrategy);
context = JdbcMappingContext.forQuotedIdentifiers(namingStrategy);
JdbcConverter converter = new MappingJdbcConverter(context, (identifier, path) -> {
throw new UnsupportedOperationException();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,11 @@
*/
package org.springframework.data.jdbc.core.convert;

import static java.util.Collections.emptySet;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.entry;
import static org.assertj.core.api.SoftAssertions.assertSoftly;
import static org.springframework.data.relational.core.mapping.ForeignKeyNaming.APPLY_RENAMING;
import static org.springframework.data.relational.core.mapping.ForeignKeyNaming.IGNORE_RENAMING;
import static org.springframework.data.relational.core.sql.SqlIdentifier.EMPTY;
import static org.springframework.data.relational.core.sql.SqlIdentifier.quoted;
import static org.springframework.data.relational.core.sql.SqlIdentifier.unquoted;
import static java.util.Collections.*;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.SoftAssertions.*;
import static org.springframework.data.relational.core.mapping.ForeignKeyNaming.*;
import static org.springframework.data.relational.core.sql.SqlIdentifier.*;

import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -87,7 +81,7 @@ class SqlGeneratorUnitTests {
private static final Identifier BACKREF = Identifier.of(unquoted("backref"), "some-value", String.class);

private final PrefixingNamingStrategy namingStrategy = new PrefixingNamingStrategy();
private RelationalMappingContext context = new JdbcMappingContext(namingStrategy);
private RelationalMappingContext context = JdbcMappingContext.forQuotedIdentifiers(namingStrategy);
private final JdbcConverter converter = new MappingJdbcConverter(context, (identifier, path) -> {
throw new UnsupportedOperationException();
});
Expand Down Expand Up @@ -977,7 +971,7 @@ void selectByQueryPaginationValidTest() {
void backReferenceShouldConsiderRenamedParent() {

namingStrategy.setForeignKeyNaming(APPLY_RENAMING);
context = new JdbcMappingContext(namingStrategy);
context = JdbcMappingContext.forQuotedIdentifiers(namingStrategy);

String sql = sqlGenerator.createDeleteInByPath(getPath("ref", RenamedDummy.class));

Expand All @@ -988,7 +982,7 @@ void backReferenceShouldConsiderRenamedParent() {
void backReferenceShouldIgnoreRenamedParent() {

namingStrategy.setForeignKeyNaming(IGNORE_RENAMING);
context = new JdbcMappingContext(namingStrategy);
context = JdbcMappingContext.forQuotedIdentifiers(namingStrategy);

String sql = sqlGenerator.createDeleteInByPath(getPath("ref", RenamedDummy.class));

Expand All @@ -999,7 +993,7 @@ void backReferenceShouldIgnoreRenamedParent() {
void keyColumnShouldConsiderRenamedParent() {

namingStrategy.setForeignKeyNaming(APPLY_RENAMING);
context = new JdbcMappingContext(namingStrategy);
context = JdbcMappingContext.forQuotedIdentifiers(namingStrategy);

SqlGenerator sqlGenerator = createSqlGenerator(ReferencedEntity.class);
String sql = sqlGenerator.getFindAllByProperty(Identifier.of(unquoted("parentId"), 23, RenamedDummy.class),
Expand All @@ -1012,7 +1006,7 @@ void keyColumnShouldConsiderRenamedParent() {
void keyColumnShouldIgnoreRenamedParent() {

namingStrategy.setForeignKeyNaming(IGNORE_RENAMING);
context = new JdbcMappingContext(namingStrategy);
context = JdbcMappingContext.forQuotedIdentifiers(namingStrategy);

SqlGenerator sqlGenerator = createSqlGenerator(ReferencedEntity.class);
String sql = sqlGenerator.getFindAllByProperty(Identifier.of(unquoted("parentId"), 23, RenamedDummy.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@
*/
package org.springframework.data.jdbc.mapping.model;

import static org.assertj.core.api.Assertions.*;

import java.time.LocalDateTime;
import java.util.List;

import org.junit.jupiter.api.Test;

import org.springframework.data.annotation.Id;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.relational.core.mapping.DefaultNamingStrategy;
import org.springframework.data.relational.core.mapping.NamingStrategy;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;

import java.time.LocalDateTime;
import java.util.List;

import static org.assertj.core.api.Assertions.*;

/**
* Unit tests for the default {@link NamingStrategy}.
*
Expand All @@ -39,7 +40,7 @@ public class DefaultNamingStrategyUnitTests {
private final NamingStrategy target = DefaultNamingStrategy.INSTANCE;

private final RelationalPersistentEntity<?> persistentEntity = //
new JdbcMappingContext(target).getRequiredPersistentEntity(DummyEntity.class);
JdbcMappingContext.forQuotedIdentifiers(target).getRequiredPersistentEntity(DummyEntity.class);

@Test // DATAJDBC-184
public void getTableName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@

package org.springframework.data.jdbc.repository;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;

import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.annotation.Id;
import org.springframework.data.jdbc.core.convert.DataAccessStrategy;
Expand Down Expand Up @@ -98,7 +96,7 @@ private String query() {

Dialect dialect = JdbcHsqlDbDialect.INSTANCE;

RelationalMappingContext context = new JdbcMappingContext();
RelationalMappingContext context = JdbcMappingContext.forQuotedIdentifiers();

DelegatingDataAccessStrategy delegatingDataAccessStrategy = new DelegatingDataAccessStrategy();
JdbcConverter converter = new MappingJdbcConverter(context, delegatingDataAccessStrategy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ DataAccessStrategy defaultDataAccessStrategy(
JdbcMappingContext jdbcMappingContextWithOutSingleQueryLoading(Optional<NamingStrategy> namingStrategy,
CustomConversions conversions) {

JdbcMappingContext mappingContext = new JdbcMappingContext(namingStrategy.orElse(DefaultNamingStrategy.INSTANCE));
JdbcMappingContext mappingContext = JdbcMappingContext
.forQuotedIdentifiers(namingStrategy.orElse(DefaultNamingStrategy.INSTANCE));
mappingContext.setSimpleTypeHolder(conversions.getSimpleTypeHolder());
return mappingContext;
}
Expand All @@ -135,7 +136,8 @@ JdbcMappingContext jdbcMappingContextWithOutSingleQueryLoading(Optional<NamingSt
JdbcMappingContext jdbcMappingContextWithSingleQueryLoading(Optional<NamingStrategy> namingStrategy,
CustomConversions conversions) {

JdbcMappingContext mappingContext = new JdbcMappingContext(namingStrategy.orElse(DefaultNamingStrategy.INSTANCE));
JdbcMappingContext mappingContext = JdbcMappingContext
.forQuotedIdentifiers(namingStrategy.orElse(DefaultNamingStrategy.INSTANCE));
mappingContext.setSimpleTypeHolder(conversions.getSimpleTypeHolder());
mappingContext.setSingleQueryLoadingEnabled(true);
return mappingContext;
Expand Down
4 changes: 2 additions & 2 deletions spring-data-r2dbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-r2dbc</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.0-1993-force-quoting-SNAPSHOT</version>

<name>Spring Data R2DBC</name>
<description>Spring Data module for R2DBC</description>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.0-1993-force-quoting-SNAPSHOT</version>
</parent>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ public R2dbcMappingContext r2dbcMappingContext(Optional<NamingStrategy> namingSt

Assert.notNull(namingStrategy, "NamingStrategy must not be null");

R2dbcMappingContext context = new R2dbcMappingContext(namingStrategy.orElse(DefaultNamingStrategy.INSTANCE));
R2dbcMappingContext context = R2dbcMappingContext
.forQuotedIdentifiers(namingStrategy.orElse(DefaultNamingStrategy.INSTANCE));
context.setSimpleTypeHolder(r2dbcCustomConversions.getSimpleTypeHolder());
context.setManagedTypes(r2dbcManagedTypes);

Expand Down
Loading