@@ -65,26 +65,46 @@ public class DefaultDataAccessStrategy implements DataAccessStrategy {
65
65
private final @ NonNull NamedParameterJdbcOperations operations ;
66
66
private final @ NonNull DataAccessStrategy accessStrategy ;
67
67
68
- public DefaultDataAccessStrategy (SqlGeneratorSource sqlGeneratorSource , RelationalMappingContext context ,
69
- JdbcConverter converter , NamedParameterJdbcOperations operations , @ Nullable DataAccessStrategy accessStrategy ) {
70
-
71
- this .sqlGeneratorSource = sqlGeneratorSource ;
72
- this .context = context ;
73
- this .converter = converter ;
74
- this .operations = operations ;
75
- this .accessStrategy = accessStrategy == null ? this : accessStrategy ;
76
- }
77
-
78
68
/**
79
69
* Creates a {@link DefaultDataAccessStrategy} which references it self for resolution of recursive data accesses.
80
70
* Only suitable if this is the only access strategy in use.
71
+ *
72
+ * @param sqlGeneratorSource must not be {@literal null}.
73
+ * @param context must not be {@literal null}.
74
+ * @param converter must not be {@literal null}.
75
+ * @param operations must not be {@literal null}.
81
76
*/
82
77
public DefaultDataAccessStrategy (SqlGeneratorSource sqlGeneratorSource , RelationalMappingContext context ,
83
78
JdbcConverter converter , NamedParameterJdbcOperations operations ) {
84
-
85
79
this (sqlGeneratorSource , context , converter , operations , null );
86
80
}
87
81
82
+ /**
83
+ * Creates a {@link DefaultDataAccessStrategy}
84
+ *
85
+ * @param sqlGeneratorSource must not be {@literal null}.
86
+ * @param context must not be {@literal null}.
87
+ * @param converter must not be {@literal null}.
88
+ * @param operations must not be {@literal null}.
89
+ * @param mappingAccessStrategy can be {@literal null}.
90
+ * @since 1.1
91
+ */
92
+ public DefaultDataAccessStrategy (SqlGeneratorSource sqlGeneratorSource , RelationalMappingContext context ,
93
+ JdbcConverter converter , NamedParameterJdbcOperations operations ,
94
+ @ Nullable DataAccessStrategy mappingAccessStrategy ) {
95
+
96
+ Assert .notNull (sqlGeneratorSource , "SqlGeneratorSource must not be null" );
97
+ Assert .notNull (context , "RelationalMappingContext must not be null" );
98
+ Assert .notNull (converter , "JdbcConverter must not be null" );
99
+ Assert .notNull (operations , "NamedParameterJdbcOperations must not be null" );
100
+
101
+ this .sqlGeneratorSource = sqlGeneratorSource ;
102
+ this .context = context ;
103
+ this .converter = converter ;
104
+ this .operations = operations ;
105
+ this .accessStrategy = mappingAccessStrategy == null ? this : mappingAccessStrategy ;
106
+ }
107
+
88
108
/*
89
109
* (non-Javadoc)
90
110
* @see org.springframework.data.jdbc.core.DataAccessStrategy#insert(java.lang.Object, java.lang.Class, java.util.Map)
@@ -104,7 +124,8 @@ public <T> Object insert(T instance, Class<T> domainType, Identifier identifier)
104
124
KeyHolder holder = new GeneratedKeyHolder ();
105
125
RelationalPersistentEntity <T > persistentEntity = getRequiredPersistentEntity (domainType );
106
126
107
- MapSqlParameterSource parameterSource = getParameterSource (instance , persistentEntity , "" , PersistentProperty ::isIdProperty );
127
+ MapSqlParameterSource parameterSource = getParameterSource (instance , persistentEntity , "" ,
128
+ PersistentProperty ::isIdProperty );
108
129
109
130
identifier .forEach ((name , value , type ) -> addConvertedPropertyValue (parameterSource , name , value , type ));
110
131
@@ -134,7 +155,7 @@ public <S> boolean update(S instance, Class<S> domainType) {
134
155
RelationalPersistentEntity <S > persistentEntity = getRequiredPersistentEntity (domainType );
135
156
136
157
return operations .update (sql (domainType ).getUpdate (),
137
- getParameterSource (instance , persistentEntity , "" , property -> false )) != 0 ;
158
+ getParameterSource (instance , persistentEntity , "" , Predicates . includeAll () )) != 0 ;
138
159
}
139
160
140
161
/*
@@ -289,7 +310,7 @@ public <T> boolean existsById(Object id, Class<T> domainType) {
289
310
}
290
311
291
312
private <S , T > MapSqlParameterSource getParameterSource (S instance , RelationalPersistentEntity <S > persistentEntity ,
292
- String prefix , Predicate <RelationalPersistentProperty > skipProperty ) {
313
+ String prefix , Predicate <RelationalPersistentProperty > skipProperty ) {
293
314
294
315
MapSqlParameterSource parameters = new MapSqlParameterSource ();
295
316
@@ -445,4 +466,19 @@ private <S> RelationalPersistentEntity<S> getRequiredPersistentEntity(Class<S> d
445
466
private SqlGenerator sql (Class <?> domainType ) {
446
467
return sqlGeneratorSource .getSqlGenerator (domainType );
447
468
}
469
+
470
+ /**
471
+ * Utility to create {@link Predicate}s.
472
+ */
473
+ static class Predicates {
474
+
475
+ /**
476
+ * Include all {@link Predicate} returning {@literal false} to never skip a property.
477
+ *
478
+ * @return the include all {@link Predicate}.
479
+ */
480
+ static Predicate <RelationalPersistentProperty > includeAll () {
481
+ return it -> false ;
482
+ }
483
+ }
448
484
}
0 commit comments