Package org.exist.storage

Examples of org.exist.storage.DBBroker


        //if invalid arguments then abort
        if((pool == null) || (xqueryresource == null) || (user == null)) {
            abort("BrokerPool or XQueryResource or User was null!");
        }

        DBBroker broker = null;
        DocumentImpl resource = null;
        Source source = null;
        XQueryPool xqPool  = null;
        CompiledXQuery compiled = null;
        XQueryContext context = null;

        try {

            //get the xquery
            broker = pool.get(user);

            if(xqueryresource.indexOf(':') > 0) {
                source = SourceFactory.getSource(broker, "", xqueryresource, true);
            } else {
                final XmldbURI pathUri = XmldbURI.create(xqueryresource);
                resource = broker.getXMLResource(pathUri, Lock.READ_LOCK);

                if(resource != null) {
                    source = new DBSource(broker, (BinaryDocument)resource, true);
                }
            }

            if(source != null) {

                //execute the xquery
                final XQuery xquery = broker.getXQueryService();
                xqPool = xquery.getXQueryPool();

                //try and get a pre-compiled query from the pool
                compiled = xqPool.borrowCompiledXQuery(broker, source);
View Full Code Here


            //
        }
    }
   
    public boolean mkdir() {
      DBBroker broker = null;
    BrokerPool db = null;
    TransactionManager tm;

    try {
      try {
        db = BrokerPool.getInstance();
        broker = db.get(null);
      } catch (final EXistException e) {
        return false;
      }
 
          final Collection collection = broker.getCollection(uri.toCollectionPathURI());
          if (collection != null) {return true;}
 
          final Collection parent_collection = broker.getCollection(uri.toCollectionPathURI().removeLastSegment());
          if (parent_collection == null) {return false;}
 
          tm = db.getTransactionManager();
      final Txn transaction = tm.beginTransaction();
     
      try {
        final Collection child = broker.getOrCreateCollection(transaction, uri.toCollectionPathURI());
        broker.saveCollection(transaction, child);
        tm.commit(transaction);
      } catch (final Exception e) {
          tm.abort(transaction);
        return false;
      } finally {
View Full Code Here

     
      return true;
    }

    public boolean mkdirs() {
      DBBroker broker = null;
    BrokerPool db = null;
    TransactionManager tm;

    try {
      try {
        db = BrokerPool.getInstance();
        broker = db.get(null);
      } catch (final EXistException e) {
        return false;
      }
 
          final Collection collection = broker.getCollection(uri.toCollectionPathURI());
          if (collection != null) {return true;}
 
      tm = db.getTransactionManager();
      final Txn transaction = tm.beginTransaction();
     
      try {
        final Collection child = broker.getOrCreateCollection(transaction, uri.toCollectionPathURI());
        broker.saveCollection(transaction, child);
        tm.commit(transaction);
      } catch (final Exception e) {
          tm.abort(transaction);
        return false;
      } finally {
View Full Code Here

    }
   
    public boolean _renameTo(File dest) {
      final XmldbURI destinationPath = ((Resource)dest).uri;

      DBBroker broker = null;
    BrokerPool db = null;
    TransactionManager tm;

    try {
      try {
        db = BrokerPool.getInstance();
        broker = db.get(null);
      } catch (final EXistException e) {
        return false;
      }
 
      tm = db.getTransactionManager();
      Txn transaction = null;
 
          org.exist.collections.Collection destination = null;
          org.exist.collections.Collection source = null;
          XmldbURI newName;
      try {
           source = broker.openCollection(uri.removeLastSegment(), Lock.WRITE_LOCK);
          if(source == null) {
            return false;
              }
          final DocumentImpl doc = source.getDocument(broker, uri.lastSegment());
              if(doc == null) {
                  return false;
              }
              destination = broker.openCollection(destinationPath.removeLastSegment(), Lock.WRITE_LOCK);
              if(destination == null) {
                  return false;
              }
             
              newName = destinationPath.lastSegment();
 
              transaction = tm.beginTransaction();
              broker.moveResource(transaction, doc, destination, newName);
              tm.commit(transaction);
              return true;
             
          } catch ( final Exception e ) {
            e.printStackTrace();
View Full Code Here

     
//      System.out.println("rename from "+uri+" to "+dest.getPath());
     
        final XmldbURI destinationPath = ((Resource)dest).uri;

        DBBroker broker = null;
        BrokerPool db = null;
        TransactionManager tm;

        try {
            try {
                db = BrokerPool.getInstance();
                broker = db.get(null);
            } catch (final EXistException e) {
                return false;
            }
   
            tm = db.getTransactionManager();
            Txn transaction = null;
   
            org.exist.collections.Collection destination = null;
            org.exist.collections.Collection source = null;
            XmldbURI newName;
            try {
                source = broker.openCollection(uri.removeLastSegment(), Lock.WRITE_LOCK);
                if(source == null) {
                    return false;
                }
                final DocumentImpl doc = source.getDocument(broker, uri.lastSegment());
                if(doc == null) {
                    return false;
                }
                destination = broker.openCollection(destinationPath.removeLastSegment(), Lock.WRITE_LOCK);
                if(destination == null) {
                    return false;
                }
               
                newName = destinationPath.lastSegment();
View Full Code Here

   
    protected synchronized void uploadTmpFile() throws IOException {
      if (file == null)
        {throw new IOException();}
     
        DBBroker broker = null;
        BrokerPool db = null;
        TransactionManager tm = null;
        Txn txn = null;

        try {
View Full Code Here

            }
        }
    }
   
    public boolean delete() {
      DBBroker broker = null;
    BrokerPool db = null;
    TransactionManager tm;

    try {
      try {
        db = BrokerPool.getInstance();
        broker = db.get(null);
      } catch (final EXistException e) {
        return false;
      }
 
      tm = db.getTransactionManager();
          Txn txn = null;
          try {
              collection = broker.openCollection(uri.removeLastSegment(), Lock.NO_LOCK);
              if (collection == null) {
                  return false;
              }
              // keep the write lock in the transaction
              //transaction.registerLock(collection.getLock(), Lock.WRITE_LOCK);
View Full Code Here

  }
 
    private void store(String name,  String data) throws EXistException {
      Database pool = BrokerPool.getInstance();;
     
        DBBroker broker = null;
        TransactionManager transact = null;
        Txn transaction = null;
        try {
            broker = pool.get(pool.getSecurityManager().getSystemSubject());
            assertNotNull(broker);
            transact = pool.getTransactionManager();
            assertNotNull(transact);
            transaction = transact.beginTransaction();
            assertNotNull(transaction);

            Collection root = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
        broker.saveCollection(transaction, root);
            assertNotNull(root);

            root.addBinaryResource(transaction, broker, XmldbURI.create(name), data.getBytes(), "application/xquery");

            transact.commit(transaction);
View Full Code Here

            initialized = false;
        }
    }

    public boolean createNewFile() throws IOException {
      DBBroker broker = null;
    BrokerPool db = null;
    TransactionManager tm;

    try {
      try {
        db = BrokerPool.getInstance();
        broker = db.get(null);
      } catch (final EXistException e) {
        throw new IOException(e);
      }
     
//      if (!uri.startsWith("/db"))
//        uri = XmldbURI.DB.append(uri);
// 
      try {
        if (uri.endsWith("/"))
          {throw new IOException("It collection, but should be resource: "+uri);}
      } catch (final Exception e) {
        throw new IOException(e);
      }
     
      final XmldbURI collectionURI = uri.removeLastSegment();
      collection = broker.getCollection(collectionURI);
      if (collection == null)
        {throw new IOException("Collection not found: "+collectionURI);}
     
      final XmldbURI fileName = uri.lastSegment();
 
//      try {
//        resource = broker.getXMLResource(uri, Lock.READ_LOCK);
//      } catch (final PermissionDeniedException e1) {
//      } finally {
//        if (resource != null) {
//          resource.getUpdateLock().release(Lock.READ_LOCK);
//          collection = resource.getCollection();
//          initialized = true;
//         
//          return false;
//        }
//      }
//     
      try {
        resource = broker.getResource(uri, Lock.READ_LOCK);
      } catch (final PermissionDeniedException e1) {
      } finally {
        if (resource != null) {
          resource.getUpdateLock().release(Lock.READ_LOCK);
          collection = resource.getCollection();
View Full Code Here

        collection = null;
        resource = null;
        initialized = false;
    }
     
      DBBroker broker = null;
    BrokerPool db = null;

    try {
      try {
        db = BrokerPool.getInstance();
        broker = db.get(null);
      } catch (final EXistException e) {
        throw new IOException(e);
      }
 
      try {
        //collection
        if (uri.endsWith("/")) {
          collection = broker.getCollection(uri);
          if (collection == null)
            {throw new IOException("Resource not found: "+uri);}
         
        //resource
        } else {
          resource = broker.getXMLResource(uri, Lock.READ_LOCK);
          if (resource == null) {
            //may be, it's collection ... checking ...
            collection = broker.getCollection(uri);
            if (collection == null) {
              throw new IOException("Resource not found: "+uri);
            }
          } else {
            collection = resource.getCollection();
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.