if (node != null) { db.setOwnerObject(lockKey); final long addr = db.findValue(lockKey, node); if (addr == BTree.KEY_NOT_FOUND) return null; DOMFile.RecordPos rec = db.findValuePosition(addr); page = rec.page.getPageNum(); p = rec.page; offset = rec.offset - 2; node = null; } else if (-1 < startAddress) { final DOMFile.RecordPos rec = db.findValuePosition(startAddress); page = rec.page.getPageNum(); offset = rec.offset - 2; p = rec.page; startAddress = -1; } else if (page > -1) p = db.getCurrentPage(page); else { lock.release(); return null;
Value nextVal = null; if(gotoNextPosition()) { do { DOMFilePageHeader ph = p.getPageHeader();  if (offset >= ph.getDataLength()) {  final long nextPage = ph.getNextDataPage(); if (nextPage < 0) { LOG.debug("bad link to next " + p.page.getPageInfo()); return null; } page = nextPage; p = db.getCurrentPage(nextPage); offset = 0; } lastOffset = offset;   lastTID = ByteConversion.byteToShort(p.data, offset); offset += 2;  if(ItemId.isLink(lastTID)) {  offset += 8; continue; }  short l = ByteConversion.byteToShort(p.data, offset); offset += 2; if(ItemId.isRelocated(lastTID)) {  offset += 8; } if(l == DOMFile.OVERFLOW) { final long op = ByteConversion.byteToLong(p.data, offset); offset += 8; final byte[] data = db.getOverflowValue(op); nextVal = new Value(data); } else { nextVal = new Value(p.data, offset, l); offset += l; } nextVal.setAddress( StorageAddress.createPointer((int) page, ItemId.getId(lastTID)) ); } while(nextVal == null);
		public Object next() {			Lock lock = db.getLock();			try {				try {					lock.acquire();				} catch (LockException e) {					return null;				}				// position the iterator at the start of the first value				if (node != null) {					db.setOwnerObject(lockKey);					final long addr = db.findValue(lockKey, node);					if (addr == BTree.KEY_NOT_FOUND)						return null;					DOMFile.RecordPos rec = db.findValuePosition(addr);					page = rec.page.getPageNum();					p = rec.page;					offset = rec.offset - 2;					node = null;				} else if (-1 < startAddress) {					final DOMFile.RecordPos rec = db.findValuePosition(startAddress);					page = rec.page.getPageNum();					offset = rec.offset - 2;					p = rec.page;					startAddress = -1;				} else if (page > -1)					p = db.getCurrentPage(page);				else {					lock.release();					return null;				}				final DOMFilePageHeader ph = p.getPageHeader();				// next value larger than length of the current page?				if (offset >= ph.getDataLength()) {					// load next page in chain					final long nextPage = ph.getNextDataPage();					if (nextPage < 0) {						LOG.debug("bad link to next " + p.page.getPageInfo());						lock.release();						return null;					}					page = nextPage;					p = db.getCurrentPage(nextPage);					offset = 0;				}				// extract the value				lastTID = ByteConversion.byteToShort(p.data, offset);				short l = ByteConversion.byteToShort(p.data, offset + 2);				Value nextVal;				if(l == DOMFile.OVERFLOW) {					final long op = ByteConversion.byteToLong(p.data, offset + 4);					final byte[] data = db.getOverflowValue(op);					nextVal = new Value(data);					l = 8;				} else					nextVal = new Value(p.data, offset + 4, l);				nextVal.setAddress(StorageAddress.createPointer((int) page, lastTID));				lastOffset = offset;				offset = offset + 4 + l;				lock.release();				return nextVal;			} catch (BTreeException e) {				LOG.warn(e);			} catch (IOException e) {				LOG.warn(e);			}			lock.release();			return null;		}