/** * {@inheritDoc} */ @Override protected synchronized KrbIdentity doUpdateIdentity(KrbIdentity identity) throws KrbException { String p = identity.getPrincipalName(); try { if (!database.hasKey(p)) { throw new KrbException("No identity found with the principal " + p); } database.delete(p); return database.insert(p, identity); } catch (Exception e) { throw new KrbException("Failed to update the identity " + p); } }
/** * Fetch the rootPage of a given B-tree for a given revision. * * @param btree The B-tree we are interested in * @param revision The revision we want to get back * @return The rootPage for this B-tree and this revision, if any * @throws KeyNotFoundException If we can't find the rootPage for this revision and this B-tree * @throws IOException If we had an ise while accessing the data on disk */ /* No qualifier */<K, V> Page<K, V> getRootPage( BTree<K, V> btree, long revision ) throws KeyNotFoundException, IOException { if ( btree.getRevision() == revision ) { // We are asking for the current revision return btree.getRootPage(); } // Get the B-tree header offset NameRevision nameRevision = new NameRevision( btree.getName(), revision ); long btreeHeaderOffset = btreeOfBtrees.get( nameRevision ); // get the B-tree rootPage Page<K, V> btreeRoot = readRootPage( btree, btreeHeaderOffset ); return btreeRoot; }
/** * Create an instance */ public ValueBTreeCursor( BTree<V, V> valueBtree ) { this.valueBtree = valueBtree; // Start at -1 to be positioned before the first element try { if ( valueBtree != null ) { cursor = valueBtree.browseKeys(); } } catch ( IOException e ) { // TODO Auto-generated catch block e.printStackTrace(); } catch ( KeyNotFoundException knfe ) { // TODO Auto-generated catch block knfe.printStackTrace(); } }
if ( bt.isAllowDuplicates() ) ValueCursor<V> dupHolder = bt.getValues( key ); int size = dupHolder.size(); dupHolder.close(); if ( bt.hasKey( key ) )
configuration.setName( btree.getName() ); configuration.setPageSize( btree.getPageSize() ); configuration.setKeySerializer( btree.getKeySerializer() ); configuration.setValueSerializer( btree.getValueSerializer() ); configuration.setAllowDuplicates( btree.isAllowDuplicates() ); configuration.setReadTimeOut( btree.getReadTimeOut() ); configuration.setWriteBufferSize( btree.getWriteBufferSize() ); final TupleCursor cursor = btree.browse();
Tuple<V, V> removedTuple = valueBtree.delete( removedValue ); if ( valueBtree.getNbElems() == 1 ) valueArray[0] = valueBtree.browse().next().getKey(); nbArrayElems = 1; valueBtree.close(); valueBtree = null;
if ( valueBtree.getNbElems() - 1 < PersistedBTree.valueThresholdLow ) int nbValues = ( int ) ( valueBtree.getNbElems() - 1 ); TupleCursor<V, V> cursor = valueBtree.browse(); V returnedValue = null; int pos = 0; Tuple<V, V> removedTuple = valueBtree.delete( removedValue );
if ( bt.isAllowDuplicates() ) ValueCursor<V> valueCursor = bt.getValues( key ); int size = valueCursor.size(); valueCursor.close(); org.apache.directory.mavibot.btree.Tuple<K, V> returned = bt.delete( key ); org.apache.directory.mavibot.btree.Tuple<K, V> returned = bt.delete( key );
if ( !bt.hasKey( key ) ) valueCursor = bt.getValues( key ); int equal = bt.getValueSerializer().compare( val, valueCursor.next() );
/** * {@inheritDoc} */ @Override protected synchronized KrbIdentity doAddIdentity(KrbIdentity identity) throws KrbException { String p = identity.getPrincipalName(); try { if (database.hasKey(p)) { throw new KrbException("Identity already exists " + p); } return database.insert(p, identity); } catch (KeyNotFoundException e) { throw new KrbException("No such identity exists " + p); } catch (IOException e) { throw new KrbException("Failed to add the identity " + p); } }
bt.setKeySerializer( keySerializer ); bt.setValueSerializer( valueSerializer ); count = bt.getNbElems();
byte[] btreeNameBytes = Strings.getBytesUtf8( btree.getName() ); byte[] keySerializerBytes = Strings.getBytesUtf8( btree.getKeySerializerFQCN() ); byte[] valueSerializerBytes = Strings.getBytesUtf8( btree.getValueSerializerFQCN() ); position = store( position, btree.getPageSize(), btreeHeaderPageIos ); position = store( position, ( btree.isAllowDuplicates() ? 1 : 0 ), btreeHeaderPageIos ); LOG.debug( "Flushing the newly managed '{}' btree header", btree.getName() ); flushPages( btreeHeaderPageIos );
/** * Add the value in the subBTree */ private void addInBtree( V value ) { try { valueBtree.insert( value, null ); } catch ( IOException e ) { // TODO Auto-generated catch block e.printStackTrace(); } }
valueSerializer = parentBtree.getValueSerializer(); valueBtree.insert( value, value );
position = store( position, btree.getRevision(), pageIos ); position = store( position, btree.getNbElems(), pageIos ); position = store( position, btreeHeaderOffset, pageIos ); LOG.debug( "-----> Flushing the '{}' B-treeHeader", btree.getName() ); LOG.debug( " revision : " + btree.getRevision() + ", NbElems : " + btree.getNbElems() + ", btreeHeader offset : 0x" + Long.toHexString( btreeHeaderOffset ) ); LOG.debug( "Rewriting the B-treeHeader on place for B-tree " + btree.getName() ); flushPages( pageIos ); if ( ( btree.getType() == BTreeTypeEnum.BTREE_OF_BTREES ) || ( btree.getType() == BTreeTypeEnum.COPIED_PAGES_BTREE ) ) position = store( position, btree.getRevision(), newPageIOs ); position = store( position, btree.getNbElems(), newPageIOs ); position = store( position, btreeHeaderOffset, newPageIOs ); LOG.debug( "Rewriting the B-treeHeader on place for B-tree " + btree.getName() ); flushPages( newPageIOs );
rm.copiedPageBtree.delete( key ); lastRemovedRev = rv; TupleCursor<NameRevision, Long> cursor = rm.btreeOfBtrees.browseFrom( nr ); rm.btreeOfBtrees.delete( t.getKey() ); btreeHeaderOffsets.add( t.value );
/** * Check if the subBtree contains a given value */ protected boolean btreeContains( V value ) { try { return valueBtree.hasKey( value ); } catch ( IOException e ) { // TODO Auto-generated catch block e.printStackTrace(); return false; } catch ( KeyNotFoundException knfe ) { knfe.printStackTrace(); return false; } }
byte[] bytesKey = btree.getKeySerializer().serialize( tuple.key ); fos.write( IntSerializer.serialize( bytesKey.length ) ); fos.write( bytesKey ); byte[] bytesValue = btree.getValueSerializer().serialize( value );