• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-WNDR4500v2-V1.0.0.60_1.0.38/ap/gpl/timemachine/db-4.7.25.NC/java/src/com/sleepycat/db/
1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2002,2008 Oracle.  All rights reserved.
5 *
6 * $Id: OperationStatus.java,v 12.7 2008/01/17 05:04:53 mjc Exp $
7 */
8
9package com.sleepycat.db;
10
11import com.sleepycat.db.internal.DbConstants;
12import com.sleepycat.db.internal.DbEnv;
13
14/**
15Status values from database operations.
16*/
17public final class OperationStatus {
18    /**
19    The operation was successful.
20    */
21    public static final OperationStatus SUCCESS =
22        new OperationStatus("SUCCESS", 0);
23    /**
24    The operation to insert data was configured to not allow overwrite
25    and the key already exists in the database.
26    */
27    public static final OperationStatus KEYEXIST =
28        new OperationStatus("KEYEXIST", DbConstants.DB_KEYEXIST);
29    /**
30    The cursor operation was unsuccessful because the current record
31    was deleted.
32    */
33    public static final OperationStatus KEYEMPTY =
34        new OperationStatus("KEYEMPTY", DbConstants.DB_KEYEMPTY);
35    /**
36    The requested key/data pair was not found.
37    */
38    public static final OperationStatus NOTFOUND =
39        new OperationStatus("NOTFOUND", DbConstants.DB_NOTFOUND);
40
41    /* package */
42    static OperationStatus fromInt(final int errCode) {
43        switch(errCode) {
44        case 0:
45            return SUCCESS;
46        case DbConstants.DB_KEYEXIST:
47            return KEYEXIST;
48        case DbConstants.DB_KEYEMPTY:
49            return KEYEMPTY;
50        case DbConstants.DB_NOTFOUND:
51            return NOTFOUND;
52        default:
53            throw new IllegalArgumentException(
54                "Unknown error code: " + DbEnv.strerror(errCode));
55        }
56    }
57
58    /* For toString */
59    private String statusName;
60    private int errCode;
61
62    private OperationStatus(final String statusName, int errCode) {
63        this.statusName = statusName;
64        this.errCode = errCode;
65    }
66
67    /** {@inheritDoc} */
68    public String toString() {
69        return "OperationStatus." + statusName;
70    }
71}
72