00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 package com.sleepycat.db;
00011
00012 import com.sleepycat.db.internal.DbConstants;
00013 import com.sleepycat.db.internal.DbEnv;
00014
00015 public final class OperationStatus {
00016 public static final OperationStatus SUCCESS =
00017 new OperationStatus("SUCCESS", 0);
00018 public static final OperationStatus KEYEXIST =
00019 new OperationStatus("KEYEXIST", DbConstants.DB_KEYEXIST);
00020 public static final OperationStatus KEYEMPTY =
00021 new OperationStatus("KEYEMPTY", DbConstants.DB_KEYEMPTY);
00022 public static final OperationStatus NOTFOUND =
00023 new OperationStatus("NOTFOUND", DbConstants.DB_NOTFOUND);
00024
00025
00026 static OperationStatus fromInt(final int errCode) {
00027 switch(errCode) {
00028 case 0:
00029 return SUCCESS;
00030 case DbConstants.DB_KEYEXIST:
00031 return KEYEXIST;
00032 case DbConstants.DB_KEYEMPTY:
00033 return KEYEMPTY;
00034 case DbConstants.DB_NOTFOUND:
00035 return NOTFOUND;
00036 default:
00037 throw new IllegalArgumentException(
00038 "Unknown error code: " + DbEnv.strerror(errCode));
00039 }
00040 }
00041
00042
00043 private String statusName;
00044 private int errCode;
00045
00046 private OperationStatus(final String statusName, int errCode) {
00047 this.statusName = statusName;
00048 this.errCode = errCode;
00049 }
00050
00051 public String toString() {
00052 return "OperationStatus." + statusName;
00053 }
00054 }