Skip to content

Commit 91ddda0

Browse files
committed
DATAJDBC-479 - Polishing.
Fixes compiler error from rebase rebase. Removes IdentifierProcessingAdapter since it wasn't used anymore Merged UnquotedDialect with NonQuotingDialect since both served the same purpose of a simple Dialect for testing. Formatting. Original pull request: #187.
1 parent 592f483 commit 91ddda0

File tree

11 files changed

+57
-123
lines changed

11 files changed

+57
-123
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlGenerator.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ class SqlGenerator {
6262
static final SqlIdentifier ROOT_ID_PARAMETER = SqlIdentifier.unquoted("rootId");
6363

6464
private static final Pattern parameterPattern = Pattern.compile("\\W");
65-
private final JdbcConverter converter;
6665
private final RelationalPersistentEntity<?> entity;
6766
private final MappingContext<RelationalPersistentEntity<?>, RelationalPersistentProperty> mappingContext;
6867
private final RenderContext renderContext;
@@ -93,10 +92,10 @@ class SqlGenerator {
9392
* @param entity must not be {@literal null}.
9493
* @param dialect must not be {@literal null}.
9594
*/
96-
SqlGenerator(RelationalMappingContext mappingContext, JdbcConverter converter,RelationalPersistentEntity<?> entity, Dialect dialect) {
95+
SqlGenerator(RelationalMappingContext mappingContext, JdbcConverter converter, RelationalPersistentEntity<?> entity,
96+
Dialect dialect) {
9797

9898
this.mappingContext = mappingContext;
99-
this.converter = converter;
10099
this.entity = entity;
101100
this.sqlContext = new SqlContext(entity);
102101
this.sqlRenderer = SqlRenderer.create(new RenderContextFactory(dialect).createRenderContext());
@@ -406,7 +405,8 @@ private SelectBuilder.SelectWhere selectBuilder(Collection<SqlIdentifier> keyCol
406405
return (SelectBuilder.SelectWhere) baseSelect;
407406
}
408407

409-
private SelectBuilder.SelectOrdered selectBuilder(Collection<String> keyColumns, Sort sort, Pageable pageable) {
408+
private SelectBuilder.SelectOrdered selectBuilder(Collection<SqlIdentifier> keyColumns, Sort sort,
409+
Pageable pageable) {
410410

411411
SelectBuilder.SelectOrdered sortable = this.selectBuilder(keyColumns);
412412
sortable = applyPagination(pageable, sortable);
@@ -426,8 +426,9 @@ private SelectBuilder.SelectOrdered applyPagination(Pageable pageable, SelectBui
426426
SelectBuilder.SelectLimitOffset limitable = (SelectBuilder.SelectLimitOffset) select;
427427
SelectBuilder.SelectLimitOffset limitResult = limitable.limitOffset(pageable.getPageSize(), pageable.getOffset());
428428

429-
Assert.state(limitResult instanceof SelectBuilder.SelectOrdered,
430-
String.format("The result of applying the limit-clause must be of type SelectOrdered in order to apply the order-by-clause but is of type %s.", select.getClass()));
429+
Assert.state(limitResult instanceof SelectBuilder.SelectOrdered, String.format(
430+
"The result of applying the limit-clause must be of type SelectOrdered in order to apply the order-by-clause but is of type %s.",
431+
select.getClass()));
431432

432433
return (SelectBuilder.SelectOrdered) limitResult;
433434
}

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlGeneratorSource.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public Dialect getDialect() {
4848
}
4949

5050
SqlGenerator getSqlGenerator(Class<?> domainType) {
51+
5152
return CACHE.computeIfAbsent(domainType,
52-
t -> new SqlGenerator(context, converter,
53-
context.getRequiredPersistentEntity(t), dialect));
53+
t -> new SqlGenerator(context, converter, context.getRequiredPersistentEntity(t), dialect));
5454
}
5555
}

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/IdentifierProcessingAdapter.java

-46
This file was deleted.

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/UnquotedDialect.java renamed to spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/NonQuotingDialect.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 the original author or authors.
2+
* Copyright 2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,19 +20,19 @@
2020
import org.springframework.data.relational.core.dialect.HsqlDbDialect;
2121
import org.springframework.data.relational.core.dialect.LimitClause;
2222
import org.springframework.data.relational.core.sql.IdentifierProcessing;
23-
import org.springframework.data.relational.core.sql.IdentifierProcessing.LetterCasing;
24-
import org.springframework.data.relational.core.sql.IdentifierProcessing.Quoting;
2523

2624
/**
2725
* Simple {@link Dialect} that provides unquoted {@link IdentifierProcessing}.
2826
*
2927
* @author Mark Paluch
28+
* @author Milan Milanov
29+
* @author Jens Schauder
3030
*/
31-
public class UnquotedDialect extends AbstractDialect implements Dialect {
31+
public class NonQuotingDialect extends AbstractDialect implements Dialect {
3232

33-
public static final UnquotedDialect INSTANCE = new UnquotedDialect();
33+
public static final NonQuotingDialect INSTANCE = new NonQuotingDialect();
3434

35-
private UnquotedDialect() {}
35+
private NonQuotingDialect() {}
3636

3737
@Override
3838
public LimitClause limit() {
@@ -41,6 +41,6 @@ public LimitClause limit() {
4141

4242
@Override
4343
public IdentifierProcessing getIdentifierProcessing() {
44-
return IdentifierProcessing.create(new Quoting(""), LetterCasing.AS_IS);
44+
return IdentifierProcessing.create(new IdentifierProcessing.Quoting(""), IdentifierProcessing.LetterCasing.AS_IS);
4545
}
4646
}

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlGeneratorContextBasedNamingStrategyUnitTests.java

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.springframework.data.annotation.Id;
2929
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
3030
import org.springframework.data.jdbc.core.mapping.PersistentPropertyPathTestUtils;
31-
import org.springframework.data.jdbc.testing.NonQuotingDialect;
3231
import org.springframework.data.mapping.PersistentPropertyPath;
3332
import org.springframework.data.relational.core.mapping.NamingStrategy;
3433
import org.springframework.data.relational.core.mapping.RelationalMappingContext;

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlGeneratorEmbeddedUnitTests.java

+31-9
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222
import org.junit.Before;
2323
import org.junit.Ignore;
2424
import org.junit.Test;
25-
2625
import org.springframework.data.annotation.Id;
2726
import org.springframework.data.jdbc.core.PropertyPathTestingUtils;
2827
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
29-
import org.springframework.data.jdbc.testing.NonQuotingDialect;
3028
import org.springframework.data.relational.core.mapping.Column;
3129
import org.springframework.data.relational.core.mapping.Embedded;
3230
import org.springframework.data.relational.core.mapping.Embedded.OnEmpty;
@@ -35,6 +33,7 @@
3533
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
3634
import org.springframework.data.relational.core.sql.Aliased;
3735
import org.springframework.data.relational.core.sql.SqlIdentifier;
36+
import org.springframework.lang.Nullable;
3837

3938
/**
4039
* Unit tests for the {@link SqlGenerator} in a context of the {@link Embedded} annotation.
@@ -203,8 +202,15 @@ public void noJoinForEmbedded() {
203202
public void columnForEmbeddedProperty() {
204203

205204
assertThat(generatedColumn("embeddable.test", DummyEntity.class)) //
206-
.extracting(c -> c.getName(), c -> c.getTable().getName(), c -> getAlias(c.getTable()), this::getAlias)
207-
.containsExactly(SqlIdentifier.unquoted("test"), SqlIdentifier.unquoted("dummy_entity"), null,
205+
.extracting( //
206+
c -> c.getName(), //
207+
c -> c.getTable().getName(), //
208+
c -> getAlias(c.getTable()), //
209+
this::getAlias) //
210+
.containsExactly( //
211+
SqlIdentifier.unquoted("test"), //
212+
SqlIdentifier.unquoted("dummy_entity"), //
213+
null, //
208214
SqlIdentifier.unquoted("test"));
209215
}
210216

@@ -227,8 +233,15 @@ public void noJoinForPrefixedEmbedded() {
227233
public void columnForPrefixedEmbeddedProperty() {
228234

229235
assertThat(generatedColumn("prefixedEmbeddable.test", DummyEntity.class)) //
230-
.extracting(c -> c.getName(), c -> c.getTable().getName(), c -> getAlias(c.getTable()), this::getAlias)
231-
.containsExactly(SqlIdentifier.unquoted("prefix_test"), SqlIdentifier.unquoted("dummy_entity"), null,
236+
.extracting( //
237+
c -> c.getName(), //
238+
c -> c.getTable().getName(), //
239+
c -> getAlias(c.getTable()), //
240+
this::getAlias) //
241+
.containsExactly( //
242+
SqlIdentifier.unquoted("prefix_test"), //
243+
SqlIdentifier.unquoted("dummy_entity"), //
244+
null, //
232245
SqlIdentifier.unquoted("prefix_test"));
233246
}
234247

@@ -268,16 +281,24 @@ public void joinForEmbeddedWithReference() {
268281
public void columnForEmbeddedWithReferenceProperty() {
269282

270283
assertThat(generatedColumn("embedded.other.value", DummyEntity2.class)) //
271-
.extracting(c -> c.getName(), c -> c.getTable().getName(), c -> getAlias(c.getTable()), this::getAlias)
272-
.containsExactly(SqlIdentifier.unquoted("value"), SqlIdentifier.unquoted("other_entity"),
273-
SqlIdentifier.quoted("prefix_other"), SqlIdentifier.unquoted("prefix_other_value"));
284+
.extracting( //
285+
c -> c.getName(), //
286+
c -> c.getTable().getName(), //
287+
c -> getAlias(c.getTable()), //
288+
this::getAlias) //
289+
.containsExactly( //
290+
SqlIdentifier.unquoted("value"), //
291+
SqlIdentifier.unquoted("other_entity"), //
292+
SqlIdentifier.quoted("prefix_other"), //
293+
SqlIdentifier.unquoted("prefix_other_value"));
274294
}
275295

276296
private SqlGenerator.Join generateJoin(String path, Class<?> type) {
277297
return createSqlGenerator(type)
278298
.getJoin(new PersistentPropertyPathExtension(context, PropertyPathTestingUtils.toPath(path, type, context)));
279299
}
280300

301+
@Nullable
281302
private SqlIdentifier getAlias(Object maybeAliased) {
282303

283304
if (maybeAliased instanceof Aliased) {
@@ -287,6 +308,7 @@ private SqlIdentifier getAlias(Object maybeAliased) {
287308
}
288309

289310
private org.springframework.data.relational.core.sql.Column generatedColumn(String path, Class<?> type) {
311+
290312
return createSqlGenerator(type)
291313
.getColumn(new PersistentPropertyPathExtension(context, PropertyPathTestingUtils.toPath(path, type, context)));
292314
}

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlGeneratorUnitTests.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
3838
import org.springframework.data.jdbc.core.mapping.PersistentPropertyPathTestUtils;
3939
import org.springframework.data.jdbc.testing.AnsiDialect;
40-
import org.springframework.data.jdbc.testing.NonQuotingDialect;
4140
import org.springframework.data.mapping.PersistentPropertyPath;
4241
import org.springframework.data.relational.core.dialect.Dialect;
4342
import org.springframework.data.relational.core.mapping.Column;
@@ -47,9 +46,6 @@
4746
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
4847
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
4948
import org.springframework.data.relational.core.sql.Aliased;
50-
import org.springframework.data.relational.core.sql.IdentifierProcessing;
51-
import org.springframework.data.relational.core.sql.IdentifierProcessing.LetterCasing;
52-
import org.springframework.data.relational.core.sql.IdentifierProcessing.Quoting;
5349
import org.springframework.data.relational.core.sql.SqlIdentifier;
5450
import org.springframework.data.relational.core.sql.Table;
5551
import org.springframework.data.relational.domain.Identifier;
@@ -243,8 +239,8 @@ public void findAllPaged() {
243239
"FROM dummy_entity ", //
244240
"LEFT OUTER JOIN referenced_entity AS ref ON ref.dummy_entity = dummy_entity.id1", //
245241
"LEFT OUTER JOIN second_level_referenced_entity AS ref_further ON ref_further.referenced_entity = ref.x_l1id", //
246-
"OFFSET 40 ROWS", //
247-
"FETCH FIRST 20 ROWS ONLY");
242+
"OFFSET 40", //
243+
"LIMIT 20");
248244
}
249245

250246
@Test // DATAJDBC-101
@@ -264,8 +260,8 @@ public void findAllPagedAndSorted() {
264260
"LEFT OUTER JOIN referenced_entity AS ref ON ref.dummy_entity = dummy_entity.id1", //
265261
"LEFT OUTER JOIN second_level_referenced_entity AS ref_further ON ref_further.referenced_entity = ref.x_l1id", //
266262
"ORDER BY x_name ASC", //
267-
"OFFSET 30 ROWS", //
268-
"FETCH FIRST 10 ROWS ONLY");
263+
"OFFSET 30", //
264+
"LIMIT 10");
269265
}
270266

271267
@Test // DATAJDBC-131, DATAJDBC-111

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/NonQuotingDialect.java

-35
This file was deleted.

spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/Table.java

-2
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@ public class Table extends AbstractSegment {
3636
private final SqlIdentifier name;
3737

3838
Table(String name) {
39-
super();
4039
this.name = SqlIdentifier.unquoted(name);
4140
}
4241

4342
Table(SqlIdentifier name) {
44-
super();
4543
this.name = name;
4644
}
4745

spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/render/ColumnVisitor.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,12 @@ class ColumnVisitor extends TypedSubtreeVisitor<Column> {
4949
Delegation leaveMatched(Column segment) {
5050

5151
SqlIdentifier column = context.getNamingStrategy().getName(segment);
52-
StringBuilder builder = new StringBuilder();
53-
if (considerTablePrefix && tableName != null) {
5452

55-
builder.append(NameRenderer.render(context, SqlIdentifier.from(tableName, column)));
56-
} else {
57-
builder.append(NameRenderer.render(context, segment));
58-
}
53+
CharSequence name = considerTablePrefix && tableName != null
54+
? NameRenderer.render(context, SqlIdentifier.from(tableName, column))
55+
: NameRenderer.render(context, segment);
5956

60-
target.onRendered(builder);
57+
target.onRendered(name);
6158
return super.leaveMatched(segment);
6259
}
6360

spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/render/JoinVisitor.java

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class JoinVisitor extends TypedSubtreeVisitor<Join> {
3838
private boolean hasSeenCondition = false;
3939

4040
JoinVisitor(RenderContext context, RenderTarget parent) {
41+
4142
this.context = context;
4243
this.parent = parent;
4344
this.conditionVisitor = new ConditionVisitor(context);
@@ -87,6 +88,7 @@ Delegation enterNested(Visitable segment) {
8788
Delegation leaveNested(Visitable segment) {
8889

8990
if (segment instanceof Condition) {
91+
9092
inCondition = false;
9193

9294
if (hasSeenCondition) {

0 commit comments

Comments
 (0)