Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*-
   * See the file LICENSE for redistribution information.
   *
   * Copyright (c) 2002, 2013 Oracle and/or its affiliates.  All rights reserved.
   *
   */
  
  package com.sleepycat.je.tree.dupConvert;
  
 
An DIN represents an Duplicate Internal Node in the JE tree. Obsolete in log version 8, only used by DupConvert and some log readers.
 
 public final class DIN extends IN {
 
     private static final String BEGIN_TAG = "<din>";
     private static final String END_TAG = "</din>";

    
Full key for this set of duplicates. For example, if the tree contains k1/d1, k1/d2, k1/d3, the dupKey = k1.
 
     private byte[] dupKey;

    
Reference to DupCountLN which stores the count.
 
     private ChildReference dupCountLNRef;

    
Create an empty DIN, with no node ID, to be filled in from the log.
 
     public DIN() {
         super();
 
          = new ChildReference();
         init(null., 0, 0);
     }

    
For Sizeof, set all array fields to null, since they are not part of the fixed overhead.
 
     public DIN(SizeofMarker marker) {
         super(marker);
          = null;
     }
 
     public ChildReference getDupCountLNRef() {
         return ;
     }
 
     public DupCountLN getDupCountLN()
         throws DatabaseException {
 
         return (DupCountLN.fetchTarget(getDatabase(), this);
     }

    

Returns:
true if this node is a duplicate-bearing node type, false if otherwise.
 
     @Override
     public boolean containsDuplicates() {
         return true;
     }

    
Count up the memory usage attributable to this node alone. LNs children are counted by their BIN/DIN parents, but INs are not counted by their parents because they are resident on the IN list.
 
     @Override
     public long computeMemorySize() {
         long size = super.computeMemorySize();
         if ( != null) {
             size += MemoryBudget.byteArraySize(.getKey().length);
             if (.getTarget() != null) {
                 size += .getTarget().
                     getMemorySizeIncludedByParent();
             }
         }
         return size;
     }
 
    /* Utility method used during unit testing. */
    @Override
    protected long printMemorySize() {
        final long inTotal = super.printMemorySize();
        long dupKeySize = 0;
        long dupLNSize = 0;
        if ( != null) {
            dupKeySize = MemoryBudget.
                byteArraySize(.getKey().length);
            if (.getTarget() != null) {
                dupLNSize =
                    .getTarget().getMemorySizeIncludedByParent();
            }
        }
        final long dupTotal = inTotal + dupKeySize + dupLNSize;
        ..format("DIN: %d dkey: %d ln: %d %n",
                          inTotaldupKeySizedupLNSize);
        return dupTotal;
    }
    @Override
    protected long getFixedMemoryOverhead() {
        return .;
    }
    @Override
    protected boolean isEvictionProhibited() {
        return true;
    }
    /*
     * Logging Support
     */

    
    @Override
    public LogEntryType getLogType() {
        return .;
    }

    
    @Override
    public int getLogSize() {
        throw EnvironmentFailureException.unexpectedState();
    }

    
    @Override
    public void writeToLog(ByteBuffer logBuffer) {
        throw EnvironmentFailureException.unexpectedState();
    }

    
    @Override
    public void readFromLog(ByteBuffer itemBufferint entryVersion) {
        boolean unpacked = (entryVersion < 6);
        super.readFromLog(itemBufferentryVersion);
         = LogUtils.readByteArray(itemBufferunpacked);
        /* DupCountLN */
        boolean dupCountLNRefExists = false;
        byte booleans = itemBuffer.get();
        dupCountLNRefExists = (booleans & 1) != 0;
        if (dupCountLNRefExists) {
            .readFromLog(itemBufferentryVersion);
        } else {
             = null;
        }
    }

    
DINS need to dump their dup key
    @Override
    protected void dumpLogAdditional(StringBuilder sb) {
        super.dumpLogAdditional(sb);
        sb.append(Key.dumpString(, 0));
        if ( != null) {
            .dumpLog(sbtrue);
        }
    }
    /*
     * Dumping
     */
    @Override
    public String beginTag() {
        return ;
    }
    @Override
    public String endTag() {
        return ;
    }

    
For unit test support:

Returns:
a string that dumps information about this DIN, without
    @Override
    public String dumpString(int nSpacesboolean dumpTags) {
        StringBuilder sb = new StringBuilder();
        if (dumpTags) {
            sb.append(TreeUtils.indent(nSpaces));
            sb.append(beginTag());
            sb.append('\n');
        }
        sb.append(TreeUtils.indent(nSpaces+2));
        sb.append("<dupkey>");
        sb.append( == null ? "" :
                  Key.dumpString(, 0));
        sb.append("</dupkey>");
        sb.append('\n');
        if ( == null) {
            sb.append(TreeUtils.indent(nSpaces+2));
            sb.append("<dupCountLN/>");
        } else {
            sb.append(.dumpString(nSpaces + 4, true));
        }
        sb.append('\n');
        sb.append(super.dumpString(nSpacesfalse));
        if (dumpTags) {
            sb.append(TreeUtils.indent(nSpaces));
            sb.append(endTag());
        }
        return sb.toString();
    }
    @Override
    public String toString() {
        return dumpString(0, true);
    }
    @Override
    public String shortClassName() {
        return "DIN";
    }
New to GrepCode? Check out our FAQ X