@@ -128,7 +128,10 @@ public final class MongoDbErrorCodes {
128
128
clientSessionCodes .put (263 , "OperationNotSupportedInTransaction" );
129
129
clientSessionCodes .put (264 , "TooManyLogicalSessions" );
130
130
131
- errorCodes = new HashMap <>();
131
+ errorCodes = new HashMap <>(
132
+ dataAccessResourceFailureCodes .size () + dataIntegrityViolationCodes .size () + duplicateKeyCodes .size ()
133
+ + invalidDataAccessApiUsageException .size () + permissionDeniedCodes .size () + clientSessionCodes .size (),
134
+ 1f );
132
135
errorCodes .putAll (dataAccessResourceFailureCodes );
133
136
errorCodes .putAll (dataIntegrityViolationCodes );
134
137
errorCodes .putAll (duplicateKeyCodes );
@@ -149,12 +152,12 @@ public static boolean isDataIntegrityViolationCode(@Nullable Integer errorCode)
149
152
/**
150
153
* @param exception can be {@literal null}.
151
154
* @return
152
- * @since 3.3
155
+ * @since 4.4
153
156
*/
154
- public static boolean isDataIntegrityViolationError (@ Nullable Exception exception ) {
157
+ public static boolean isDataIntegrityViolationError (Exception exception ) {
155
158
156
- if (exception instanceof MongoException ) {
157
- return isDataIntegrityViolationCode ((( MongoException ) exception ) .getCode ());
159
+ if (exception instanceof MongoException me ) {
160
+ return isDataIntegrityViolationCode (me .getCode ());
158
161
}
159
162
return false ;
160
163
}
@@ -166,12 +169,12 @@ public static boolean isDataAccessResourceFailureCode(@Nullable Integer errorCod
166
169
/**
167
170
* @param exception can be {@literal null}.
168
171
* @return
169
- * @since 3.3
172
+ * @since 4.4
170
173
*/
171
- public static boolean isDataAccessResourceError (@ Nullable Exception exception ) {
174
+ public static boolean isDataAccessResourceError (Exception exception ) {
172
175
173
- if (exception instanceof MongoException ) {
174
- return isDataAccessResourceFailureCode ((( MongoException ) exception ) .getCode ());
176
+ if (exception instanceof MongoException me ) {
177
+ return isDataAccessResourceFailureCode (me .getCode ());
175
178
}
176
179
return false ;
177
180
}
@@ -183,27 +186,23 @@ public static boolean isDuplicateKeyCode(@Nullable Integer errorCode) {
183
186
/**
184
187
* @param exception can be {@literal null}.
185
188
* @return
186
- * @since 3.3
189
+ * @since 4.4
187
190
*/
188
- public static boolean isDuplicateKeyError (@ Nullable Exception exception ) {
191
+ public static boolean isDuplicateKeyError (Exception exception ) {
189
192
190
- if (exception instanceof MongoException ) {
191
- return isDuplicateKeyCode ((( MongoException ) exception ) .getCode ());
193
+ if (exception instanceof MongoException me ) {
194
+ return isDuplicateKeyCode (me .getCode ());
192
195
}
193
196
return false ;
194
197
}
195
198
196
199
/**
197
200
* @param exception can be {@literal null}.
198
201
* @return
199
- * @since 3.3
202
+ * @since 4.4
200
203
*/
201
- public static boolean isDataDuplicateKeyError (@ Nullable Exception exception ) {
202
-
203
- if (exception instanceof MongoException ) {
204
- return isDuplicateKeyCode (((MongoException ) exception ).getCode ());
205
- }
206
- return false ;
204
+ public static boolean isDataDuplicateKeyError (Exception exception ) {
205
+ return isDuplicateKeyError (exception );
207
206
}
208
207
209
208
public static boolean isPermissionDeniedCode (@ Nullable Integer errorCode ) {
@@ -213,11 +212,11 @@ public static boolean isPermissionDeniedCode(@Nullable Integer errorCode) {
213
212
/**
214
213
* @param exception can be {@literal null}.
215
214
* @return
216
- * @since 3.3
215
+ * @since 4.4
217
216
*/
218
- public static boolean isPermissionDeniedError (@ Nullable Exception exception ) {
217
+ public static boolean isPermissionDeniedError (Exception exception ) {
219
218
220
- if (exception instanceof MongoException ) {
219
+ if (exception instanceof MongoException ) {
221
220
return isPermissionDeniedCode (((MongoException ) exception ).getCode ());
222
221
}
223
222
return false ;
@@ -230,12 +229,12 @@ public static boolean isInvalidDataAccessApiUsageCode(@Nullable Integer errorCod
230
229
/**
231
230
* @param exception can be {@literal null}.
232
231
* @return
233
- * @since 3.3
232
+ * @since 4.4
234
233
*/
235
- public static boolean isInvalidDataAccessApiUsageError (@ Nullable Exception exception ) {
234
+ public static boolean isInvalidDataAccessApiUsageError (Exception exception ) {
236
235
237
- if (exception instanceof MongoException ) {
238
- return isInvalidDataAccessApiUsageCode ((( MongoException ) exception ) .getCode ());
236
+ if (exception instanceof MongoException me ) {
237
+ return isInvalidDataAccessApiUsageCode (me .getCode ());
239
238
}
240
239
return false ;
241
240
}
@@ -265,12 +264,12 @@ public static boolean isTransactionFailureCode(@Nullable Integer errorCode) {
265
264
/**
266
265
* @param exception can be {@literal null}.
267
266
* @return
268
- * @since 3.3
267
+ * @since 4.4
269
268
*/
270
- public static boolean isClientSessionFailure (@ Nullable Exception exception ) {
269
+ public static boolean isClientSessionFailure (Exception exception ) {
271
270
272
- if (exception instanceof MongoException ) {
273
- return isClientSessionFailureCode ((( MongoException ) exception ) .getCode ());
271
+ if (exception instanceof MongoException me ) {
272
+ return isClientSessionFailureCode (me .getCode ());
274
273
}
275
274
return false ;
276
275
}
0 commit comments