|
16 | 16 | package org.springframework.data.mongodb.core;
|
17 | 17 |
|
18 | 18 | import java.util.Arrays;
|
19 |
| -import java.util.HashMap; |
20 | 19 | import java.util.HashSet;
|
21 | 20 | import java.util.Set;
|
22 | 21 |
|
|
29 | 28 | import org.springframework.dao.PermissionDeniedDataAccessException;
|
30 | 29 | import org.springframework.dao.support.PersistenceExceptionTranslator;
|
31 | 30 | import org.springframework.data.mongodb.UncategorizedMongoDbException;
|
| 31 | +import org.springframework.data.mongodb.util.MongoDbErrorCodes; |
32 | 32 | import org.springframework.util.ClassUtils;
|
33 | 33 |
|
34 | 34 | import com.mongodb.MongoException;
|
@@ -106,126 +106,4 @@ public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
|
106 | 106 | // that translation should not occur.
|
107 | 107 | return null;
|
108 | 108 | }
|
109 |
| - |
110 |
| - /** |
111 |
| - * {@link MongoDbErrorCodes} holds MongoDB specific error codes outlined in {@literal mongo/base/error_codes.err}. |
112 |
| - * |
113 |
| - * @author Christoph Strobl |
114 |
| - * @since 1.8 |
115 |
| - */ |
116 |
| - public static final class MongoDbErrorCodes { |
117 |
| - |
118 |
| - static HashMap<Integer, String> dataAccessResourceFailureCodes; |
119 |
| - static HashMap<Integer, String> dataIntegrityViolationCodes; |
120 |
| - static HashMap<Integer, String> duplicateKeyCodes; |
121 |
| - static HashMap<Integer, String> invalidDataAccessApiUsageExeption; |
122 |
| - static HashMap<Integer, String> permissionDeniedCodes; |
123 |
| - |
124 |
| - static HashMap<Integer, String> errorCodes; |
125 |
| - |
126 |
| - static { |
127 |
| - |
128 |
| - dataAccessResourceFailureCodes = new HashMap<Integer, String>(10); |
129 |
| - dataAccessResourceFailureCodes.put(6, "HostUnreachable"); |
130 |
| - dataAccessResourceFailureCodes.put(7, "HostNotFound"); |
131 |
| - dataAccessResourceFailureCodes.put(89, "NetworkTimeout"); |
132 |
| - dataAccessResourceFailureCodes.put(91, "ShutdownInProgress"); |
133 |
| - dataAccessResourceFailureCodes.put(12000, "SlaveDelayDifferential"); |
134 |
| - dataAccessResourceFailureCodes.put(10084, "CannotFindMapFile64Bit"); |
135 |
| - dataAccessResourceFailureCodes.put(10085, "CannotFindMapFile"); |
136 |
| - dataAccessResourceFailureCodes.put(10357, "ShutdownInProgress"); |
137 |
| - dataAccessResourceFailureCodes.put(10359, "Header==0"); |
138 |
| - dataAccessResourceFailureCodes.put(13440, "BadOffsetInFile"); |
139 |
| - dataAccessResourceFailureCodes.put(13441, "BadOffsetInFile"); |
140 |
| - dataAccessResourceFailureCodes.put(13640, "DataFileHeaderCorrupt"); |
141 |
| - |
142 |
| - dataIntegrityViolationCodes = new HashMap<Integer, String>(6); |
143 |
| - dataIntegrityViolationCodes.put(67, "CannotCreateIndex"); |
144 |
| - dataIntegrityViolationCodes.put(68, "IndexAlreadyExists"); |
145 |
| - dataIntegrityViolationCodes.put(85, "IndexOptionsConflict"); |
146 |
| - dataIntegrityViolationCodes.put(86, "IndexKeySpecsConflict"); |
147 |
| - dataIntegrityViolationCodes.put(112, "WriteConflict"); |
148 |
| - dataIntegrityViolationCodes.put(117, "ConflictingOperationInProgress"); |
149 |
| - |
150 |
| - duplicateKeyCodes = new HashMap<Integer, String>(3); |
151 |
| - duplicateKeyCodes.put(3, "OBSOLETE_DuplicateKey"); |
152 |
| - duplicateKeyCodes.put(84, "DuplicateKeyValue"); |
153 |
| - duplicateKeyCodes.put(11000, "DuplicateKey"); |
154 |
| - duplicateKeyCodes.put(11001, "DuplicateKey"); |
155 |
| - |
156 |
| - invalidDataAccessApiUsageExeption = new HashMap<Integer, String>(); |
157 |
| - invalidDataAccessApiUsageExeption.put(5, "GraphContainsCycle"); |
158 |
| - invalidDataAccessApiUsageExeption.put(9, "FailedToParse"); |
159 |
| - invalidDataAccessApiUsageExeption.put(14, "TypeMismatch"); |
160 |
| - invalidDataAccessApiUsageExeption.put(15, "Overflow"); |
161 |
| - invalidDataAccessApiUsageExeption.put(16, "InvalidLength"); |
162 |
| - invalidDataAccessApiUsageExeption.put(20, "IllegalOperation"); |
163 |
| - invalidDataAccessApiUsageExeption.put(21, "EmptyArrayOperation"); |
164 |
| - invalidDataAccessApiUsageExeption.put(22, "InvalidBSON"); |
165 |
| - invalidDataAccessApiUsageExeption.put(23, "AlreadyInitialized"); |
166 |
| - invalidDataAccessApiUsageExeption.put(29, "NonExistentPath"); |
167 |
| - invalidDataAccessApiUsageExeption.put(30, "InvalidPath"); |
168 |
| - invalidDataAccessApiUsageExeption.put(40, "ConflictingUpdateOperators"); |
169 |
| - invalidDataAccessApiUsageExeption.put(45, "UserDataInconsistent"); |
170 |
| - invalidDataAccessApiUsageExeption.put(30, "DollarPrefixedFieldName"); |
171 |
| - invalidDataAccessApiUsageExeption.put(52, "InvalidPath"); |
172 |
| - invalidDataAccessApiUsageExeption.put(53, "InvalidIdField"); |
173 |
| - invalidDataAccessApiUsageExeption.put(54, "NotSingleValueField"); |
174 |
| - invalidDataAccessApiUsageExeption.put(55, "InvalidDBRef"); |
175 |
| - invalidDataAccessApiUsageExeption.put(56, "EmptyFieldName"); |
176 |
| - invalidDataAccessApiUsageExeption.put(57, "DottedFieldName"); |
177 |
| - invalidDataAccessApiUsageExeption.put(59, "CommandNotFound"); |
178 |
| - invalidDataAccessApiUsageExeption.put(60, "DatabaseNotFound"); |
179 |
| - invalidDataAccessApiUsageExeption.put(61, "ShardKeyNotFound"); |
180 |
| - invalidDataAccessApiUsageExeption.put(62, "OplogOperationUnsupported"); |
181 |
| - invalidDataAccessApiUsageExeption.put(66, "ImmutableField"); |
182 |
| - invalidDataAccessApiUsageExeption.put(72, "InvalidOptions"); |
183 |
| - invalidDataAccessApiUsageExeption.put(115, "CommandNotSupported"); |
184 |
| - invalidDataAccessApiUsageExeption.put(116, "DocTooLargeForCapped"); |
185 |
| - invalidDataAccessApiUsageExeption.put(130, "SymbolNotFound"); |
186 |
| - invalidDataAccessApiUsageExeption.put(17280, "KeyTooLong"); |
187 |
| - invalidDataAccessApiUsageExeption.put(13334, "ShardKeyTooBig"); |
188 |
| - |
189 |
| - permissionDeniedCodes = new HashMap<Integer, String>(); |
190 |
| - permissionDeniedCodes.put(11, "UserNotFound"); |
191 |
| - permissionDeniedCodes.put(18, "AuthenticationFailed"); |
192 |
| - permissionDeniedCodes.put(31, "RoleNotFound"); |
193 |
| - permissionDeniedCodes.put(32, "RolesNotRelated"); |
194 |
| - permissionDeniedCodes.put(33, "PrvilegeNotFound"); |
195 |
| - permissionDeniedCodes.put(15847, "CannotAuthenticate"); |
196 |
| - permissionDeniedCodes.put(16704, "CannotAuthenticateToAdminDB"); |
197 |
| - permissionDeniedCodes.put(16705, "CannotAuthenticateToAdminDB"); |
198 |
| - |
199 |
| - errorCodes = new HashMap<Integer, String>(); |
200 |
| - errorCodes.putAll(dataAccessResourceFailureCodes); |
201 |
| - errorCodes.putAll(dataIntegrityViolationCodes); |
202 |
| - errorCodes.putAll(duplicateKeyCodes); |
203 |
| - errorCodes.putAll(invalidDataAccessApiUsageExeption); |
204 |
| - errorCodes.putAll(permissionDeniedCodes); |
205 |
| - } |
206 |
| - |
207 |
| - public static boolean isDataIntegrityViolationCode(Integer errorCode) { |
208 |
| - return errorCode == null ? false : dataIntegrityViolationCodes.containsKey(errorCode); |
209 |
| - } |
210 |
| - |
211 |
| - public static boolean isDataAccessResourceFailureCode(Integer errorCode) { |
212 |
| - return errorCode == null ? false : dataAccessResourceFailureCodes.containsKey(errorCode); |
213 |
| - } |
214 |
| - |
215 |
| - public static boolean isDuplicateKeyCode(Integer errorCode) { |
216 |
| - return errorCode == null ? false : duplicateKeyCodes.containsKey(errorCode); |
217 |
| - } |
218 |
| - |
219 |
| - public static boolean isPermissionDeniedCode(Integer errorCode) { |
220 |
| - return errorCode == null ? false : permissionDeniedCodes.containsKey(errorCode); |
221 |
| - } |
222 |
| - |
223 |
| - public static boolean isInvalidDataAccessApiUsageCode(Integer errorCode) { |
224 |
| - return errorCode == null ? false : invalidDataAccessApiUsageExeption.containsKey(errorCode); |
225 |
| - } |
226 |
| - |
227 |
| - public static String getErrorDescription(Integer errorCode) { |
228 |
| - return errorCode == null ? null : errorCodes.get(errorCode); |
229 |
| - } |
230 |
| - } |
231 | 109 | }
|
0 commit comments