private boolean updateChildren(HierarchicalRecord record, boolean add) {
   boolean result = false;
   if (record == null) return result;
   try {
     childSem.acquire(uniqueId << 4 + getDataType());
     getWriteLockSem().startRead("updateChildren");
     if (add) {
       boolean found = false;
       int i = 0;
       if (childIds != null) {
         while ((i < childIds.length) && !found) {
           if (childIds[i] == record.getUniqueId()) found = true;
           ++i;
         }
       }
       if (!found) {
         int[] newChilds = new int[(childIds != null) ? childIds.length + 1 : 1];
         i = 0;
         if (childIds != null) {
           while (i < childIds.length) {
             newChilds[i] = childIds[i];
             ++i;
           }
         }
         newChilds[i] = record.getUniqueId();
         childIds = newChilds;
         result = true;
       }
     } else {
       // remove
       removeChildId(record.getUniqueId());
       if (record.getDuplicateIds() != null) {
         for (int duplicateId : record.getDuplicateIds()) removeChildId(duplicateId);
       }
     }
   } catch (Exception e) {
     log.error("updateChildren(): error", e);
   } finally {
     getWriteLockSem().endRead();
     childSem.release(uniqueId << 4 + getDataType());
   }
   childRecords = null;
   return result;
 }
 public boolean containsParentDirectly(HierarchicalRecord record) {
   if (parentIds != null) {
     for (int parentId : parentIds) if (parentId == record.getUniqueId()) return true;
   }
   return false;
 }
 private boolean updateParents(HierarchicalRecord record, boolean add) {
   boolean result = false;
   if (record == null) return result;
   try {
     parentSem.acquire(uniqueId << 4 + getDataType());
     getWriteLockSem().startRead("updateParents");
     if (add) {
       boolean found = false;
       int i = 0;
       if (parentIds != null) {
         while ((i < parentIds.length) && !found) {
           if (parentIds[i] == record.getUniqueId()) found = true;
           ++i;
         }
       }
       if (!found) {
         int[] newParents = new int[(parentIds != null) ? parentIds.length + 1 : 1];
         i = 0;
         if (parentIds != null) {
           while (i < parentIds.length) {
             newParents[i] = parentIds[i];
             ++i;
           }
         }
         newParents[i] = record.getUniqueId();
         parentIds = newParents;
         result = true;
       }
     } else {
       // remove
       boolean found = false;
       int removedIndex = 0;
       if (parentIds != null) {
         while ((removedIndex < parentIds.length) && !found) {
           if (parentIds[removedIndex] == record.getUniqueId()) found = true;
           else ++removedIndex;
         }
       }
       if (found) {
         int[] newParents = new int[parentIds.length - 1];
         int i = 0;
         while (i < parentIds.length) {
           if (i < removedIndex) newParents[i] = parentIds[i];
           else if (i > removedIndex) newParents[i - 1] = parentIds[i];
           ++i;
         }
         parentIds = newParents;
         result = true;
       } else {
         if (log.isDebugEnabled()) log.debug("updateParents(): parent not found=" + record);
       }
     }
   } catch (Exception e) {
     log.error("updateParents(): error", e);
   } finally {
     getWriteLockSem().endRead();
     parentSem.release(uniqueId << 4 + getDataType());
   }
   parentRecords = null;
   return result;
 }
 public boolean containsChildDirectly(HierarchicalRecord record) {
   if (childIds != null) {
     for (int childId : childIds) if (childId == record.getUniqueId()) return true;
   }
   return false;
 }