5
5
* you may not use this file except in compliance with the License.
6
6
* You may obtain a copy of the License at
7
7
*
8
- * http ://www.apache.org/licenses/LICENSE-2.0
8
+ * https ://www.apache.org/licenses/LICENSE-2.0
9
9
*
10
10
* Unless required by applicable law or agreed to in writing, software
11
11
* distributed under the License is distributed on an "AS IS" BASIS,
15
15
*/
16
16
package org .springframework .data .jdbc .core ;
17
17
18
- import java .util .Objects ;
19
-
20
18
import org .springframework .data .mapping .PersistentPropertyPath ;
21
- import org .springframework .data .relational . core . mapping .RelationalMappingContext ;
19
+ import org .springframework .data .mapping .context . MappingContext ;
22
20
import org .springframework .data .relational .core .mapping .RelationalPersistentEntity ;
23
21
import org .springframework .data .relational .core .mapping .RelationalPersistentProperty ;
24
22
import org .springframework .lang .Nullable ;
34
32
class PersistentPropertyPathExtension {
35
33
36
34
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 ;
39
37
40
- PersistentPropertyPathExtension (RelationalMappingContext context , RelationalPersistentEntity <?> entity ) {
38
+ PersistentPropertyPathExtension (MappingContext <RelationalPersistentEntity <?>, RelationalPersistentProperty > context ,
39
+ RelationalPersistentEntity <?> entity ) {
41
40
42
41
Assert .notNull (context , "Context must not be null." );
43
42
Assert .notNull (entity , "Entity must not be null." );
@@ -47,15 +46,15 @@ class PersistentPropertyPathExtension {
47
46
this .path = null ;
48
47
}
49
48
50
- PersistentPropertyPathExtension (RelationalMappingContext context ,
49
+ PersistentPropertyPathExtension (MappingContext < RelationalPersistentEntity <?>, RelationalPersistentProperty > context ,
51
50
PersistentPropertyPath <RelationalPersistentProperty > path ) {
52
51
53
52
Assert .notNull (context , "Context must not be null." );
54
53
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." );
56
55
57
56
this .context = context ;
58
- this .entity = Objects . requireNonNull ( path .getBaseProperty () ).getOwner ();
57
+ this .entity = path .getBaseProperty ().getOwner ();
59
58
this .path = path ;
60
59
}
61
60
@@ -140,6 +139,8 @@ boolean isCollectionLike() {
140
139
*/
141
140
String getReverseColumnName () {
142
141
142
+ Assert .state (path != null , "Path is null" );
143
+
143
144
return path .getRequiredLeafProperty ().getReverseColumnName ();
144
145
}
145
146
@@ -160,6 +161,8 @@ String getReverseColumnNameAlias() {
160
161
*/
161
162
String getColumnName () {
162
163
164
+ Assert .state (path != null , "Path is null" );
165
+
163
166
return assembleColumnName (path .getRequiredLeafProperty ().getColumnName ());
164
167
}
165
168
@@ -212,11 +215,9 @@ String getTableName() {
212
215
String getTableAlias () {
213
216
214
217
PersistentPropertyPathExtension tableOwner = getTableOwningAncestor ();
215
- if (tableOwner .path == null ) {
216
- return null ;
217
- }
218
218
219
- return tableOwner .assembleTableAlias ();
219
+ return tableOwner .path == null ? null : tableOwner .assembleTableAlias ();
220
+
220
221
}
221
222
222
223
/**
@@ -251,14 +252,13 @@ int getLength() {
251
252
*/
252
253
private PersistentPropertyPathExtension getTableOwningAncestor () {
253
254
254
- if (isEntity () && !isEmbedded ()) {
255
- return this ;
256
- }
257
- return getParentPath ().getTableOwningAncestor ();
255
+ return isEntity () && !isEmbedded () ? this : getParentPath ().getTableOwningAncestor ();
258
256
}
259
257
260
258
private String assembleTableAlias () {
261
259
260
+ Assert .state (path != null , "Path is null" );
261
+
262
262
RelationalPersistentProperty leafProperty = path .getRequiredLeafProperty ();
263
263
String prefix = isEmbedded () ? leafProperty .getEmbeddedPrefix () : leafProperty .getName ();
264
264
@@ -274,6 +274,8 @@ private String assembleTableAlias() {
274
274
275
275
private String assembleColumnName (String suffix ) {
276
276
277
+ Assert .state (path != null , "Path is null" );
278
+
277
279
if (path .getLength () <= 1 ) {
278
280
return suffix ;
279
281
}
@@ -286,11 +288,11 @@ private String assembleColumnName(String suffix) {
286
288
return getParentPath ().assembleColumnName (embeddedPrefix + suffix );
287
289
}
288
290
291
+ @ SuppressWarnings ("unchecked" )
289
292
private RelationalPersistentEntity <?> getRequiredLeafEntity () {
290
293
return path == null ? entity : context .getRequiredPersistentEntity (path .getRequiredLeafProperty ().getActualType ());
291
294
}
292
295
293
-
294
296
private String prefixWithTableAlias (String columnName ) {
295
297
296
298
String tableAlias = getTableAlias ();
0 commit comments