Skip to content

Commit 141f2d7

Browse files
committed
DATAJDBC-340 - Polishing.
Encapsulate column caches in Columns type. Relax RelationalMappingContext to MappingContext with appropriate generics. Remove unused SQL generator source. Cache table and Id column objects. Simplify assertions. Consistently use naming pattern for named parameters. Migrate http URLs to https. Original pull request: #147.
1 parent 810c62b commit 141f2d7

11 files changed

+343
-211
lines changed

mvnw

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# "License"); you may not use this file except in compliance
99
# with the License. You may obtain a copy of the License at
1010
#
11-
# http://www.apache.org/licenses/LICENSE-2.0
11+
# https://www.apache.org/licenses/LICENSE-2.0
1212
#
1313
# Unless required by applicable law or agreed to in writing,
1414
# software distributed under the License is distributed on an

mvnw.cmd

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@REM "License"); you may not use this file except in compliance
88
@REM with the License. You may obtain a copy of the License at
99
@REM
10-
@REM http://www.apache.org/licenses/LICENSE-2.0
10+
@REM https://www.apache.org/licenses/LICENSE-2.0
1111
@REM
1212
@REM Unless required by applicable law or agreed to in writing,
1313
@REM software distributed under the License is distributed on an
@@ -122,7 +122,7 @@ set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
122122

123123
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
124124
FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO (
125-
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
125+
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
126126
)
127127

128128
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central

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

+21-19
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -15,10 +15,8 @@
1515
*/
1616
package org.springframework.data.jdbc.core;
1717

18-
import java.util.Objects;
19-
2018
import org.springframework.data.mapping.PersistentPropertyPath;
21-
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
19+
import org.springframework.data.mapping.context.MappingContext;
2220
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
2321
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
2422
import org.springframework.lang.Nullable;
@@ -34,10 +32,11 @@
3432
class PersistentPropertyPathExtension {
3533

3634
private final RelationalPersistentEntity<?> entity;
37-
private final PersistentPropertyPath<RelationalPersistentProperty> path;
38-
private final RelationalMappingContext context;
35+
private final @Nullable PersistentPropertyPath<RelationalPersistentProperty> path;
36+
private final MappingContext<RelationalPersistentEntity<?>, RelationalPersistentProperty> context;
3937

40-
PersistentPropertyPathExtension(RelationalMappingContext context, RelationalPersistentEntity<?> entity) {
38+
PersistentPropertyPathExtension(MappingContext<RelationalPersistentEntity<?>, RelationalPersistentProperty> context,
39+
RelationalPersistentEntity<?> entity) {
4140

4241
Assert.notNull(context, "Context must not be null.");
4342
Assert.notNull(entity, "Entity must not be null.");
@@ -47,15 +46,15 @@ class PersistentPropertyPathExtension {
4746
this.path = null;
4847
}
4948

50-
PersistentPropertyPathExtension(RelationalMappingContext context,
49+
PersistentPropertyPathExtension(MappingContext<RelationalPersistentEntity<?>, RelationalPersistentProperty> context,
5150
PersistentPropertyPath<RelationalPersistentProperty> path) {
5251

5352
Assert.notNull(context, "Context must not be null.");
5453
Assert.notNull(path, "Path must not be null.");
55-
Assert.isTrue(!path.isEmpty(), "Path must not be empty.");
54+
Assert.notNull(path.getBaseProperty(), "Path must not be empty.");
5655

5756
this.context = context;
58-
this.entity = Objects.requireNonNull(path.getBaseProperty()).getOwner();
57+
this.entity = path.getBaseProperty().getOwner();
5958
this.path = path;
6059
}
6160

@@ -140,6 +139,8 @@ boolean isCollectionLike() {
140139
*/
141140
String getReverseColumnName() {
142141

142+
Assert.state(path != null, "Path is null");
143+
143144
return path.getRequiredLeafProperty().getReverseColumnName();
144145
}
145146

@@ -160,6 +161,8 @@ String getReverseColumnNameAlias() {
160161
*/
161162
String getColumnName() {
162163

164+
Assert.state(path != null, "Path is null");
165+
163166
return assembleColumnName(path.getRequiredLeafProperty().getColumnName());
164167
}
165168

@@ -212,11 +215,9 @@ String getTableName() {
212215
String getTableAlias() {
213216

214217
PersistentPropertyPathExtension tableOwner = getTableOwningAncestor();
215-
if (tableOwner.path == null) {
216-
return null;
217-
}
218218

219-
return tableOwner.assembleTableAlias();
219+
return tableOwner.path == null ? null : tableOwner.assembleTableAlias();
220+
220221
}
221222

222223
/**
@@ -251,14 +252,13 @@ int getLength() {
251252
*/
252253
private PersistentPropertyPathExtension getTableOwningAncestor() {
253254

254-
if (isEntity() && !isEmbedded()) {
255-
return this;
256-
}
257-
return getParentPath().getTableOwningAncestor();
255+
return isEntity() && !isEmbedded() ? this : getParentPath().getTableOwningAncestor();
258256
}
259257

260258
private String assembleTableAlias() {
261259

260+
Assert.state(path != null, "Path is null");
261+
262262
RelationalPersistentProperty leafProperty = path.getRequiredLeafProperty();
263263
String prefix = isEmbedded() ? leafProperty.getEmbeddedPrefix() : leafProperty.getName();
264264

@@ -274,6 +274,8 @@ private String assembleTableAlias() {
274274

275275
private String assembleColumnName(String suffix) {
276276

277+
Assert.state(path != null, "Path is null");
278+
277279
if (path.getLength() <= 1) {
278280
return suffix;
279281
}
@@ -286,11 +288,11 @@ private String assembleColumnName(String suffix) {
286288
return getParentPath().assembleColumnName(embeddedPrefix + suffix);
287289
}
288290

291+
@SuppressWarnings("unchecked")
289292
private RelationalPersistentEntity<?> getRequiredLeafEntity() {
290293
return path == null ? entity : context.getRequiredPersistentEntity(path.getRequiredLeafProperty().getActualType());
291294
}
292295

293-
294296
private String prefixWithTableAlias(String columnName) {
295297

296298
String tableAlias = getTableAlias();

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

+9-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -24,18 +24,25 @@
2424
* Utility to get from path to SQL DSL elements.
2525
*
2626
* @author Jens Schauder
27+
* @author Mark Paluch
2728
* @since 1.1
2829
*/
2930
class SqlContext {
3031

3132
private final RelationalPersistentEntity<?> entity;
33+
private final Table table;
3234

3335
SqlContext(RelationalPersistentEntity<?> entity) {
3436
this.entity = entity;
37+
this.table = SQL.table(entity.getTableName());
3538
}
3639

3740
Column getIdColumn() {
38-
return getTable().column(entity.getIdColumn());
41+
return table.column(entity.getIdColumn());
42+
}
43+
44+
Table getTable() {
45+
return table;
3946
}
4047

4148
Table getTable(PersistentPropertyPathExtension path) {
@@ -45,10 +52,6 @@ Table getTable(PersistentPropertyPathExtension path) {
4552
return tableAlias == null ? table : table.as(tableAlias);
4653
}
4754

48-
Table getTable() {
49-
return SQL.table(entity.getTableName());
50-
}
51-
5255
Column getColumn(PersistentPropertyPathExtension path) {
5356
return getTable(path).column(path.getColumnName()).as(path.getColumnAlias());
5457
}

0 commit comments

Comments
 (0)