Package com.sleepycat.bdb

Examples of com.sleepycat.bdb.DataCursor


            extremeKeys[i] = extremeKeyBytes[i];
        }

        // with empty range

        cursor = new DataCursor(view, false);
        expectRange(keyBytes, 0, end);
        cursor.close();

        // begin key only, inclusive

        for (int i = 0; i <= end; i++) {
            cursor = new DataCursor(view, false, keys[i], true, null, false);
            expectRange(keyBytes, i, end);
            cursor.close();
        }

        // begin key only, exclusive

        for (int i = 0; i <= end; i++) {
            cursor = new DataCursor(view, false, keys[i], false, null, false);
            expectRange(keyBytes, i + 1, end);
            cursor.close();
        }

        // end key only, inclusive

        for (int i = 0; i <= end; i++) {
            cursor = new DataCursor(view, false, null, false, keys[i], true);
            expectRange(keyBytes, 0, i);
            cursor.close();
        }

        // end key only, exclusive

        for (int i = 0; i <= end; i++) {
            cursor = new DataCursor(view, false, null, false, keys[i], false);
            expectRange(keyBytes, 0, i - 1);
            cursor.close();
        }

        // begin and end keys, inclusive and exclusive

        for (int i = 0; i <= end; i++) {
            for (int j = i; j <= end; j++) {
                // begin inclusive, end inclusive

                cursor = new DataCursor(view, false, keys[i], true, keys[j],
                                        true);
                expectRange(keyBytes, i, j);
                cursor.close();

                // begin inclusive, end exclusive

                cursor = new DataCursor(view, false, keys[i], true, keys[j],
                                        false);
                expectRange(keyBytes, i, j - 1);
                cursor.close();

                // begin exclusive, end inclusive

                cursor = new DataCursor(view, false, keys[i], false, keys[j],
                                        true);
                expectRange(keyBytes, i + 1, j);
                cursor.close();

                // begin exclusive, end exclusive

                cursor = new DataCursor(view, false, keys[i], false, keys[j],
                                        false);
                expectRange(keyBytes, i + 1, j - 1);
                cursor.close();
            }
        }

        // single key range

        for (int i = 0; i <= end; i++) {
            cursor = new DataCursor(view, false, keys[i]);
            expectRange(keyBytes, i, i);
            cursor.close();
        }

        // start with lower extreme (before any existing key)

        cursor = new DataCursor(view, false, extremeKeys[0], true, null,                                        false);
        expectRange(keyBytes, 0, end);
        cursor.close();

        // start with higher extreme (after any existing key)

        cursor = new DataCursor(view, false, null, false, extremeKeys[1],                                       true);
        expectRange(keyBytes, 0, end);
        cursor.close();
    }
View Full Code Here


        return getFirstOrLastKey(false);
    }

    private Object getFirstOrLastKey(boolean doGetFirst) {

        DataCursor cursor = null;
        try {
            cursor = new DataCursor(view, false);
            int err = cursor.get(null, null,
                                 doGetFirst ? Db.DB_FIRST : Db.DB_LAST,
                                 false);
            return (err == 0) ? cursor.getCurrentKey() : null;
        } catch (Exception e) {
            throw StoredContainer.convertException(e);
        } finally {
            closeCursor(cursor);
        }
View Full Code Here

        if (!(mapEntry instanceof Map.Entry)) {
            return false;
        }
        Map.Entry entry = (Map.Entry) mapEntry;
        DataCursor cursor = null;
        boolean doAutoCommit = beginAutoCommit();
        try {
            cursor = new DataCursor(view, true);
            int err = cursor.get(entry.getKey(), entry.getValue(),
                                 Db.DB_GET_BOTH, true);
            if (err == 0) {
                cursor.delete();
            }
            closeCursor(cursor);
            commitAutoCommit(doAutoCommit);
            return (err == 0);
        } catch (Exception e) {
View Full Code Here

        if (!(mapEntry instanceof Map.Entry)) {
            return false;
        }
        Map.Entry entry = (Map.Entry) mapEntry;
        DataCursor cursor = null;
        try {
            cursor = new DataCursor(view, false);
            int err = cursor.get(entry.getKey(), entry.getValue(),
                                 Db.DB_GET_BOTH, false);
            return (err == 0);
        } catch (Exception e) {
            throw StoredContainer.convertException(e);
        } finally {
View Full Code Here

    // javadoc is inherited
    public int size() {

        if (!isSingleKey) return super.size();
        DataCursor cursor = null;
        try {
            cursor = new DataCursor(view, false);
            int err = cursor.get(null, null, Db.DB_FIRST, false);
            if (err == 0) {
                return cursor.count();
            } else {
                return 0;
            }
        } catch (Exception e) {
            throw StoredContainer.convertException(e);
View Full Code Here

     * @throws RuntimeExceptionWrapper if a {@link DbException} is thrown.
     */
    public void add(int index, Object value) {

        checkIterAddAllowed();
        DataCursor cursor = null;
        boolean doAutoCommit = beginAutoCommit();
        try {
            cursor = new DataCursor(view, true);
            int err = cursor.get(new Long(index), null, Db.DB_SET, false);
            if (err == 0) {
                cursor.put(null, value, Db.DB_BEFORE, null);
                closeCursor(cursor);
            } else {
                closeCursor(cursor);
                cursor = null;
                view.append(value, null, null);
View Full Code Here

     * @throws RuntimeExceptionWrapper if a {@link DbException} is thrown.
     */
    public boolean addAll(int index, Collection coll) {

        checkIterAddAllowed();
        DataCursor cursor = null;
  Iterator i = null;
        boolean doAutoCommit = beginAutoCommit();
        try {
            i = coll.iterator();
            if (!i.hasNext()) {
                return false;
            }
            cursor = new DataCursor(view, true);
            int err = cursor.get(new Long(index), null, Db.DB_SET, false);
            if (err == 0) {
                while (i.hasNext()) {
                    cursor.put(null, i.next(), Db.DB_BEFORE, null);
                }
                closeCursor(cursor);
            } else {
                closeCursor(cursor);
                cursor = null;
View Full Code Here

        return indexOf(value, false);
    }

    private int indexOf(Object value, boolean findFirst) {

        DataCursor cursor = null;
        try {
            cursor = new DataCursor(view, false);
            int err = cursor.find(value, findFirst);
            return (err == 0)
                    ? (cursor.getCurrentRecordNumber() - baseIndex)
                    : (-1);
        } catch (Exception e) {
            throw StoredContainer.convertException(e);
        } finally {
            closeCursor(cursor);
View Full Code Here

        try {
            this.coll = coll;
            this.writeAllowed = writeAllowed;
            if (joinCursor == null)
                this.cursor = new DataCursor(coll.view, writeAllowed);
            else
                this.cursor = joinCursor;
            this.recNumAccess = cursor.hasRecNumAccess();
            if (coll.iterateDuplicates()) {
                this.NEXT_FLAG = Db.DB_NEXT;
View Full Code Here

     */
    protected Object clone() {

        try {
            StoredIterator o = (StoredIterator) super.clone();
            o.cursor = new DataCursor(cursor);
            return o;
        } catch (Exception e) {
            throw StoredContainer.convertException(e);
        }
    }
View Full Code Here

TOP

Related Classes of com.sleepycat.bdb.DataCursor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.