From: Wolfgang M. M. <wol...@us...> - 2004-05-03 13:09:26
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/storage/store In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19067/src/org/exist/storage/store Modified Files: BFile.java DOMFile.java ItemId.java StorageAddress.java Log Message: Implemented lazy evaluation for XQuery enclosed expressions. Index: DOMFile.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/storage/store/DOMFile.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** DOMFile.java 27 Apr 2004 15:46:57 -0000 1.23 --- DOMFile.java 3 May 2004 13:08:45 -0000 1.24 *************** *** 683,707 **** /** - * Retrieve a range of nodes, starting at first and including last. - * - * @param first - * the first node to retrieve - * @param last - * the last node to retrieve - * @return list of nodes - * @exception IOException - * Description of the Exception - * @exception BTreeException - * Description of the Exception - */ - public ArrayList findRange(Value first, Value last) throws IOException, - BTreeException { - final IndexQuery query = new IndexQuery(IndexQuery.BW, first, last); - final RangeCallback cb = new RangeCallback(); - query(query, cb); - return cb.getValues(); - } - - /** * Find a node by searching for a known ancestor in the index. If an * ancestor is found, it is traversed to locate the specified descendant --- 683,686 ---- *************** *** 1091,1095 **** dataCache.remove(page); DOMFilePageHeader ph = page.getPageHeader(); - LOG.debug("---------------------------\nFreeing page: " + page.getPageNum()); if (ph.getNextDataPage() > -1) { DOMPage next = getCurrentPage(ph.getNextDataPage()); --- 1070,1073 ---- *************** *** 1117,1120 **** --- 1095,1112 ---- } + public void removeAll(long p) { + long pnum = StorageAddress.pageFromPointer(p); + while(-1 < pnum) { + DOMPage page = getCurrentPage(pnum); + pnum = page.getPageHeader().getNextDataPage(); + dataCache.remove(page); + try { + unlinkPages(page.page); + } catch (IOException e) { + LOG.warn("Error while removing page: " + e.getMessage(), e); + } + } + } + /** * Set the last page in the sequence to which nodes are currently appended. *************** *** 1140,1153 **** /** - * Set the file location for this DOMFile. - * - * @param location - * The new location value - */ - public void setLocation(String location) { - setFile(new File(location + ".dbx")); - } - - /** * The current object owning this file. * --- 1132,1135 ---- *************** *** 1329,1395 **** } ! /** ! * Find a record within the page or the pages linked to it. ! * ! * @param p ! * @return ! */ ! protected RecordPos findRecord(long p, boolean skipLinks) { ! long pageNr = StorageAddress.pageFromPointer(p); ! short targetId = StorageAddress.tidFromPointer(p); ! DOMPage page; ! int pos; ! short currentId, vlen; ! int dlen; ! outerLoop: ! while (pageNr > -1) { ! page = getCurrentPage(pageNr); ! dataCache.add(page); ! dlen = page.getPageHeader().getDataLength(); ! for (pos = 0; pos < dlen;) { ! currentId = ByteConversion.byteToShort(page.data, pos); ! if (ItemId.isLink(currentId)) { ! if (ItemId.getId(currentId) == targetId) { ! if(!skipLinks) ! return new RecordPos(pos + 2, page, currentId); ! long forwardLink = ByteConversion.byteToLong(page.data, ! pos + 2); ! // load the link page ! pageNr = StorageAddress.pageFromPointer(forwardLink); ! targetId = StorageAddress.tidFromPointer(forwardLink); ! // LOG.debug("following link. page = " ! // + pageNr ! // + "; tid=" ! // + targetId); ! continue outerLoop; ! } else { ! pos += 10; } - } else if (ItemId.getId(currentId) == targetId) - return new RecordPos(pos + 2, page, currentId); - else { - vlen = ByteConversion.byteToShort(page.data, pos + 2); - if (ItemId.isRelocated(currentId)) { - pos += vlen == OVERFLOW ? 20 : vlen + 12; - } else - pos += vlen == OVERFLOW ? 12 : vlen + 4; } } ! pageNr = page.getPageHeader().getNextDataPage(); ! if (pageNr == page.getPageNum()) { ! LOG.debug("illegal link to next page"); ! return null; ! } ! // LOG.debug( ! // owner.toString() ! // + ": tid " ! // + targetId ! // + " not found on " ! // + page.page.getPageInfo() ! // + ". Loading " ! // + pageNr); } - return null; - } private final class DOMFileHeader extends BTreeFileHeader { --- 1311,1377 ---- } ! /** ! * Find a record within the page or the pages linked to it. ! * ! * @param p ! * @return ! */ ! protected RecordPos findRecord(long p, boolean skipLinks) { ! long pageNr = StorageAddress.pageFromPointer(p); ! short targetId = StorageAddress.tidFromPointer(p); ! DOMPage page; ! int pos; ! short currentId, vlen; ! int dlen; ! outerLoop: ! while (pageNr > -1) { ! page = getCurrentPage(pageNr); ! dataCache.add(page); ! dlen = page.getPageHeader().getDataLength(); ! for (pos = 0; pos < dlen;) { ! currentId = ByteConversion.byteToShort(page.data, pos); ! if (ItemId.isLink(currentId)) { ! if (ItemId.getId(currentId) == targetId) { ! if(!skipLinks) ! return new RecordPos(pos + 2, page, currentId); ! long forwardLink = ByteConversion.byteToLong(page.data, ! pos + 2); ! // load the link page ! pageNr = StorageAddress.pageFromPointer(forwardLink); ! targetId = StorageAddress.tidFromPointer(forwardLink); ! // LOG.debug("following link. page = " ! // + pageNr ! // + "; tid=" ! // + targetId); ! continue outerLoop; ! } else { ! pos += 10; ! } ! } else if (ItemId.getId(currentId) == targetId) ! return new RecordPos(pos + 2, page, currentId); ! else { ! vlen = ByteConversion.byteToShort(page.data, pos + 2); ! if (ItemId.isRelocated(currentId)) { ! pos += vlen == OVERFLOW ? 20 : vlen + 12; ! } else ! pos += vlen == OVERFLOW ? 12 : vlen + 4; } } + pageNr = page.getPageHeader().getNextDataPage(); + if (pageNr == page.getPageNum()) { + LOG.debug("illegal link to next page"); + return null; + } + // LOG.debug( + // owner.toString() + // + ": tid " + // + targetId + // + " not found on " + // + page.page.getPageInfo() + // + ". Loading " + // + pageNr); } ! return null; } private final class DOMFileHeader extends BTreeFileHeader { Index: StorageAddress.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/storage/store/StorageAddress.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** StorageAddress.java 14 Apr 2004 12:17:22 -0000 1.3 --- StorageAddress.java 3 May 2004 13:08:45 -0000 1.4 *************** *** 4,9 **** import java.io.IOException; ! import org.exist.util.VariableByteInputStream; ! import org.exist.util.VariableByteOutputStream; /** --- 4,9 ---- import java.io.IOException; ! import org.exist.storage.io.VariableByteInput; ! import org.exist.storage.io.VariableByteOutputStream; /** *************** *** 62,67 **** } ! public final static long read(VariableByteInputStream is) throws IOException, EOFException { ! return createPointer(is.readInt(), is.readShort(), is.readShort()); } --- 62,67 ---- } ! public final static long read(VariableByteInput is) throws IOException, EOFException { ! return createPointer(is.readInt(), is.readShort(), is.readShort()); } Index: BFile.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/storage/store/BFile.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** BFile.java 27 Apr 2004 15:46:57 -0000 1.19 --- BFile.java 3 May 2004 13:08:45 -0000 1.20 *************** *** 1,31 **** /* ! * eXist Open Source Native XML Database ! * Copyright (C) 2001-03 Wolfgang M. Meier ! * wol...@ex... ! * http://exist.sourceforge.net ! * ! * This program is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public License ! * as published by the Free Software Foundation; either version 2 ! * of the License, or (at your option) any later version. [...3532 lines suppressed...] ! public String getPageInfo() { ! return page.getPageInfo(); ! } ! ! public long getPageNum() { ! return page.getPageNum(); ! } ! ! public void setData(byte[] buf) { ! data = buf; ! } ! ! public void write() throws IOException { ! //LOG.debug(getFile().getName() + " writing page " + getPageNum()); ! writeValue(page, new Value(data)); ! setDirty(false); ! } ! } ! } \ No newline at end of file Index: ItemId.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/storage/store/ItemId.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ItemId.java 14 Apr 2004 12:17:22 -0000 1.1 --- ItemId.java 3 May 2004 13:08:45 -0000 1.2 *************** *** 29,32 **** --- 29,33 ---- public static final short LINK_MASK = (short) 0x4000; public static final short ID_MASK = (short) 0x3FFF; + public static final short LINK_OR_RELOCATED_MASK = (short) 0xC000; public final static short getId(short id) { *************** *** 39,43 **** public final static boolean isLink(short id) { ! return (id & LINK_MASK) != 0; } --- 40,44 ---- public final static boolean isLink(short id) { ! return (id & LINK_MASK) == LINK_MASK; } *************** *** 47,51 **** public final static boolean isRelocated(short id) { ! return (id & RELOCATED_MASK) != 0; } } \ No newline at end of file --- 48,60 ---- public final static boolean isRelocated(short id) { ! return (id & RELOCATED_MASK) == RELOCATED_MASK; } + + public final static boolean isLinkOrRelocated(short id) { + return (id & LINK_OR_RELOCATED_MASK) != 0; + } + + public final static boolean isOrdinaryRecord(short id) { + return (id & LINK_OR_RELOCATED_MASK) == 0; + } } \ No newline at end of file |