Package org.exist.dom

Examples of org.exist.dom.DocumentImpl


        //TODO : generate it in AbstractGMLJDBCIndexWorker
        String docConstraint = "";
        boolean refine_query_on_doc = false;
        if (contextSet != null) {
            if(contextSet.getDocumentSet().getDocumentCount() <= index.getMaxDocsInContextToRefineQuery()) {
                DocumentImpl doc;
                Iterator<DocumentImpl> it = contextSet.getDocumentSet().getDocumentIterator();
                doc  = it.next();
                docConstraint = "(DOCUMENT_URI = '" + doc.getURI().toString() + "')";
                while(it.hasNext()) {
                    doc  = it.next();
                    docConstraint = docConstraint + " OR (DOCUMENT_URI = '" + doc.getURI().toString() + "')";
                }
            }
        }

        if (LOG.isDebugEnabled()) {
            LOG.debug("Refine query on documents is " + (refine_query_on_doc ? "enabled." : "disabled."));
        }

        PreparedStatement ps = conn.prepareStatement(
            "SELECT " + (getEPSG4326 ? "EPSG4326_WKB" : "WKB") + ", DOCUMENT_URI, NODE_ID_UNITS, NODE_ID" +
            " FROM " + GMLHSQLIndex.TABLE_NAME + (refine_query_on_doc ? " WHERE " + docConstraint : "")
        );
        ResultSet rs = null;
        try {
            rs = ps.executeQuery();
            Geometry[] result = new Geometry[contextSet.getLength()];
            int index= 0;
            while (rs.next()) {
                DocumentImpl doc = null;
                try {
                    doc = (DocumentImpl)broker.getXMLResource(XmldbURI.create(rs.getString("DOCUMENT_URI")));             
                } catch (PermissionDeniedException e) {
                    LOG.debug(e);
                    result[index++] = null;
                    //Ignore since the broker has no right on the document
                    continue;
                }
                if (contextSet == null || refine_query_on_doc || contextSet.getDocumentSet().contains(doc.getDocId())) {
                    NodeId nodeId = new DLN(rs.getInt("NODE_ID_UNITS"), rs.getBytes("NODE_ID"), 0);
                    NodeProxy p = new NodeProxy(doc, nodeId);
                    //Node is in the context : check if it is accurate
                    //contextSet.contains(p) would have made more sense but there is a problem with
                    //VirtualNodeSet when on the DESCENDANT_OR_SELF axis
View Full Code Here


        //TODO : generate it in AbstractGMLJDBCIndexWorker
        String docConstraint = "";
        boolean refine_query_on_doc = false;
        if (contextSet != null) {
            if(contextSet.getDocumentSet().getDocumentCount() <= index.getMaxDocsInContextToRefineQuery()) {
                DocumentImpl doc;
                Iterator<DocumentImpl> it = contextSet.getDocumentSet().getDocumentIterator();
                doc  = it.next();
                docConstraint = "(DOCUMENT_URI = '" + doc.getURI().toString() + "')";
                while(it.hasNext()) {
                    doc = it.next();
                    docConstraint = docConstraint + " OR (DOCUMENT_URI = '" + doc.getURI().toString() + "')";
                }
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Refine query on documents is enabled.");
                }
            } else {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Refine query on documents is disabled.");
                }
            }
        }

        PreparedStatement ps = conn.prepareStatement(
            "SELECT " + propertyName + ", DOCUMENT_URI, NODE_ID_UNITS, NODE_ID" +
            " FROM " + GMLHSQLIndex.TABLE_NAME + (refine_query_on_doc ? " WHERE " + docConstraint : "")
        );
        ResultSet rs = null;
        try {
            rs = ps.executeQuery();
            ValueSequence result;
            if (contextSet == null)
                result = new ValueSequence();
            else
                result = new ValueSequence(contextSet.getLength());
            while (rs.next()) {
                DocumentImpl doc = null;
                try {
                    doc = (DocumentImpl)broker.getXMLResource(XmldbURI.create(rs.getString("DOCUMENT_URI")));             
                } catch (PermissionDeniedException e) {
                    LOG.debug(e);
                    //Untested, but that is roughly what should be returned.
                    if (rs.getMetaData().getColumnClassName(1).equals(Boolean.class.getName())) {
                        result.add(AtomicValue.EMPTY_VALUE);
                    } else if (rs.getMetaData().getColumnClassName(1).equals(Double.class.getName())) {
                        result.add(AtomicValue.EMPTY_VALUE);
                    } else if (rs.getMetaData().getColumnClassName(1).equals(String.class.getName())) {
                        result.add(AtomicValue.EMPTY_VALUE);
                    } else if (rs.getMetaData().getColumnType(1) == java.sql.Types.BINARY) {
                        result.add(AtomicValue.EMPTY_VALUE);
                    } else
                        throw new SQLException("Unable to make an atomic value from '" + rs.getMetaData().getColumnClassName(1) + "'");
                    //Ignore since the broker has no right on the document
                    continue;
                }
                if (contextSet.getDocumentSet().contains(doc.getDocId())) {
                    NodeId nodeId = new DLN(rs.getInt("NODE_ID_UNITS"), rs.getBytes("NODE_ID"), 0);
                    NodeProxy p = new NodeProxy(doc, nodeId);
                    //Node is in the context : check if it is accurate
                    //contextSet.contains(p) would have made more sense but there is a problem with
                    //VirtualNodeSet when on the DESCENDANT_OR_SELF axis
View Full Code Here

                if (original_geometry.isValid() != rs.getBoolean("IS_VALID")) {
                    LOG.info("Inconsistent area: " + rs.getBoolean("IS_VALID"));
                    return false;
                }

                DocumentImpl doc = null;
                try {
                    doc = (DocumentImpl)broker.getXMLResource(XmldbURI.create(rs.getString("DOCUMENT_URI")));
                } catch (PermissionDeniedException e) {
                    //The broker has no right on the document
                    LOG.error(e);
View Full Code Here

            }
        }

        private BinaryDocument getDoc() throws PermissionDeniedException {

            DocumentImpl doc = context.getBroker().getXMLResource(uri, Lock.READ_LOCK);
            if (doc == null || doc.getResourceType() != DocumentImpl.BINARY_FILE) {
                return null;
            }

            return (BinaryDocument) doc;
        }
View Full Code Here

    public final static String XQUERY_MIME_TYPE = "application/xquery";
   
    public static CompiledXQuery compile(final DBBroker broker, final URI xqueryLocation) throws RestXqServiceCompilationException {
       
        try {
            final DocumentImpl document = broker.getResource(XmldbURI.create(xqueryLocation), Permission.READ);
            if(document != null) {
                return compile(broker, document);
            } else {
                throw new RestXqServiceCompilationException("Invalid document location for XQuery: " + xqueryLocation.toString());
            }
View Full Code Here

        if (LOG.isDebugEnabled()) {
            LOG.debug("Get current lock " + xmldbUri);
        }

        DBBroker broker = null;
        DocumentImpl document = null;

        try {
            broker = brokerPool.get(subject);

            // If it is not a collection, check if it is a document
            document = broker.getXMLResource(xmldbUri, Lock.READ_LOCK);

            if (document == null) {
                LOG.debug("No resource found for path: " + xmldbUri);
                return null;
            }

            // TODO consider. A Webdav lock can be set without subject lock.
            Account lock = document.getUserLock();
            if (lock == null) {

                if (LOG.isDebugEnabled()) {
                    LOG.debug("Document " + xmldbUri + " does not contain userlock");
                }
                return null;
            }

            // Retrieve Locktoken from document metadata
            org.exist.dom.LockToken token = document.getMetadata().getLockToken();
            if (token == null) {

                if (LOG.isDebugEnabled()) {
                    LOG.debug("Document meta data does not contain a LockToken");
                }
                return null;
            }


            if (LOG.isDebugEnabled()) {
                LOG.debug("Successfully retrieved token");
            }

            return token;


        } catch (EXistException | PermissionDeniedException e) {
            LOG.error(e);
            return null;

        } finally {

            if (document != null) {
                document.getUpdateLock().release(Lock.READ_LOCK);
            }

            brokerPool.release(broker);

            if (LOG.isDebugEnabled()) {
View Full Code Here

        if (LOG.isDebugEnabled()) {
            LOG.debug("create lock " + xmldbUri);
        }

        DBBroker broker = null;
        DocumentImpl document = null;
        TransactionManager txnManager = null;
        Txn txn = null;

        try {
            broker = brokerPool.get(subject);

            // Try to get document (add catch?)
            document = broker.getXMLResource(xmldbUri, Lock.WRITE_LOCK);

            if (document == null) {

                if (LOG.isDebugEnabled()) {
                    LOG.debug(String.format("No resource found for path: %s", xmldbUri));
                }
                //return null; // throw exception?
                throw new EXistException("No resource found.");
            }

            // Get current userlock
            Account userLock = document.getUserLock();

            // Check if Resource is already locked. @@ToDo
            if (userLock != null) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Resource was already locked, ignored.");
                }
            }

            if ( userLock != null && userLock.getName() != null
                    && !userLock.getName().equals(subject.getName())
                    && !subject.hasDbaRole() ) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug(String.format("Resource is locked by user %s.", userLock.getName()));
                }
                throw new PermissionDeniedException(userLock.getName());
            }

            // Check for request for shared lock. @@TODO
            if (inputToken.getScope() == LockToken.LOCK_SCOPE_SHARED) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Shared locks are not implemented.");
                }
                throw new EXistException("Shared locks are not implemented.");
            }

            // Update locktoken
            inputToken.setOwner(subject.getName());
            inputToken.createOpaqueLockToken();
            //inputToken.setTimeOut(inputToken.getTimeOut());
            inputToken.setTimeOut(LockToken.LOCK_TIMEOUT_INFINITE);

            // Update document
            document.getMetadata().setLockToken(inputToken);
            document.setUserLock(subject);

            // Make token persistant
            txnManager = brokerPool.getTransactionManager();
            txn = txnManager.beginTransaction();
            broker.storeMetadata(txn, document);
            txnManager.commit(txn);

            if (LOG.isDebugEnabled()) {
                LOG.debug("Successfully retrieved token");
            }
           
            return inputToken;


        } catch (EXistException | PermissionDeniedException e) {
            LOG.error(e);
            if (txnManager != null) {
                txnManager.abort(txn);
            }
            throw e;

        } catch (TriggerException e) {
            LOG.error(e);
            //dead code, remove?
            if (txnManager != null) {
                txnManager.abort(txn);
            }
            //-----------------------
            throw new EXistException(e);

    } finally {

            // TODO: check if can be done earlier
            if (document != null) {
                document.getUpdateLock().release(Lock.WRITE_LOCK);
            }

            if (txnManager != null) {
                txnManager.close(txn);
            }
View Full Code Here

        if (LOG.isDebugEnabled()) {
            LOG.debug("unlock " + xmldbUri);
        }

        DBBroker broker = null;
        DocumentImpl document = null;

        TransactionManager txnManager = brokerPool.getTransactionManager();
        Txn txn = txnManager.beginTransaction();

        try {
            broker = brokerPool.get(subject);


            // Try to get document (add catch?)
            document = broker.getXMLResource(xmldbUri, Lock.WRITE_LOCK);

            if (document == null) {
                final String msg = String.format("No resource found for path: %s", xmldbUri);
                LOG.debug(msg);
                throw new EXistException(msg);
            }

            // Get current userlock
            Account lock = document.getUserLock();

            // Check if Resource is already locked.
            if (lock == null) {
                LOG.debug(String.format("Resource %s is not locked.", xmldbUri));
                throw new DocumentNotLockedException("" + xmldbUri);
            }

            // Check if Resource is from subject
            if (!lock.getName().equals(subject.getName()) && !subject.hasDbaRole() ) {
                LOG.debug(String.format("Resource lock is from user %s", lock.getName()));
                throw new PermissionDeniedException(lock.getName());
            }

            // Update document
            document.setUserLock(null);
            document.getMetadata().setLockToken(null);

            // Make it persistant
            broker.storeMetadata(txn, document);
            txnManager.commit(txn);

        } catch (EXistException | PermissionDeniedException e) {
            txnManager.abort(txn);
            LOG.error(e);
            throw e;

        } catch (TriggerException e) {
            txnManager.abort(txn);
            LOG.error(e);
            throw new EXistException(e);

    } finally {

            if (document != null) {
                document.getUpdateLock().release(Lock.WRITE_LOCK);
            }
            txnManager.close(txn);
            brokerPool.release(broker);

            if (LOG.isDebugEnabled()) {
View Full Code Here

            throw new EXistException(ex.getMessage());
        }

        DBBroker broker = null;
        Collection srcCollection = null;
        DocumentImpl srcDocument = null;

        Collection destCollection = null;


        TransactionManager txnManager = brokerPool.getTransactionManager();
View Full Code Here

        if (LOG.isDebugEnabled()) {
            LOG.debug(String.format("refresh lock %s  lock=%s", xmldbUri, token));
        }

        DBBroker broker = null;
        DocumentImpl document = null;

        if (token == null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("token is null");
            }
            throw new EXistException("token is null");
        }

        // Prepare transaction
        TransactionManager txnManager = null;
        Txn txn = null;

        try {
            broker = brokerPool.get(subject);

            // Try to get document (add catch?)
            document = broker.getXMLResource(xmldbUri, Lock.WRITE_LOCK);

            if (document == null) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug(String.format("No resource found for path: %s", xmldbUri));
                }
                //return null; // throw exception?
                throw new EXistException("No resource found.");
            }

            // Get current userlock
            Account userLock = document.getUserLock();

            // Check if Resource is already locked.
            if (userLock == null) {
                final String msg = "Resource was not locked.";
                if (LOG.isDebugEnabled()) {
                    LOG.debug(msg);
                }
                throw new DocumentNotLockedException(msg);
            }

            if (userLock.getName() != null && !userLock.getName().equals(subject.getName())
                    && !subject.hasDbaRole()) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug(String.format("Resource is locked by %s", userLock.getName()));
                }
                throw new PermissionDeniedException(userLock.getName());
            }

            LockToken lockToken = document.getMetadata().getLockToken();

            if (!token.equals(lockToken.getOpaqueLockToken())) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Token does not match");
                }
                throw new PermissionDeniedException(String.format("Token %s does not match %s", token, lockToken.getOpaqueLockToken()));
            }

            lockToken.setTimeOut(LockToken.LOCK_TIMEOUT_INFINITE);

            // Make token persistant
            txnManager = brokerPool.getTransactionManager();
            txn = txnManager.beginTransaction();
            broker.storeXMLResource(txn, document);
            txnManager.commit(txn);

            if (LOG.isDebugEnabled()) {
                LOG.debug("Successfully retrieved token");
            }
            return lockToken;


        } catch (EXistException | PermissionDeniedException e) {
            LOG.error(e);
            if (txnManager != null) {
                txnManager.abort(txn);
            }
            throw e;

        } finally {

            // TODO: check if can be done earlier
            if (document != null) {
                document.getUpdateLock().release(Lock.WRITE_LOCK);
            }
           
            if (txnManager != null) {
                txnManager.close(txn);
            }
View Full Code Here

TOP

Related Classes of org.exist.dom.DocumentImpl

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.