// Path: src/main/java/org/lmdbjava/Txn.java
// public static final class BadException extends LmdbNativeException {
// 
//   static final int MDB_BAD_TXN = -30_782;
//   private static final long serialVersionUID = 1L;
// 
//   BadException() {
//     super(MDB_BAD_TXN, "Transaction must abort, has a child, or is invalid");
//   }
// }
// 
// Path: src/main/java/org/lmdbjava/Txn.java
// public static final class BadReaderLockException extends LmdbNativeException {
// 
//   static final int MDB_BAD_RSLOT = -30_783;
//   private static final long serialVersionUID = 1L;
// 
//   BadReaderLockException() {
//     super(MDB_BAD_RSLOT, "Invalid reuse of reader locktable slot");
//   }
// }
// 
// Path: src/main/java/org/lmdbjava/Txn.java
// public static final class TxFullException extends LmdbNativeException {
// 
//   static final int MDB_TXN_FULL = -30_788;
//   private static final long serialVersionUID = 1L;
// 
//   TxFullException() {
//     super(MDB_TXN_FULL, "Transaction has too many dirty pages");
//   }
// }


import static jnr.constants.ConstantSet.getConstantSet;
import jnr.constants.Constant;
import jnr.constants.ConstantSet;
import org.lmdbjava.Txn.BadException;
import org.lmdbjava.Txn.BadReaderLockException;
import org.lmdbjava.Txn.TxFullException;
/*-
 * #%L
 * LmdbJava
 * %%
 * Copyright (C) 2016 - 2021 The LmdbJava Open Source Project
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

package org.lmdbjava;



/**
 * Maps a LMDB C result code to the equivalent Java exception.
 *
 * <p>
 * The immutable nature of all LMDB exceptions means the mapper internally
 * maintains a table of them.
 */
@SuppressWarnings("PMD.CyclomaticComplexity")
final class ResultCodeMapper {

  /**
   * Successful result.
   */
  static final int MDB_SUCCESS = 0;

  private static final ConstantSet CONSTANTS;
  private static final String POSIX_ERR_NO = "Errno";

  static {
    CONSTANTS = getConstantSet(POSIX_ERR_NO);
  }

  private ResultCodeMapper() {
  }

  /**
   * Checks the result code and raises an exception is not {@link #MDB_SUCCESS}.
   *
   * @param rc the LMDB result code
   */
  static void checkRc(final int rc) {
    switch (rc) {
      case MDB_SUCCESS:
        return;
      case Dbi.BadDbiException.MDB_BAD_DBI:
        throw new Dbi.BadDbiException();
// Path: src/main/java/org/lmdbjava/Txn.java
// public static final class BadException extends LmdbNativeException {
// 
//   static final int MDB_BAD_TXN = -30_782;
//   private static final long serialVersionUID = 1L;
// 
//   BadException() {
//     super(MDB_BAD_TXN, "Transaction must abort, has a child, or is invalid");
//   }
// }
// 
// Path: src/main/java/org/lmdbjava/Txn.java
// public static final class BadReaderLockException extends LmdbNativeException {
// 
//   static final int MDB_BAD_RSLOT = -30_783;
//   private static final long serialVersionUID = 1L;
// 
//   BadReaderLockException() {
//     super(MDB_BAD_RSLOT, "Invalid reuse of reader locktable slot");
//   }
// }
// 
// Path: src/main/java/org/lmdbjava/Txn.java
// public static final class TxFullException extends LmdbNativeException {
// 
//   static final int MDB_TXN_FULL = -30_788;
//   private static final long serialVersionUID = 1L;
// 
//   TxFullException() {
//     super(MDB_TXN_FULL, "Transaction has too many dirty pages");
//   }
// }


// Path: src/main/java/org/lmdbjava/ResultCodeMapper.java
import static jnr.constants.ConstantSet.getConstantSet;
import jnr.constants.Constant;
import jnr.constants.ConstantSet;
import org.lmdbjava.Txn.BadException;
import org.lmdbjava.Txn.BadReaderLockException;
import org.lmdbjava.Txn.TxFullException;

/*-
 * #%L
 * LmdbJava
 * %%
 * Copyright (C) 2016 - 2021 The LmdbJava Open Source Project
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

package org.lmdbjava;



/**
 * Maps a LMDB C result code to the equivalent Java exception.
 *
 * <p>
 * The immutable nature of all LMDB exceptions means the mapper internally
 * maintains a table of them.
 */
@SuppressWarnings("PMD.CyclomaticComplexity")
final class ResultCodeMapper {

  /**
   * Successful result.
   */
  static final int MDB_SUCCESS = 0;

  private static final ConstantSet CONSTANTS;
  private static final String POSIX_ERR_NO = "Errno";

  static {
    CONSTANTS = getConstantSet(POSIX_ERR_NO);
  }

  private ResultCodeMapper() {
  }

  /**
   * Checks the result code and raises an exception is not {@link #MDB_SUCCESS}.
   *
   * @param rc the LMDB result code
   */
  static void checkRc(final int rc) {
    switch (rc) {
      case MDB_SUCCESS:
        return;
      case Dbi.BadDbiException.MDB_BAD_DBI:
        throw new Dbi.BadDbiException();
      case BadReaderLockException.MDB_BAD_RSLOT: