001package io.ebean.config.dbplatform; 002 003import java.util.HashMap; 004import java.util.Map; 005 006/** 007 * Used to build a SQLCodeTranslator given DB platform specific codes. 008 */ 009public class SqlErrorCodes { 010 011 private final Map<String, DataErrorType> map = new HashMap<>(); 012 013 /** 014 * Map the codes to AcquireLockException. 015 */ 016 public SqlErrorCodes addAcquireLock(String... codes) { 017 return add(DataErrorType.AcquireLock, codes); 018 } 019 020 /** 021 * Map the codes to DataIntegrityException. 022 */ 023 public SqlErrorCodes addDataIntegrity(String... codes) { 024 return add(DataErrorType.DataIntegrity, codes); 025 } 026 027 /** 028 * Map the codes to DuplicateKeyException. 029 */ 030 public SqlErrorCodes addDuplicateKey(String... codes) { 031 return add(DataErrorType.DuplicateKey, codes); 032 } 033 034 /** 035 * Map the codes to SerializableConflictException. 036 */ 037 public SqlErrorCodes addSerializableConflict(String... codes) { 038 return add(DataErrorType.SerializableConflict, codes); 039 } 040 041 private SqlErrorCodes add(DataErrorType type, String... codes) { 042 for (String code : codes) { 043 map.put(code, type); 044 } 045 return this; 046 } 047 048 /** 049 * Build and return the SQLCodeTranslator with the mapped codes. 050 */ 051 public SqlCodeTranslator build() { 052 return new SqlCodeTranslator(map); 053 } 054}