All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.ebean.config.dbplatform.SqlErrorCodes Maven / Gradle / Ivy

There is a newer version: 15.6.0
Show newest version
package io.ebean.config.dbplatform;

import java.util.HashMap;
import java.util.Map;

/**
 * Used to build a SQLCodeTranslator given DB platform specific codes.
 */
public class SqlErrorCodes {

  private Map map = new HashMap<>();

  /**
   * Map the codes to AcquireLockException.
   */
  public SqlErrorCodes addAcquireLock(String... codes) {
    return add(DataErrorType.AcquireLock, codes);
  }

  /**
   * Map the codes to DataIntegrityException.
   */
  public SqlErrorCodes addDataIntegrity(String... codes) {
    return add(DataErrorType.DataIntegrity, codes);
  }

  /**
   * Map the codes to DuplicateKeyException.
   */
  public SqlErrorCodes addDuplicateKey(String... codes) {
    return add(DataErrorType.DuplicateKey, codes);
  }

  private SqlErrorCodes add(DataErrorType type, String... codes) {
    for (String code : codes) {
      map.put(code, type);
    }
    return this;
  }

  /**
   * Build and return the SQLCodeTranslator with the mapped codes.
   */
  public SqlCodeTranslator build() {
    return new SqlCodeTranslator(map);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy