📄 datacursor.java
字号:
return cursor.getNext(keyThang, primaryKeyThang, valueThang, lockMode); } } /** * Binding version of Cursor.getNext(), join cursor is allowed. */ OperationStatus getNextNoDup(boolean lockForWrite) throws DatabaseException { LockMode lockMode = getLockMode(lockForWrite); if (joinCursor != null) { return joinCursor.getNext(keyThang, valueThang, lockMode); } else if (view.dupsView) { return cursor.getNext (keyThang, primaryKeyThang, valueThang, lockMode); } else { return cursor.getNextNoDup (keyThang, primaryKeyThang, valueThang, lockMode); } } /** * Binding version of Cursor.getNextDup(), no join cursor allowed. */ OperationStatus getNextDup(boolean lockForWrite) throws DatabaseException { checkNoJoinCursor(); if (view.dupsView) { return null; } else { return cursor.getNextDup (keyThang, primaryKeyThang, valueThang, getLockMode(lockForWrite)); } } /** * Binding version of Cursor.getLast(), no join cursor allowed. */ OperationStatus getLast(boolean lockForWrite) throws DatabaseException { checkNoJoinCursor(); return cursor.getLast(keyThang, primaryKeyThang, valueThang, getLockMode(lockForWrite)); } /** * Binding version of Cursor.getPrev(), no join cursor allowed. */ OperationStatus getPrev(boolean lockForWrite) throws DatabaseException { checkNoJoinCursor(); return cursor.getPrev(keyThang, primaryKeyThang, valueThang, getLockMode(lockForWrite)); } /** * Binding version of Cursor.getPrevNoDup(), no join cursor allowed. */ OperationStatus getPrevNoDup(boolean lockForWrite) throws DatabaseException { checkNoJoinCursor(); LockMode lockMode = getLockMode(lockForWrite); if (view.dupsView) { return null; } else if (view.dupsView) { return cursor.getPrev (keyThang, primaryKeyThang, valueThang, lockMode); } else { return cursor.getPrevNoDup (keyThang, primaryKeyThang, valueThang, lockMode); } } /** * Binding version of Cursor.getPrevDup(), no join cursor allowed. */ OperationStatus getPrevDup(boolean lockForWrite) throws DatabaseException { checkNoJoinCursor(); if (view.dupsView) { return null; } else { return cursor.getPrevDup (keyThang, primaryKeyThang, valueThang, getLockMode(lockForWrite)); } } /** * Binding version of Cursor.getSearchKey(), no join cursor allowed. * Searches by record number in a BTREE-RECNO db with RECNO access. */ OperationStatus getSearchKey(Object key, Object value, boolean lockForWrite) throws DatabaseException { checkNoJoinCursor(); if (view.dupsView) { if (view.useKey(key, value, primaryKeyThang, view.dupsRange)) { KeyRange.copy(view.dupsKey, keyThang); return cursor.getSearchBoth (keyThang, primaryKeyThang, valueThang, getLockMode(lockForWrite)); } } else { if (view.useKey(key, value, keyThang, range)) { return doGetSearchKey(lockForWrite); } } return OperationStatus.NOTFOUND; } /** * Pass-thru version of Cursor.getSearchKey(). * Searches by record number in a BTREE-RECNO db with RECNO access. */ private OperationStatus doGetSearchKey(boolean lockForWrite) throws DatabaseException { LockMode lockMode = getLockMode(lockForWrite); if (view.btreeRecNumAccess) { return cursor.getSearchRecordNumber(keyThang, primaryKeyThang, valueThang, lockMode); } else { return cursor.getSearchKey(keyThang, primaryKeyThang, valueThang, lockMode); } } /** * Binding version of Cursor.getSearchKeyRange(), no join cursor allowed. */ OperationStatus getSearchKeyRange(Object key, Object value, boolean lockForWrite) throws DatabaseException { checkNoJoinCursor(); LockMode lockMode = getLockMode(lockForWrite); if (view.dupsView) { if (view.useKey(key, value, primaryKeyThang, view.dupsRange)) { KeyRange.copy(view.dupsKey, keyThang); return cursor.getSearchBothRange (keyThang, primaryKeyThang, valueThang, lockMode); } } else { if (view.useKey(key, value, keyThang, range)) { return cursor.getSearchKeyRange (keyThang, primaryKeyThang, valueThang, lockMode); } } return OperationStatus.NOTFOUND; } /** * Find the given key and value using getSearchBoth if possible or a * sequential scan otherwise, no join cursor allowed. */ OperationStatus findBoth(Object key, Object value, boolean lockForWrite) throws DatabaseException { checkNoJoinCursor(); LockMode lockMode = getLockMode(lockForWrite); view.useValue(value, valueThang, null); if (view.dupsView) { if (view.useKey(key, value, primaryKeyThang, view.dupsRange)) { KeyRange.copy(view.dupsKey, keyThang); if (otherThang == null) { otherThang = new DatabaseEntry(); } OperationStatus status = cursor.getSearchBoth (keyThang, primaryKeyThang, otherThang, lockMode); if (status == OperationStatus.SUCCESS && KeyRange.equalBytes(otherThang, valueThang)) { return status; } } } else if (view.useKey(key, value, keyThang, range)) { if (view.isSecondary()) { if (otherThang == null) { otherThang = new DatabaseEntry(); } OperationStatus status = cursor.getSearchKey(keyThang, primaryKeyThang, otherThang, lockMode); while (status == OperationStatus.SUCCESS) { if (KeyRange.equalBytes(otherThang, valueThang)) { return status; } status = cursor.getNextDup(keyThang, primaryKeyThang, otherThang, lockMode); } /* if status != SUCCESS set range cursor to invalid? */ } else { return cursor.getSearchBoth(keyThang, null, valueThang, lockMode); } } return OperationStatus.NOTFOUND; } /** * Find the given value using getSearchBoth if possible or a sequential * scan otherwise, no join cursor allowed. */ OperationStatus findValue(Object value, boolean findFirst) throws DatabaseException { checkNoJoinCursor(); if (view.entityBinding != null && !view.isSecondary() && (findFirst || !view.dupsAllowed)) { return findBoth(null, value, false); } else { if (otherThang == null) { otherThang = new DatabaseEntry(); } view.useValue(value, otherThang, null); OperationStatus status = findFirst ? getFirst(false) : getLast(false); while (status == OperationStatus.SUCCESS) { if (KeyRange.equalBytes(valueThang, otherThang)) { break; } status = findFirst ? getNext(false) : getPrev(false); } return status; } } /** * Calls Cursor.count(), no join cursor allowed. */ int count() throws DatabaseException { checkNoJoinCursor(); if (view.dupsView) { return 1; } else { return cursor.count(); } } /** * Binding version of Cursor.putCurrent(). */ OperationStatus putCurrent(Object value) throws DatabaseException { checkWriteAllowed(false); view.useValue(value, valueThang, keyThang); /* * Workaround for a DB core problem: With HASH type a put() with * different data is allowed. */ boolean hashWorkaround = (view.dupsOrdered && !view.ordered); if (hashWorkaround) { if (otherThang == null) { otherThang = new DatabaseEntry(); } cursor.getCurrent(keyThang, primaryKeyThang, otherThang, LockMode.DEFAULT); if (KeyRange.equalBytes(valueThang, otherThang)) { return OperationStatus.SUCCESS; } else { throw new IllegalArgumentException( "Current data differs from put data with sorted duplicates"); } } return cursor.putCurrent(valueThang); } /** * Binding version of Cursor.putAfter(). */ OperationStatus putAfter(Object value) throws DatabaseException { checkWriteAllowed(false); view.useValue(value, valueThang, null); /* why no key check? */ return cursor.putAfter(keyThang, valueThang); } /** * Binding version of Cursor.putBefore(). */ OperationStatus putBefore(Object value) throws DatabaseException { checkWriteAllowed(false); view.useValue(value, valueThang, keyThang); return cursor.putBefore(keyThang, valueThang); } /** * Binding version of Cursor.put(), optionally returning the old value and * optionally using the current key instead of the key parameter. */ OperationStatus put(Object key, Object value, Object[] oldValue, boolean useCurrentKey) throws DatabaseException { initForPut(key, value, oldValue, useCurrentKey); return cursor.put(keyThang, valueThang); } /** * Binding version of Cursor.putNoOverwrite(), optionally using the current * key instead of the key parameter. */ OperationStatus putNoOverwrite(Object key, Object value, boolean useCurrentKey) throws DatabaseException { initForPut(key, value, null, useCurrentKey); return cursor.putNoOverwrite(keyThang, valueThang); } /** * Binding version of Cursor.putNoDupData(), optionally returning the old * value and optionally using the current key instead of the key parameter. */ OperationStatus putNoDupData(Object key, Object value, Object[] oldValue, boolean useCurrentKey) throws DatabaseException { initForPut(key, value, oldValue, useCurrentKey); if (view.dupsOrdered) { return cursor.putNoDupData(keyThang, valueThang); } else { if (view.dupsAllowed) { /* Unordered duplicates. */ OperationStatus status = cursor.getSearchBoth(keyThang, primaryKeyThang, valueThang, getLockMode(false)); if (status == OperationStatus.SUCCESS) { return OperationStatus.KEYEXIST; } else { return cursor.put(keyThang, valueThang); } } else { /* No duplicates. */ return cursor.putNoOverwrite(keyThang, valueThang); } } } /** * Do setup for a put() operation. */ private void initForPut(Object key, Object value, Object[] oldValue, boolean useCurrentKey) throws DatabaseException { checkWriteAllowed(false); if (!useCurrentKey && !view.useKey(key, value, keyThang, range)) { throw new IllegalArgumentException("key out of range"); } if (oldValue != null) { oldValue[0] = null; if (!view.dupsAllowed) { OperationStatus status = doGetSearchKey(true); if (status == OperationStatus.SUCCESS) { oldValue[0] = getCurrentValue(); } } } view.useValue(value, valueThang, keyThang); } /** * Sets the key entry to the begin key of a single key range, so the next * time a putXxx() method is called that key will be used. */ void useRangeKey() { if (!range.isSingleKey()) { throw new IllegalStateException(); } KeyRange.copy(range.getSingleKey(), keyThang); } /** * Perform an arbitrary database 'delete' operation. */ OperationStatus delete() throws DatabaseException { checkWriteAllowed(true); return cursor.delete(); } /** * Returns the lock mode to use for a getXxx() operation. */ LockMode getLockMode(boolean lockForWrite) { /* Read-uncommmitted takes precedence over write-locking. */ if (readUncommitted) { return LockMode.READ_UNCOMMITTED; } else if (lockForWrite) { return view.currentTxn.getWriteLockMode(); } else { return LockMode.DEFAULT; } } /** * Throws an exception if a join cursor is in use. */ private void checkNoJoinCursor() { if (joinCursor != null) { throw new UnsupportedOperationException ("Not allowed with a join cursor"); } } /** * Throws an exception if write is not allowed or if a join cursor is in * use. */ private void checkWriteAllowed(boolean allowSecondary) { checkNoJoinCursor(); if (!writeAllowed || (!allowSecondary && view.isSecondary())) { throw new UnsupportedOperationException ("Writing is not allowed"); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -