29
29
import org .springframework .data .relational .core .dialect .LockClause ;
30
30
import org .springframework .data .relational .core .sql .IdentifierProcessing ;
31
31
import org .springframework .data .relational .core .sql .SqlIdentifier ;
32
+ import org .springframework .jdbc .core .namedparam .NamedParameterJdbcOperations ;
32
33
import org .springframework .jdbc .core .namedparam .SqlParameterSource ;
33
34
import org .springframework .jdbc .support .KeyHolder ;
34
35
@@ -41,7 +42,7 @@ class IdGeneratingBatchInsertStrategyTest {
41
42
42
43
SqlIdentifier idColumn = SqlIdentifier .quoted ("id" );
43
44
IdentifierProcessing identifierProcessing = IdentifierProcessing .ANSI ;
44
- BatchJdbcOperations batchJdbcOperations = mock (BatchJdbcOperations .class );
45
+ NamedParameterJdbcOperations jdbcOperations = mock (NamedParameterJdbcOperations .class );
45
46
InsertStrategy insertStrategy = mock (InsertStrategy .class );
46
47
String sql = "some sql" ;
47
48
SqlParameterSource [] sqlParameterSources = new SqlParameterSource [] { new SqlIdentifierParameterSource () };
@@ -50,7 +51,7 @@ class IdGeneratingBatchInsertStrategyTest {
50
51
void insertsSequentially_whenIdGenerationForBatchOperationsNotSupported () {
51
52
52
53
BatchInsertStrategy batchInsertStrategy = new IdGeneratingBatchInsertStrategy (insertStrategy ,
53
- createDialect (identifierProcessing , true , false ), batchJdbcOperations , idColumn );
54
+ createDialect (identifierProcessing , true , false ), jdbcOperations , idColumn );
54
55
55
56
SqlIdentifierParameterSource sqlParameterSource1 = new SqlIdentifierParameterSource ();
56
57
sqlParameterSource1 .addValue (SqlIdentifier .quoted ("property1" ), "value1" );
@@ -72,41 +73,41 @@ void insertsSequentially_whenIdGenerationForBatchOperationsNotSupported() {
72
73
void insertsWithKeyHolderAndKeyColumnNames_whenDriverRequiresKeyColumnNames () {
73
74
74
75
BatchInsertStrategy batchInsertStrategy = new IdGeneratingBatchInsertStrategy (insertStrategy ,
75
- createDialect (identifierProcessing , true , true ), batchJdbcOperations , idColumn );
76
+ createDialect (identifierProcessing , true , true ), jdbcOperations , idColumn );
76
77
77
78
batchInsertStrategy .execute (sql , sqlParameterSources );
78
79
79
- verify (batchJdbcOperations ).batchUpdate (eq (sql ), eq (sqlParameterSources ), any (KeyHolder .class ),
80
+ verify (jdbcOperations ).batchUpdate (eq (sql ), eq (sqlParameterSources ), any (KeyHolder .class ),
80
81
eq (new String [] { idColumn .getReference () }));
81
82
}
82
83
83
84
@ Test
84
85
void insertsWithKeyHolder_whenDriverRequiresKeyColumnNames_butIdColumnIsNull () {
85
86
86
87
BatchInsertStrategy batchInsertStrategy = new IdGeneratingBatchInsertStrategy (insertStrategy ,
87
- createDialect (identifierProcessing , true , true ), batchJdbcOperations , null );
88
+ createDialect (identifierProcessing , true , true ), jdbcOperations , null );
88
89
89
90
batchInsertStrategy .execute (sql , sqlParameterSources );
90
91
91
- verify (batchJdbcOperations ).batchUpdate (eq (sql ), eq (sqlParameterSources ), any (KeyHolder .class ));
92
+ verify (jdbcOperations ).batchUpdate (eq (sql ), eq (sqlParameterSources ), any (KeyHolder .class ));
92
93
}
93
94
94
95
@ Test
95
96
void insertsWithKeyHolder_whenDriverDoesNotRequireKeyColumnNames () {
96
97
97
98
BatchInsertStrategy batchInsertStrategy = new IdGeneratingBatchInsertStrategy (insertStrategy ,
98
- createDialect (identifierProcessing , false , true ), batchJdbcOperations , idColumn );
99
+ createDialect (identifierProcessing , false , true ), jdbcOperations , idColumn );
99
100
100
101
batchInsertStrategy .execute (sql , sqlParameterSources );
101
102
102
- verify (batchJdbcOperations ).batchUpdate (eq (sql ), eq (sqlParameterSources ), any (KeyHolder .class ));
103
+ verify (jdbcOperations ).batchUpdate (eq (sql ), eq (sqlParameterSources ), any (KeyHolder .class ));
103
104
}
104
105
105
106
@ Test
106
107
void insertsWithKeyHolder_returningKey_whenThereIsOnlyOne () {
107
108
108
109
Long idValue = 123L ;
109
- when (batchJdbcOperations .batchUpdate (any (), any (), any ())).thenAnswer (invocationOnMock -> {
110
+ when (jdbcOperations .batchUpdate (any (), any (), any ())).thenAnswer (invocationOnMock -> {
110
111
111
112
KeyHolder keyHolder = invocationOnMock .getArgument (2 );
112
113
HashMap <String , Object > keys = new HashMap <>();
@@ -115,7 +116,7 @@ void insertsWithKeyHolder_returningKey_whenThereIsOnlyOne() {
115
116
return null ;
116
117
});
117
118
BatchInsertStrategy batchInsertStrategy = new IdGeneratingBatchInsertStrategy (insertStrategy ,
118
- createDialect (identifierProcessing , false , true ), batchJdbcOperations , idColumn );
119
+ createDialect (identifierProcessing , false , true ), jdbcOperations , idColumn );
119
120
120
121
Object [] ids = batchInsertStrategy .execute (sql , sqlParameterSources );
121
122
@@ -126,7 +127,7 @@ void insertsWithKeyHolder_returningKey_whenThereIsOnlyOne() {
126
127
void insertsWithKeyHolder_returningKeyMatchingIdColumn_whenKeyHolderContainsMultipleKeysPerRecord () {
127
128
128
129
Long idValue = 123L ;
129
- when (batchJdbcOperations .batchUpdate (any (), any (), any ())).thenAnswer (invocationOnMock -> {
130
+ when (jdbcOperations .batchUpdate (any (), any (), any ())).thenAnswer (invocationOnMock -> {
130
131
131
132
KeyHolder keyHolder = invocationOnMock .getArgument (2 );
132
133
HashMap <String , Object > keys = new HashMap <>();
@@ -136,7 +137,7 @@ void insertsWithKeyHolder_returningKeyMatchingIdColumn_whenKeyHolderContainsMult
136
137
return null ;
137
138
});
138
139
BatchInsertStrategy batchInsertStrategy = new IdGeneratingBatchInsertStrategy (insertStrategy ,
139
- createDialect (identifierProcessing , false , true ), batchJdbcOperations , idColumn );
140
+ createDialect (identifierProcessing , false , true ), jdbcOperations , idColumn );
140
141
141
142
Object [] ids = batchInsertStrategy .execute (sql , sqlParameterSources );
142
143
@@ -147,7 +148,7 @@ void insertsWithKeyHolder_returningKeyMatchingIdColumn_whenKeyHolderContainsMult
147
148
void insertsWithKeyHolder_returningNull__whenKeyHolderContainsMultipleKeysPerRecord_butIdColumnIsNull () {
148
149
149
150
Long idValue = 123L ;
150
- when (batchJdbcOperations .batchUpdate (any (), any (), any ())).thenAnswer (invocationOnMock -> {
151
+ when (jdbcOperations .batchUpdate (any (), any (), any ())).thenAnswer (invocationOnMock -> {
151
152
152
153
KeyHolder keyHolder = invocationOnMock .getArgument (2 );
153
154
HashMap <String , Object > keys = new HashMap <>();
@@ -157,7 +158,7 @@ void insertsWithKeyHolder_returningNull__whenKeyHolderContainsMultipleKeysPerRec
157
158
return null ;
158
159
});
159
160
BatchInsertStrategy batchInsertStrategy = new IdGeneratingBatchInsertStrategy (insertStrategy ,
160
- createDialect (identifierProcessing , false , true ), batchJdbcOperations , null );
161
+ createDialect (identifierProcessing , false , true ), jdbcOperations , null );
161
162
162
163
Object [] ids = batchInsertStrategy .execute (sql , sqlParameterSources );
163
164
@@ -169,7 +170,7 @@ void insertsWithKeyHolder_returningNull__whenKeyHolderContainsMultipleKeysPerRec
169
170
void insertsWithKeyHolder_returningNull_whenKeyHolderHasNoKeys () {
170
171
171
172
BatchInsertStrategy batchInsertStrategy = new IdGeneratingBatchInsertStrategy (insertStrategy ,
172
- createDialect (identifierProcessing , false , true ), batchJdbcOperations , idColumn );
173
+ createDialect (identifierProcessing , false , true ), jdbcOperations , idColumn );
173
174
174
175
Object [] ids = batchInsertStrategy .execute (sql , sqlParameterSources );
175
176
0 commit comments