View Javadoc

1   package org.treetank.io;
2   
3   import static com.google.common.base.Objects.toStringHelper;
4   
5   import com.sleepycat.bind.tuple.TupleBinding;
6   import com.sleepycat.bind.tuple.TupleInput;
7   import com.sleepycat.bind.tuple.TupleOutput;
8   
9   /**
10   * Container for Key-Entry in the log determining the level and the the sequence in the level.
11   * Needed for the WriteTrx for getting inserting any modified buckets in the right order since the bucket-key
12   * can not be computed from the datakeys due to the relative position of the datas in the subtree of the
13   * related
14   * RevisionRootBucket.
15   * 
16   * @author Sebastian Graf, University of Konstanz
17   * 
18   */
19  public class LogKey {
20  
21      /** Is this key referencing to the root level or to the data level. */
22      private final boolean mRootLevel;
23  
24      /** Level Key. */
25      private final int mLevel;
26  
27      /** Sequence Key. */
28      private final long mSeq;
29  
30      /**
31       * Constructor.
32       * 
33       * @param pRootLevel
34       * 
35       * 
36       *            is key part of the revision-part or the data-part
37       * @param pLevel
38       *            to be set.
39       * @param pSeq
40       *            to be set.
41       */
42      public LogKey(final boolean pRootLevel, final int pLevel, final long pSeq) {
43          mRootLevel = pRootLevel;
44          mLevel = pLevel;
45          mSeq = pSeq;
46      }
47  
48      /**
49       * 
50       * Getting the level key.
51       * 
52       * @return the mLevel
53       */
54      public int getLevel() {
55          return mLevel;
56      }
57  
58      /**
59       * Getting the seq key.
60       * 
61       * @return the mSeq
62       */
63      public long getSeq() {
64          return mSeq;
65      }
66  
67      /**
68       * Getter for mRootLevel.
69       * 
70       * @return the mRootLevel
71       */
72      public boolean isRootLevel() {
73          return mRootLevel;
74      }
75  
76      /**
77       * {@inheritDoc}
78       */
79      @Override
80      public int hashCode() {
81          final int prime = 31;
82          int result = 1;
83          result = prime * result + (int)(mLevel ^ (mLevel >>> 32));
84          result = prime * result + (mRootLevel ? 1231 : 1237);
85          result = prime * result + (int)(mSeq ^ (mSeq >>> 32));
86          return result;
87      }
88  
89      /**
90       * {@inheritDoc}
91       */
92      @Override
93      public boolean equals(Object obj) {
94          if (this == obj)
95              return true;
96          if (obj == null)
97              return false;
98          if (getClass() != obj.getClass())
99              return false;
100         LogKey other = (LogKey)obj;
101         if (mLevel != other.mLevel)
102             return false;
103         if (mRootLevel != other.mRootLevel)
104             return false;
105         if (mSeq != other.mSeq)
106             return false;
107         return true;
108     }
109 
110     /**
111      * {@inheritDoc}
112      */
113     @Override
114     public String toString() {
115         return toStringHelper(this).add("mRootLevel", mRootLevel).add("mLevel", mLevel).add("mSeq", mSeq)
116             .toString();
117     }
118 
119     /**
120      * Binding for serializing LogKeys in the BDB.
121      * 
122      * @author Sebastian Graf, University of Konstanz
123      * 
124      */
125     static class LogKeyBinding extends TupleBinding<LogKey> {
126 
127         /**
128          * {@inheritDoc}
129          */
130         @Override
131         public LogKey entryToObject(TupleInput arg0) {
132             final LogKey key = new LogKey(arg0.readBoolean(), arg0.readInt(), arg0.readLong());
133             return key;
134         }
135 
136         /**
137          * {@inheritDoc}
138          */
139         @Override
140         public void objectToEntry(LogKey arg0, TupleOutput arg1) {
141             arg1.writeBoolean(arg0.isRootLevel());
142             arg1.writeInt(arg0.getLevel());
143             arg1.writeLong(arg0.getSeq());
144         }
145 
146     }
147 
148 }