public void reindex(DocumentImpl document, StoredNode node) { if (pending.size() == 0) return; final short collectionId = document.getCollection().getId(); final Lock lock = dbValues.getLock(); for (Iterator i = pending.entrySet().iterator(); i.hasNext();) {  Map.Entry entry = (Map.Entry) i.next(); Indexable indexable = (Indexable) entry.getKey();  LongLinkedList storedGIDList = (LongLinkedList) entry.getValue(); Value ref = new Value(indexable.serialize(collectionId, caseSensitive)); try { lock.acquire(Lock.WRITE_LOCK); VariableByteInput is = dbValues.getAsStream(ref); os.clear();  LongLinkedList newGIDList = new LongLinkedList();  if (is != null) { try { while (is.available() > 0) { int storedDocId = is.readInt(); int gidsCount = is.readInt(); if (storedDocId != document.getDocId()) {   os.writeInt(gidsCount); os.writeInt(gidsCount); is.copyTo(os, gidsCount); } else {   long previousGID = 0; for (int j = 0; j < gidsCount; j++) { long delta = is.readLong(); long storedGID = previousGID + delta; if (node == null) { if (document.getTreeLevel(storedGID) < document.getMetadata().reindexRequired()) storedGIDList.add(storedGID); } else { if (!NodeSetHelper.isDescendant(document, node.getGID(), storedGID))  newGIDList.add(storedGID); } previousGID = storedGID; } } } } catch (EOFException e) {  } }     if (storedGIDList.getSize() > 0) { long[] gids = storedGIDList.getData(); int gidsCount = gids.length;  Arrays.sort(gids); os.writeInt(document.getDocId()); os.writeInt(gidsCount); long previousGID = 0; for (int j = 0; j < gidsCount; j++) { long delta = gids[j] - previousGID; os.writeLong(delta); previousGID = gids[j]; } }  if (is == null) {  if (dbValues.put(ref, os.data()) == BFile.UNKNOWN_ADDRESS) { LOG.error("Could not put index data for value '" +  ref + "'"); } } else { long address = ((BFile.PageInputStream) is).getAddress(); if (dbValues.update(address, ref, os.data()) == BFile.UNKNOWN_ADDRESS) { LOG.error("Could not update index data for value '" +  ref + "'"); } }  } catch (LockException e) { LOG.warn("Failed to acquire lock for '" + dbValues.getFile().getName() + "'", e); return; } catch (IOException e) { LOG.error(e.getMessage(), e);  } catch (ReadOnlyException e) { LOG.warn(e.getMessage(), e);  } finally { lock.release(Lock.WRITE_LOCK); } } pending.clear();
public void reindex(DocumentImpl oldDoc, StoredNode node) {
    public void reindex(DocumentImpl document, StoredNode node) {        if (pending.size() == 0)             return;                final short collectionId = document.getCollection().getId();        final Lock lock = dbValues.getLock();                      for (Iterator i = pending.entrySet().iterator(); i.hasNext();) {            //Compute a key for the value            Map.Entry entry = (Map.Entry) i.next();            Indexable indexable = (Indexable) entry.getKey();            //TODO : NativeElementIndex uses ArrayLists -pb            LongLinkedList storedGIDList = (LongLinkedList) entry.getValue();            Value ref = new Value(indexable.serialize(collectionId, caseSensitive));             try {                lock.acquire(Lock.WRITE_LOCK);                VariableByteInput is = dbValues.getAsStream(ref);                os.clear();                //TODO : NativeElementIndex uses ArrayLists -pb                LongLinkedList newGIDList = new LongLinkedList();                //Does the value already has data in the index ?                if (is != null) {                                        try {                        while (is.available() > 0) {                            int storedDocId = is.readInt();                            int gidsCount = is.readInt();                            if (storedDocId != document.getDocId()) {                                // data are related to another document:                                // append them to any existing data                                os.writeInt(gidsCount);                                os.writeInt(gidsCount);                                is.copyTo(os, gidsCount);                            } else {                                // data are related to our document:                                // feed the new list with the GIDs                                                                    long previousGID = 0;                                for (int j = 0; j < gidsCount; j++) {                                    long delta = is.readLong();                                    long storedGID = previousGID + delta;                                        if (node == null) {                                        if (document.getTreeLevel(storedGID) < document.getMetadata().reindexRequired())                                            storedGIDList.add(storedGID);                                    } else {                                         if (!NodeSetHelper.isDescendant(document, node.getGID(), storedGID))                                             //TO UNDERSTAND : what will these GIDs become ? -pb                                             newGIDList.add(storedGID);                                    }                                    previousGID = storedGID;                                }                            }                        }                    } catch (EOFException e) {                        //EOFException expected                    }                }                //TOUNDERSTAND (bis) : don't we lack the 2 following lines like in NativeElementIndex ? -pb                //if (node != null)                 //    storedGIDList.addAll(newGIDList);                // append the data                if (storedGIDList.getSize() > 0) {                                       long[] gids = storedGIDList.getData();                    int gidsCount = gids.length;                    //Don't forget this one                    Arrays.sort(gids);                    os.writeInt(document.getDocId());                    os.writeInt(gidsCount);                    long previousGID = 0;                    for (int j = 0; j < gidsCount; j++) {                        long delta = gids[j] - previousGID;                                                os.writeLong(delta);                        previousGID = gids[j];                    }                }                //Store the data                if (is == null) {                    //TOUNDERSTAND : Should is be null, what will there be in os.data() ? -pb                    if (dbValues.put(ref, os.data()) == BFile.UNKNOWN_ADDRESS) {                        LOG.error("Could not put index data for value '" +  ref + "'");                    }                } else {                    long address = ((BFile.PageInputStream) is).getAddress();                    if (dbValues.update(address, ref, os.data()) == BFile.UNKNOWN_ADDRESS) {                        LOG.error("Could not update index data for value '" +  ref + "'");                    }                }                            } catch (LockException e) {                LOG.warn("Failed to acquire lock for '" + dbValues.getFile().getName() + "'", e);                     return;            } catch (IOException e) {                LOG.error(e.getMessage(), e);                                //TODO : return ?            } catch (ReadOnlyException e) {                LOG.warn(e.getMessage(), e);                  //TODO : return ?            } finally {                lock.release(Lock.WRITE_LOCK);            }        }        pending.clear();    }