@Override public boolean available() { return tuple.getKey() != null; }
public Object next() { if ( ! success ) { throw new NoSuchElementException(); } Object next = jdbmTuple.getKey(); try { prefetch(); } catch ( IOException e ) { throw new NoSuchElementException( "Failure on btree: " + e.getMessage() ); } return next; }
/** * {@inheritDoc} */ public E get() throws CursorException { checkNotClosed(); if ( valueAvailable ) { return ( E ) tuple.getKey(); } throw new InvalidCursorPositionException(); }
/** * Dumps the tree past the key to debug. */ public void dump(Object key) throws IOException { TupleBrowser browser = tree.browse(key); Tuple t = new Tuple(); log.debug("contents: " + key); while (browser.getNext(t)) { log.debug(t.getKey() + "\t" + t.getValue()); } log.debug(""); }
/** * {@inheritDoc} */ @Override @SuppressWarnings("unchecked") public boolean hasGreaterOrEqual( PartitionTxn transaction, K key ) throws LdapException { try { // See if we can find the border between keys greater than and less // than in the set of keys. This will be the spot we search from. jdbm.helper.Tuple tuple = bt.findGreaterOrEqual( key ); // Test for equality first since it satisfies both greater/less than if ( null != tuple && keyComparator.compare( ( K ) tuple.getKey(), key ) == 0 ) { return true; } // Greater searches are easy and quick thanks to findGreaterOrEqual // A null return above means there were no equal or greater keys return ( null != tuple ); } catch ( IOException ioe ) { throw new LdapOtherException( ioe.getMessage() ); } }
public Object next() throws NamingException { if ( ! success ) { throw new NoSuchElementException(); } Object next = jdbmTuple.getKey(); try { prefetch(); } catch ( IOException e ) { LdapNamingException lne = new LdapNamingException( "Failure on btree: " + e.getMessage(), ResultCodeEnum.OTHER ); lne.setRootCause( e ); throw lne; } return next; }
continue; Fqn fqn = (Fqn) t.getKey(); if (!fqn.isChildOrEquals(name))
public K firstKey() { if(size() == 0) throw new NoSuchElementException(); try{ TupleBrowser<K,V> b = fromKey==null?tree.browse():tree.browse(fromKey); Tuple<K,V> t = new Tuple<K,V>(); b.getNext(t); return t.getKey(); }catch(IOException e){ throw new IOError(e); } }
public K lastKey() { if(size() == 0) throw new NoSuchElementException(); try{ TupleBrowser<K,V> b = toKey==null?tree.browse(null):tree.browse(toKey); Tuple<K,V> t = new Tuple<K,V>(); b.getPrevious(t); return t.getKey(); }catch(IOException e){ throw new IOError(e); } }
public Object next() throws NamingException { if ( ! success ) { throw new NoSuchElementException(); } tuple.setKey( key ); tuple.setValue( jdbmTuple.getKey() ); try { prefetch(); } catch ( IOException e ) { LdapNamingException lne = new LdapNamingException( "Failure on btree: " + e.getMessage(), ResultCodeEnum.OTHER ); lne.setRootCause( e ); throw lne; } return tuple; }
@Override Set<Object> getChildrenNames0(Fqn name) throws IOException { Fqn name2 = withDepth(name, name.size() + 1); TupleBrowser browser = tree.browse(name2); Tuple t = new Tuple(); Set<Object> set = new HashSet<Object>(); while (browser.getNext(t)) { Fqn fqn = (Fqn) t.getKey(); if (!fqn.isChildOf(name2)) { break; } set.add(fqn.getLastElement()); } if (set.isEmpty()) { return null; } return Collections.unmodifiableSet(set); }
private Object removeAll( BTree tree ) throws NamingException { Object first = null; jdbm.helper.Tuple jdbmTuple = new jdbm.helper.Tuple(); TupleBrowser browser; try { browser = tree.browse(); while( browser.getNext( jdbmTuple ) ) { tree.remove( jdbmTuple.getKey() ); if ( first == null ) { first = jdbmTuple.getKey(); } } } catch ( IOException e ) { LdapNamingException lne = new LdapNamingException( "Failed to remove all keys in BTree", ResultCodeEnum.OTHER ); lne.setRootCause( e ); throw lne; } return first; } }
@SuppressWarnings("unchecked") private ArrayTree<V> convertToArrayTree( BTree bTree ) throws IOException { ArrayTree<V> avlTree = new ArrayTree<V>( valueComparator ); TupleBrowser browser = bTree.browse(); jdbm.helper.Tuple tuple = new jdbm.helper.Tuple(); while ( browser.getNext( tuple ) ) { avlTree.insert( ( V ) tuple.getKey() ); } return avlTree; }
/** * @see TupleBrowser#getPrevious(Tuple) */ public boolean getPrevious( Tuple tuple ) throws NamingException { boolean isSuccess = false; synchronized ( jdbmTuple ) { try { isSuccess = jdbmBrowser.getPrevious( jdbmTuple ); } catch ( IOException ioe ) { NamingException ne = new NamingException( "Failed on call to jdbm TupleBrowser.getPrevious()" ); ne.setRootCause( ioe ); throw ne; } if ( isSuccess ) { tuple.setKey( jdbmTuple.getKey() ); tuple.setValue( jdbmTuple.getValue() ); } } return isSuccess; } }
if ( gotNextOk ) Object nextVal = jdbmTuple.getKey(); int compared = comparator.compare( val, nextVal ); if ( compared != 0 )
private Object firstKey ( BTree tree ) throws NamingException { jdbm.helper.Tuple tuple = new jdbm.helper.Tuple(); boolean success = false; try { success = tree.browse().getNext( tuple ); if ( success ) { return tuple.getKey(); } else { return null; } } catch ( IOException e ) { LdapNamingException lne = new LdapNamingException( "IO failure while acessing btree: " + e.getMessage(), ResultCodeEnum.OTHER ); lne.setRootCause( e ); throw lne; } }
/** * @see TupleBrowser#getNext(org.apache.directory.server.core.partition.impl.btree.Tuple) */ public boolean getNext( Tuple tuple ) throws NamingException { boolean isSuccess = false; synchronized ( jdbmTuple ) { try { isSuccess = jdbmBrowser.getNext( jdbmTuple ); } catch ( IOException ioe ) { NamingException ne = new NamingException( "Failed on call to jdbm TupleBrowser.getNext()" ); ne.setRootCause( ioe ); throw ne; } if ( isSuccess ) { tuple.setKey( jdbmTuple.getKey() ); tuple.setValue( jdbmTuple.getValue() ); } } return isSuccess; }
private boolean btreeHas( BTree tree, Object key ) throws NamingException { jdbm.helper.Tuple tuple = new jdbm.helper.Tuple(); try { TupleBrowser browser = tree.browse( key ); boolean success = browser.getNext( tuple ); if ( success ) { if ( comparator.compareValue( key, tuple.getKey() ) == 0 ) { return true; } } return false; } catch ( IOException e ) { LdapNamingException lne = new LdapNamingException( "IO failure while acessing btree: " + e.getMessage(), ResultCodeEnum.OTHER ); lne.setRootCause( e ); throw lne; } }