Example #1
0
 @Override
 public Cursor find(Session session, SearchRow first, SearchRow last) {
   ValueLong min, max;
   if (first == null) {
     min = MIN;
   } else if (mainIndexColumn < 0) {
     min = ValueLong.get(first.getKey());
   } else {
     ValueLong v = (ValueLong) first.getValue(mainIndexColumn);
     if (v == null) {
       min = ValueLong.get(first.getKey());
     } else {
       min = v;
     }
   }
   if (last == null) {
     max = MAX;
   } else if (mainIndexColumn < 0) {
     max = ValueLong.get(last.getKey());
   } else {
     ValueLong v = (ValueLong) last.getValue(mainIndexColumn);
     if (v == null) {
       max = ValueLong.get(last.getKey());
     } else {
       max = v;
     }
   }
   TransactionMap<Value, Value> map = getMap(session);
   return new MVStoreCursor(session, map.entryIterator(min), max);
 }
Example #2
0
 /**
  * Compare the positions of two rows.
  *
  * @param rowData the first row
  * @param compare the second row
  * @return 0 if both rows are equal, -1 if the first row is smaller, otherwise 1
  */
 int compareKeys(SearchRow rowData, SearchRow compare) {
   long k1 = rowData.getKey();
   long k2 = compare.getKey();
   if (k1 == k2) {
     if (isMultiVersion) {
       int v1 = rowData.getVersion();
       int v2 = compare.getVersion();
       return MathUtils.compareInt(v2, v1);
     }
     return 0;
   }
   return k1 > k2 ? 1 : -1;
 }
 @Override
 public boolean next() {
   synchronized (sync) {
     if (SysProperties.CHECK && end) {
       DbException.throwInternalError();
     }
     while (true) {
       if (needNewDelta) {
         loadNext(false);
         needNewDelta = false;
       }
       if (needNewBase) {
         loadNext(true);
         needNewBase = false;
       }
       if (deltaRow == null) {
         if (baseRow == null) {
           end = true;
           return false;
         }
         onBase = true;
         needNewBase = true;
         return true;
       }
       int sessionId = deltaRow.getSessionId();
       boolean isThisSession = sessionId == session.getId();
       boolean isDeleted = deltaRow.isDeleted();
       if (isThisSession && isDeleted) {
         needNewDelta = true;
         continue;
       }
       if (baseRow == null) {
         if (isDeleted) {
           if (isThisSession) {
             end = true;
             return false;
           }
           // the row was deleted by another session: return it
           onBase = false;
           needNewDelta = true;
           return true;
         }
         DbException.throwInternalError();
       }
       int compare = index.compareRows(deltaRow, baseRow);
       if (compare == 0) {
         // can't use compareKeys because the
         // version would be compared as well
         long k1 = deltaRow.getKey();
         long k2 = baseRow.getKey();
         compare = MathUtils.compareLong(k1, k2);
       }
       if (compare == 0) {
         if (isDeleted) {
           if (isThisSession) {
             DbException.throwInternalError();
           }
           // another session updated the row
         } else {
           if (isThisSession) {
             onBase = false;
             needNewBase = true;
             needNewDelta = true;
             return true;
           }
           // another session inserted the row: ignore
           needNewBase = true;
           needNewDelta = true;
           continue;
         }
       }
       if (compare > 0) {
         onBase = true;
         needNewBase = true;
         return true;
       }
       onBase = false;
       needNewDelta = true;
       return true;
     }
   }
 }