Package org.exist.storage

Examples of org.exist.storage.DBBroker


    @Test
    public void saxEventModificationsAtXConf() throws EXistException {

        BrokerPool db = BrokerPool.getInstance();

        DBBroker broker = null;

        try {
            broker = db.get(db.getSecurityManager().getSystemSubject());

            Collection root = DatabaseManager.getCollection(BASE_URI + testCollection, "admin", "");

            IndexQueryService idxConf = (IndexQueryService) root.getService("IndexQueryService", "1.0");
            idxConf.configureCollection(COLLECTION_CONFIG);

            Resource resource = root.createResource("data.xml", "XMLResource");
            resource.setContent(DOCUMENT2_CONTENT);
            root.storeResource(resource);

            resource = root.createResource("data.xml", "XMLResource");

            assertEquals(DOCUMENT3_CONTENT, resource.getContent().toString());

        } catch (XMLDBException e) {
            e.printStackTrace();
            fail(e.getMessage());
        } finally {
            if (broker != null)
                broker.release();
        }
    }
View Full Code Here


        throw new RemoteException("Invalid collection URI",e);
      }
    }
    public boolean createCollection(java.lang.String sessionId, XmldbURI path) throws java.rmi.RemoteException {
        final Session session = getSession(sessionId);
        DBBroker broker = null;
        final TransactionManager transact = pool.getTransactionManager();
        final Txn txn = transact.beginTransaction();
        try {
            broker = pool.get(session.getUser());
            LOG.debug("creating collection " + path);
            final org.exist.collections.Collection coll =
                    broker.getOrCreateCollection(txn, path);
            if (coll == null) {
                LOG.debug("failed to create collection");
                return false;
            }
            broker.saveCollection(txn, coll);
            transact.commit(txn);
            broker.flush();
            broker.sync(Sync.MINOR_SYNC);
            return true;
        } catch (final Exception e) {
            transact.abort(txn);
            LOG.debug(e.getMessage(), e);
            throw new RemoteException(e.getMessage());
View Full Code Here

        throw new RemoteException("Invalid collection URI",e);
      }
    }
    public boolean removeCollection(java.lang.String sessionId, XmldbURI path) throws java.rmi.RemoteException {
        final Session session = getSession(sessionId);
        DBBroker broker = null;
        final TransactionManager transact = pool.getTransactionManager();
        final Txn txn = transact.beginTransaction();
        try {
            broker = pool.get(session.getUser());
            final Collection collection = broker.getCollection(path);
            if(collection == null) {
                transact.abort(txn);
                return false;
            }
            final boolean removed = broker.removeCollection(txn, collection);
            transact.commit(txn);
            return removed;
        } catch (final Exception e) {
            transact.abort(txn);
            LOG.debug(e.getMessage(), e);
View Full Code Here

        throw new RemoteException("Invalid document URI",e);
      }
    }
    public boolean removeDocument(java.lang.String sessionId, XmldbURI path) throws java.rmi.RemoteException {
        final Session session = getSession(sessionId);
        DBBroker broker = null;
        final TransactionManager transact = pool.getTransactionManager();
        final Txn txn = transact.beginTransaction();
        try {
            broker = pool.get(session.getUser());
            final XmldbURI collectionUri = path.removeLastSegment();
            final XmldbURI docUri = path.lastSegment();
            if (collectionUri==null || docUri==null) {
                transact.abort(txn);
                throw new EXistException("Illegal document path");
            }
            final Collection collection = broker.getCollection(collectionUri);
            if (collection == null) {
                transact.abort(txn);
                throw new EXistException(
                        "Collection " + collectionUri + " not found");
            }
View Full Code Here

        throw new RemoteException("Invalid document URI",e);
      }
    }
    public void store(java.lang.String sessionId, byte[] data, java.lang.String encoding, XmldbURI path, boolean replace) throws java.rmi.RemoteException {
        final Session session = getSession(sessionId);
        DBBroker broker = null;
        final TransactionManager transact = pool.getTransactionManager();
        final Txn txn = transact.beginTransaction();
        try {
            broker = pool.get(session.getUser());
            final XmldbURI collectionUri = path.removeLastSegment();
            final XmldbURI docUri = path.lastSegment();
            if (collectionUri==null || docUri==null) {
                transact.abort(txn);
                throw new EXistException("Illegal document path");
            }
            final Collection collection = broker.getCollection(collectionUri);
            if (collection == null) {
                transact.abort(txn);
                throw new EXistException("Collection " + collectionUri + " not found");
            }
            if(!replace) {
View Full Code Here

      } catch(final URISyntaxException e) {
        throw new RemoteException("Invalid collection URI",e);
      }
    }
    public int xupdate(java.lang.String sessionId, XmldbURI collectionName, java.lang.String xupdate) throws java.rmi.RemoteException {
        DBBroker broker = null;
        final Session session = getSession(sessionId);
        final TransactionManager transact = pool.getTransactionManager();
        final Txn transaction = transact.beginTransaction();
        try {
            broker = pool.get(session.getUser());
            final Collection collection = broker.getCollection(collectionName);
            if (collection == null) {
                transact.abort(transaction);
                throw new RemoteException(
                        "collection " + collectionName + " not found");
            }
            final DocumentSet docs =
                    collection.allDocs(broker, new DefaultDocumentSet(), true);
            final XUpdateProcessor processor =
                    new XUpdateProcessor(broker, docs, AccessContext.SOAP);
            final Modification modifications[] =
                    processor.parse(new InputSource(new StringReader(xupdate)));
            long mods = 0;
            for (int i = 0; i < modifications.length; i++) {
                mods += modifications[i].process(transaction);
                broker.flush();
            }
            transact.commit(transaction);
            return (int) mods;
        } catch (final ParserConfigurationException e) {
            transact.abort(transaction);
View Full Code Here

      } catch(final URISyntaxException e) {
        throw new RemoteException("Invalid document URI",e);
      }
    }
    public int xupdateResource(java.lang.String sessionId, XmldbURI documentName, java.lang.String xupdate) throws java.rmi.RemoteException {
        DBBroker broker = null;
        final Session session = getSession(sessionId);
        final TransactionManager transact = pool.getTransactionManager();
        final Txn transaction = transact.beginTransaction();
        try {
            broker = pool.get(session.getUser());
// TODO check XML/Binary resource
//            DocumentImpl doc = (DocumentImpl)broker.getDocument(documentName);
            final DocumentImpl doc = broker.getXMLResource(documentName, Permission.READ);
            if (doc == null) {
                transact.abort(transaction);
                throw new RemoteException(
                        "document " + documentName + " not found");
            }
            final MutableDocumentSet docs = new DefaultDocumentSet();
            docs.add(doc);
            final XUpdateProcessor processor =
                    new XUpdateProcessor(broker, docs, AccessContext.SOAP);
            final Modification modifications[] =
                    processor.parse(new InputSource(new StringReader(xupdate)));
            long mods = 0;
            for (int i = 0; i < modifications.length; i++) {
                mods += modifications[i].process(transaction);
                broker.flush();
            }
            transact.commit(transaction);
           
            // Release lock, as reported http://markmail.org/message/pau6hoaeybg2bvch
            doc.getUpdateLock().release(Permission.READ);
View Full Code Here

      } catch(final URISyntaxException e) {
        throw new RemoteException("Invalid document URI",e);
      }
    }
    public void storeBinary(java.lang.String sessionId, byte[] data, XmldbURI path, java.lang.String mimeType, boolean replace) throws java.rmi.RemoteException {
        DBBroker broker = null;
        final Session session = getSession(sessionId);
        Collection collection = null;
        final TransactionManager transact = pool.getTransactionManager();
        final Txn txn = transact.beginTransaction();
        try {
            broker = pool.get(session.getUser());
            final XmldbURI collectionUri = path.removeLastSegment();
            final XmldbURI docUri = path.lastSegment();
            if (collectionUri==null || docUri==null) {
                transact.abort(txn);
                throw new EXistException("Illegal document path");
            }
            collection = broker.openCollection(collectionUri, Lock.WRITE_LOCK);
            if (collection == null)
                {throw new EXistException("Collection " + collectionUri
                        + " not found");}
            if (!replace) {
                final DocumentImpl old = collection.getDocument(broker, docUri);
View Full Code Here

      } catch(final URISyntaxException e) {
        throw new RemoteException("Invalid document URI",e);
      }
    }
    public byte[] getBinaryResource(java.lang.String sessionId, XmldbURI name) throws java.rmi.RemoteException {
        DBBroker broker = null;
        final Session session = getSession(sessionId);
        DocumentImpl doc = null;
        try {
            broker = pool.get(session.getUser());
            // TODO check XML/Binary resource
            doc = broker.getXMLResource(name, Lock.READ_LOCK);
            if (doc == null)
                {throw new EXistException("Resource " + name + " not found");}
            if (doc.getResourceType() != DocumentImpl.BINARY_FILE)
                {throw new EXistException("Document " + name
                        + " is not a binary resource");}
            if(!doc.getPermissions().validate(session.getUser(), Permission.READ))
                {throw new PermissionDeniedException("Insufficient privileges to read resource");}
            final InputStream is = broker.getBinaryResource((BinaryDocument) doc);
            final long resourceSize = broker.getBinaryResourceSize((BinaryDocument) doc);
            if(resourceSize > Integer.MAX_VALUE)
                {throw new RemoteException("Resource too big to be read using this port.");}
            final byte [] data = new byte[(int)resourceSize];
            is.read(data);
            is.close();
View Full Code Here

      } catch(final URISyntaxException e) {
        throw new RemoteException("Invalid collection URI",e);
      }
    }
    public org.exist.soap.CollectionDesc getCollectionDesc(java.lang.String sessionId, XmldbURI collectionName) throws java.rmi.RemoteException {
        DBBroker broker = null;
        final Session session = getSession(sessionId);
        Collection collection = null;
        try {
            broker = pool.get(session.getUser());
            if (collectionName == null)
                {collectionName = XmldbURI.ROOT_COLLECTION_URI;}
           
            collection = broker.openCollection(collectionName, Lock.READ_LOCK);
            if (collection == null)
                {throw new EXistException("collection " + collectionName
                        + " not found!");}
            final CollectionDesc desc = new CollectionDesc();
            final List<DocumentDesc> docs = new ArrayList<DocumentDesc>();
View Full Code Here

TOP

Related Classes of org.exist.storage.DBBroker

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.