summaryrefslogtreecommitdiff
path: root/lang/java/src/com/sleepycat/db/OperationStatus.java
blob: 35f49da0d7d5930a04c503cfe9dd412c3dc79607 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*-
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 2002, 2015 Oracle and/or its affiliates.  All rights reserved.
 *
 * $Id$
 */

package com.sleepycat.db;

import com.sleepycat.db.internal.DbConstants;
import com.sleepycat.db.internal.DbEnv;

/**
Status values from database operations.
*/
public final class OperationStatus {
    /**
    The operation was successful.
    */
    public static final OperationStatus SUCCESS =
        new OperationStatus("SUCCESS", 0);
    /**
    The operation to insert data was configured to not allow overwrite
    and the key already exists in the database.
    */
    public static final OperationStatus KEYEXIST =
        new OperationStatus("KEYEXIST", DbConstants.DB_KEYEXIST);
    /**
    The cursor operation was unsuccessful because the current record
    was deleted.
    */
    public static final OperationStatus KEYEMPTY =
        new OperationStatus("KEYEMPTY", DbConstants.DB_KEYEMPTY);
    /**
    The requested key/data pair was not found.
    */
    public static final OperationStatus NOTFOUND =
        new OperationStatus("NOTFOUND", DbConstants.DB_NOTFOUND);

    /* package */
    static OperationStatus fromInt(final int errCode) {
        switch(errCode) {
        case 0:
            return SUCCESS;
        case DbConstants.DB_KEYEXIST:
            return KEYEXIST;
        case DbConstants.DB_KEYEMPTY:
            return KEYEMPTY;
        case DbConstants.DB_NOTFOUND:
            return NOTFOUND;
        default:
            throw new IllegalArgumentException(
                "Unknown error code: " + DbEnv.strerror(errCode));
        }
    }

    /* For toString */
    private String statusName;
    private int errCode;

    private OperationStatus(final String statusName, int errCode) {
        this.statusName = statusName;
        this.errCode = errCode;
    }

    /** {@inheritDoc} */
    public String toString() {
        return "OperationStatus." + statusName;
    }
}