Package org.exist.storage.lock

Examples of org.exist.storage.lock.Lock


        return (Occurrences[]) cb.map.values().toArray(result);
    }

    public Occurrences[] scanIndexTerms(DocumentSet docs, NodeSet contextSet,
            QName[] qnames, String start, String end) throws PermissionDeniedException {
        final Lock lock = dbTokens.getLock();
        final IndexScanCallback cb = new IndexScanCallback(docs, contextSet, true);
        for (int q = 0; q < qnames.length; q++) {
            for (final Iterator<Collection> i = docs.getCollectionIterator(); i.hasNext();) {
                final int collectionId = (i.next()).getId();
                final IndexQuery query;
                if (start == null) {
                    final Value startRef = new QNameWordRef(collectionId, qnames[q],
                        broker.getBrokerPool().getSymbols());
                    query = new IndexQuery(IndexQuery.TRUNC_RIGHT, startRef);
                } else if (end == null) {
                    final Value startRef = new QNameWordRef(collectionId, qnames[q],
                        start.toLowerCase(), broker.getBrokerPool().getSymbols());
                    query = new IndexQuery(IndexQuery.TRUNC_RIGHT, startRef);
                } else {
                    final Value startRef = new QNameWordRef(collectionId, qnames[q], start.toLowerCase(),
                        broker.getBrokerPool().getSymbols());
                    final Value endRef = new QNameWordRef(collectionId, qnames[q], end.toLowerCase(),
                        broker.getBrokerPool().getSymbols());
                    query = new IndexQuery(IndexQuery.BW, startRef, endRef);
                }
                try {
                    lock.acquire(Lock.READ_LOCK);
                    dbTokens.query(query, cb);
                } catch (final LockException e) {
                    LOG.warn("Failed to acquire lock for '" + dbTokens.getFile().getName() + "'", e);
                    //TODO : throw exception ? -pb
                } catch (final IOException e) {
                    LOG.error(e.getMessage(), e);
                    //TODO : throw exception ? -pb
                } catch (final BTreeException e) {
                    LOG.error(e.getMessage(), e);
                    //TODO : throw exception ? -pb
                } catch (final TerminatedException e) {
                    LOG.warn(e.getMessage(), e);
                    //TODO : throw exception ? -pb
                } finally {
                    lock.release(Lock.READ_LOCK);
                }
            }
        }
        final Occurrences[] result = new Occurrences[cb.map.size()];
        return (Occurrences[]) cb.map.values().toArray(result);
View Full Code Here


     * @throws EXistException
     * @throws LockException
     */
    public void remove(String name) throws EXistException, LockException {
        short id = getId(name);
        final Lock lock = index.btree.getLock();
        try {
            lock.acquire(Lock.READ_LOCK);
            byte[] fromKey = computeKey(id);
            byte[] toKey = computeKey((short) (id + 1));
            final IndexQuery query = new IndexQuery(IndexQuery.RANGE, new Value(fromKey), new Value(toKey));
            index.btree.remove(query, null);

            removeId(name);
        } catch (BTreeException e) {
            throw new EXistException("Exception caught while deleting sort index: " + e.getMessage(), e);
        } catch (IOException e) {
            throw new EXistException("Exception caught while deleting sort index: " + e.getMessage(), e);
        } catch (TerminatedException e) {
            throw new EXistException("Exception caught while deleting sort index: " + e.getMessage(), e);
        } finally {
            lock.release(Lock.READ_LOCK);
        }
    }
View Full Code Here

        short id = getId(name);
        remove(doc, id);
    }

    private void remove(DocumentImpl doc, short id) throws LockException, EXistException {
        final Lock lock = index.btree.getLock();
        try {
            lock.acquire(Lock.READ_LOCK);
            byte[] fromKey = computeKey(id, doc.getDocId());
            byte[] toKey = computeKey(id, doc.getDocId() + 1);
            final IndexQuery query = new IndexQuery(IndexQuery.RANGE, new Value(fromKey), new Value(toKey));
            index.btree.remove(query, null);
        } catch (BTreeException e) {
            throw new EXistException("Exception caught while deleting sort index: " + e.getMessage(), e);
        } catch (IOException e) {
            throw new EXistException("Exception caught while deleting sort index: " + e.getMessage(), e);
        } catch (TerminatedException e) {
            throw new EXistException("Exception caught while deleting sort index: " + e.getMessage(), e);
        } finally {
            lock.release(Lock.READ_LOCK);
        }
    }
View Full Code Here

        if (index.btree == null)
            return;
        byte[] fromKey = new byte[] { 1 };
        byte[] endKey = new byte[] { 2 };

        final Lock lock = index.btree.getLock();
        try {
            lock.acquire(Lock.READ_LOCK);
            IndexQuery query = new IndexQuery(IndexQuery.RANGE, new Value(fromKey), new Value(endKey));
            FindIdCallback callback = new FindIdCallback(true);
            index.btree.query(query, callback);

            for (long id : callback.allIds) {
                remove(doc, (short) id);
            }

        } catch (BTreeException e) {
            SortIndex.LOG.debug("Exception caught while reading sort index: " + e.getMessage(), e);
        } catch (IOException e) {
            SortIndex.LOG.debug("Exception caught while reading sort index: " + e.getMessage(), e);
        } catch (TerminatedException e) {
            SortIndex.LOG.debug("Exception caught while reading sort index: " + e.getMessage(), e);
        } catch (LockException e) {
            SortIndex.LOG.debug("Exception caught while reading sort index: " + e.getMessage(), e);
        } catch (EXistException e) {
            SortIndex.LOG.debug("Exception caught while reading sort index: " + e.getMessage(), e);
        } finally {
            lock.release(Lock.READ_LOCK);
        }
    }
View Full Code Here

        short id = getId(name);
        if (id < 0) {
            byte[] fromKey = { 1 };
            byte[] endKey = { 2 };
            IndexQuery query = new IndexQuery(IndexQuery.RANGE, new Value(fromKey), new Value(endKey));
            final Lock lock = index.btree.getLock();
            try {
                lock.acquire(Lock.READ_LOCK);
                FindIdCallback callback = new FindIdCallback(false);
                index.btree.query(query, callback);
                id = (short)(callback.max + 1);
                registerId(id, name);
            } catch (IOException e) {
                throw new EXistException("Exception caught while reading sort index: " + e.getMessage(), e);
            } catch (BTreeException e) {
                throw new EXistException("Exception caught while reading sort index: " + e.getMessage(), e);
            } catch (TerminatedException e) {
                throw new EXistException("Exception caught while reading sort index: " + e.getMessage(), e);
            } finally {
                lock.release(Lock.READ_LOCK);
            }
        }
        return id;
    }
View Full Code Here

    private void registerId(short id, String name) throws EXistException {
        byte[] key = new byte[1 + UTF8.encoded(name)];
        key[0] = 1;
        UTF8.encode(name, key, 1);
        final Lock lock = index.btree.getLock();
        try {
            lock.acquire(Lock.READ_LOCK);
            index.btree.addValue(new Value(key), id);
        } catch (LockException e) {
            throw new EXistException("Exception caught while reading sort index: " + e.getMessage(), e);
        } catch (BTreeException e) {
            throw new EXistException("Exception caught while reading sort index: " + e.getMessage(), e);
        } catch (IOException e) {
            throw new EXistException("Exception caught while reading sort index: " + e.getMessage(), e);
        } finally {
            lock.release(Lock.READ_LOCK);
        }
    }
View Full Code Here

    private void removeId(String name) throws EXistException {
        byte[] key = new byte[1 + UTF8.encoded(name)];
        key[0] = 1;
        UTF8.encode(name, key, 1);
        final Lock lock = index.btree.getLock();
        try {
            lock.acquire(Lock.READ_LOCK);
            index.btree.removeValue(new Value(key));
        } catch (LockException e) {
            throw new EXistException("Exception caught while reading sort index: " + e.getMessage(), e);
        } catch (BTreeException e) {
            throw new EXistException("Exception caught while reading sort index: " + e.getMessage(), e);
        } catch (IOException e) {
            throw new EXistException("Exception caught while reading sort index: " + e.getMessage(), e);
        } finally {
            lock.release(Lock.READ_LOCK);
        }
    }
View Full Code Here

    private short getId(String name) throws EXistException, LockException {
        byte[] key = new byte[1 + UTF8.encoded(name)];
        key[0] = 1;
        UTF8.encode(name, key, 1);
        final Lock lock = index.btree.getLock();
        try {
            lock.acquire(Lock.READ_LOCK);
            return (short) index.btree.findValue(new Value(key));
        } catch (BTreeException e) {
            throw new EXistException("Exception caught while reading sort index: " + e.getMessage(), e);
        } catch (IOException e) {
            throw new EXistException("Exception caught while reading sort index: " + e.getMessage(), e);
        } finally {
            lock.release(Lock.READ_LOCK);
        }
    }
View Full Code Here

    @Override
    public void sync() throws DBException {
        if (btree == null)
            return;
        final Lock lock = btree.getLock();
        try {
            lock.acquire(Lock.WRITE_LOCK);
            btree.flush();
        } catch (LockException e) {
            LOG.warn("Failed to acquire lock for '" + btree.getFile().getName() + "'", e);
            //TODO : throw an exception ? -pb
        } catch (DBException e) {
            LOG.error(e.getMessage(), e);
            //TODO : throw an exception ? -pb
        } finally {
            lock.release(Lock.WRITE_LOCK);
        }
    }
View Full Code Here

     * @throws LockException
     */
    public void createIndex(String name, List<SortItem> items) throws EXistException, LockException {
        // get an id for the new index
        short id = getOrRegisterId(name);
        final Lock lock = index.btree.getLock();
        try {
            lock.acquire(Lock.WRITE_LOCK);
            long idx = 0;
            for (SortItem item : items) {
                byte[] key = computeKey(id, item.getNode());
                index.btree.addValue(new Value(key), idx++);
            }
        } catch (LockException e) {
            throw new EXistException("Exception caught while creating sort index: " + e.getMessage(), e);
        } catch (BTreeException e) {
            throw new EXistException("Exception caught while creating sort index: " + e.getMessage(), e);
        } catch (IOException e) {
            throw new EXistException("Exception caught while creating sort index: " + e.getMessage(), e);
        } finally {
            lock.release(Lock.WRITE_LOCK);
        }
    }
View Full Code Here

TOP

Related Classes of org.exist.storage.lock.Lock

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.