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 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  private SqlErrorCodes add(DataErrorType type, String... codes) {
035    for (String code : codes) {
036      map.put(code, type);
037    }
038    return this;
039  }
040
041  /**
042   * Build and return the SQLCodeTranslator with the mapped codes.
043   */
044  public SqlCodeTranslator build() {
045    return new SqlCodeTranslator(map);
046  }
047}