Package xbird.storage

Examples of xbird.storage.DbException


        }

        /** find lest-most value which matches to the key */
        private synchronized long findValue(Value value) throws DbException {
            if(value == null) {
                throw new DbException("Can't search on null Value");
            }
            int idx = searchLeftmostKey(keys, value, keys.length);
            switch(ph.getStatus()) {
                case BRANCH:
                    idx = idx < 0 ? -(idx + 1) : idx + 1;
View Full Code Here


    public boolean create(boolean close) throws DbException {
        ensureResourceOpen();
        try {
            _fileHeader.write();
        } catch (IOException e) {
            throw new DbException(e);
        }
        if(close) {
            close();
        } else {
            this._opened = true;
View Full Code Here

        ensureResourceOpen();
        if(exists()) {
            try {
                _fileHeader.read();
            } catch (IOException e) {
                throw new DbException(e);
            }
            this._opened = true;
            return true;
        } else {
            this._opened = false;
View Full Code Here

    protected final RandomAccessFile ensureResourceOpen() throws DbException {
        if(_raf == null) {
            try {
                this._raf = new RandomAccessFile(_file, "rw");
            } catch (FileNotFoundException e) {
                throw new DbException(e);
            }
        }
        if(_fc == null) {
            this._fc = _raf.getChannel();
        }
View Full Code Here

            // close resources
            try {
                _raf.close();
                _fc.close();
            } catch (IOException e) {
                throw new DbException(e);
            }
            reset();
            return true;
        } else {
            return false;
View Full Code Here

        }
    }

    protected final void checkOpened() throws DbException {
        if(!_opened) {
            throw new DbException("Not opened");
        }
    }
View Full Code Here

            if(_fileHeader._fhDirty) {
                _fileHeader.write();
            }
            _fc.force(true);
        } catch (IOException e) {
            throw new DbException(e);
        }
    }
View Full Code Here

                // if still not found we need to create it and add it to the page cache.
                p = new Page(pageNum);
                try {
                    p.read(); // Load the page from disk if necessary
                } catch (IOException e) {
                    throw new DbException(e);
                }
                _pages.put(pageNum, new WeakReference<Page>(p));
            }
        }
        return p;
View Full Code Here

        PageHeader hdr = page.getPageHeader();
        hdr.setRecordLength(value.getLength());
        try {
            page.readData(is);
        } catch (IOException e) {
            throw new DbException(e);
        }

        // Write out the rest of the value onto any needed overflow pages
        Page lastPage = page;
        while(true) {
            final int available;
            try {
                available = is.available();
            } catch (IOException e) {
                throw new DbException(e);
            }
            if(available == 0) {
                break;
            }
            LOG.debug("page overflowed");

            Page lpage = lastPage;
            PageHeader lhdr = hdr;

            // Find an overflow page to use
            long np = lhdr.getNextPage();
            if(np != NO_PAGE) {
                // Use an existing page
                lastPage = getPage(np);
            } else {
                // Create a new overflow page
                lastPage = getFreePage();
                lhdr.setNextPage(lastPage.getPageNum());
            }

            // Mark the page as an overflow page
            hdr = lastPage.getPageHeader();
            hdr.setStatus(OVERFLOW);

            // Write some more of the value to the overflow page
            try {
                lastPage.readData(is);
            } catch (IOException e) {
                throw new DbException(e);
            }
            lpage.write();
        }

        // Cleanup any unused overflow pages. i.e. the value is smaller then the
View Full Code Here

        while(true) {
            // Add the contents of the page onto the stream
            try {
                p.writeData(bos);
            } catch (IOException e) {
                throw new DbException(e);
            }
            // Continue following the list of pages until we get to the end
            PageHeader ph = p.getPageHeader();
            long nextPage = ph.getNextPage();
            if(nextPage == NO_PAGE) {
View Full Code Here

TOP

Related Classes of xbird.storage.DbException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.