Package org.exist.storage

Examples of org.exist.storage.BrokerPool


    private URLConnection connection = null;
   
    private URLConnection getConnection() throws IOException {
      if (connection == null) {
      BrokerPool db = null;
      DBBroker broker = null;
      try {
        db = BrokerPool.getInstance();
        broker = db.get(null);
        final Subject subject = broker.getSubject();
       
        final URL url = new URL("xmldb:exist://jsessionid:"+subject.getSessionId()+"@"+ uri.toString());
        connection = url.openConnection();
      } catch (final IllegalArgumentException e) {
        throw new IOException(e);
      } catch (final MalformedURLException e) {
        throw new IOException(e);
      } catch (final EXistException e) {
        throw new IOException(e);
      } finally {
        if (db != null)
          {db.release(broker);}
      }
      }
      return connection;
    }
View Full Code Here


  }

  public Collection getCollection() throws IOException {
    if (!initialized) {
        DBBroker broker = null;
      BrokerPool db = null;

      try {
        try {
          db = BrokerPool.getInstance();
          broker = db.get(null);
        } catch (final EXistException e) {
          throw new IOException(e);
        }
 
        try {
          if (uri.endsWith("/")) {
            collection = broker.getCollection(uri);
          } else {
            collection = broker.getCollection(uri);
            if (collection == null)
              {collection = broker.getCollection(uri.removeLastSegment());}
          }
          if (collection == null)
            {throw new IOException("Collection not found: "+uri);}
         
          return collection;
        } catch (final Exception e) {
          throw new IOException(e);
        }
      } finally {
        if (db != null)
          {db.release(broker);}
      }
    }

    if (resource == null)
      {return collection;}
View Full Code Here

    public String[] list() {
     
      if (isDirectory()) {
       
          DBBroker broker = null;
        BrokerPool db = null;

        try {
          try {
            db = BrokerPool.getInstance();
            broker = db.get(null);
          } catch (final EXistException e) {
                  return new String[0];
          }

            final List<String> list = new ArrayList<String>();
          for (final CollectionEntry entry : collection.getEntries(broker)) {
            list.add(entry.getUri().lastSegment().toString());
          }
         
          return list.toArray(new String[list.size()]);

        } catch (final PermissionDeniedException e) {
              return new String[0];

      } finally {
              if (db != null)
                {db.release( broker );}
            }
      }
     
      return new String[0];
    }
View Full Code Here

     
      if (collection == null)
        {return null;}
     
      DBBroker broker = null;
    BrokerPool db = null;

    try {
      try {
        db = BrokerPool.getInstance();
        broker = db.get(null);
      } catch (final EXistException e) {
        return null;
      }
 
        try {
            collection.getLock().acquire(Lock.READ_LOCK);
 
            final File[] children = new File[collection.getChildCollectionCount(broker) +
                                         collection.getDocumentCount(broker)];
             
              //collections
              int j = 0;
              for (final Iterator<XmldbURI> i = collection.collectionIterator(broker); i.hasNext(); j++)
                children[j] = new Resource(collection.getURI().append(i.next()));
 
              //collections
              final List<XmldbURI> allresources = new ArrayList<XmldbURI>();
              DocumentImpl doc = null;
              for (final Iterator<DocumentImpl> i = collection.iterator(broker); i.hasNext(); ) {
                  doc = i.next();
                 
                  // Include only when (1) locktoken is present or (2)
                  // locktoken indicates that it is not a null resource
                  final LockToken lock = doc.getMetadata().getLockToken();
                  if(lock==null || (!lock.isNullResource()) ){
                      allresources.add( doc.getURI() );
                  }
              }
             
              // Copy content of list into String array.
              for(final Iterator<XmldbURI> i = allresources.iterator(); i.hasNext(); j++){
                children[j] = new Resource(i.next());
              }
             
              return children;
          } catch (final LockException e) {
            //throw new IOException("Failed to acquire lock on collection '" + uri + "'");
          return null;
         
          } catch (final Exception e) {
            return null;
           
        } finally {
            collection.release(Lock.READ_LOCK);
        }
     
    } catch (final Exception e) {
      return null;
     
    } finally {
        if (db != null)
          {db.release(broker);}
      }
    }
View Full Code Here

    } catch (final IOException e) {
      throw new FileNotFoundException(e.getMessage());
    }
   
      DBBroker broker = null;
    BrokerPool db = null;

    try {
      try {
        db = BrokerPool.getInstance();
        broker = db.get(null);
      } catch (final EXistException e) {
        throw new FileNotFoundException(e.getMessage());
      }
 
      if (doc instanceof BinaryDocument) {
        return broker.getBinaryFile(((BinaryDocument)doc));
       
      } else {
        return serialize(broker, doc);
      }

    } catch (final Exception e) {
      throw new FileNotFoundException(e.getMessage());
     
    } finally {
        if (db != null)
          {db.release(broker);}
      }
//    throw new FileNotFoundException("unsupported operation for "+doc.getClass()+".");
  }
View Full Code Here

   
    private void modifyMetadata(ModifyMetadata method) throws IOException {
//      if (initialized) {return;}
     
    DBBroker broker = null;
    BrokerPool db = null;

    try {
      try {
        db = BrokerPool.getInstance();
        broker = db.get(null);
      } catch (final EXistException e) {
        throw new IOException(e);
      }
 
      final TransactionManager tm = db.getTransactionManager();
      Txn txn = null;
     
      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);
            }
           
            txn = tm.beginTransaction();

            method.modify(collection);
            broker.saveCollection(txn, collection);
           
            tm.commit(txn);

          } else {
            collection = resource.getCollection();

            txn = tm.beginTransaction();
           
            method.modify(resource);
                  broker.storeMetadata(txn, resource);
           
            tm.commit(txn);
          }
        }
      } catch (final IOException e) {
        if (txn != null) {
          tm.abort(txn);
        }
        throw e;
      } catch (final Exception e) {
        if (txn != null) {
          tm.abort(txn);
        }
        throw new IOException(e);
      } finally {
                tm.close(txn);
        if (resource != null)
          {resource.getUpdateLock().release(Lock.READ_LOCK);}
      }
    } finally {
      if (db != null)
        {db.release(broker);}
    }
   
    initialized = true;
    }
View Full Code Here


    @Override
    public final void execute(final JobExecutionContext jec) throws JobExecutionException {
        final JobDataMap jobDataMap = jec.getJobDetail().getJobDataMap();
        final BrokerPool pool = (BrokerPool)jobDataMap.get("brokerpool");
        final SystemTask task = ( SystemTask )jobDataMap.get("systemtask");

        //if invalid arguments then abort
        if((pool == null) || (task == null)) {

            //abort all triggers for this job
            final JobExecutionException jaa = new JobExecutionException("SystemTaskJob Failed: BrokerPool or SystemTask was null! Unscheduling SystemTask", false);
            jaa.setUnscheduleAllTriggers( true );
            throw jaa;
        }

        //trigger the system task
        pool.triggerSystemTask(task);
    }
View Full Code Here

    @Override
    public final void execute(final JobExecutionContext jec) throws JobExecutionException {
        final JobDataMap jobDataMap = jec.getJobDetail().getJobDataMap();

        //get the brokerpool from the data map
        final BrokerPool pool = (BrokerPool)jobDataMap.get("brokerpool");

        //get any parameters from the data map
        final Map params = (Map)jobDataMap.get("params");

        try {
View Full Code Here

 
  public DocumentImpl getDocument(String uuid) throws EXistException, PermissionDeniedException {
    MetasImpl ms = docByUUID.get(uuid);
    if (ms == null) return null;
   
    BrokerPool db = null;
    DBBroker broker = null;
    try {
      db = BrokerPool.getInstance();
      broker = db.get(null);
     
      XmldbURI uri = XmldbURI.create(ms.uri);
      Collection col = broker.getCollection(uri.removeLastSegment());
      if (col != null) {
        return col.getDocument(broker, uri.lastSegment());
      }
     
      return null;
    } finally {
      if (db != null)
        db.release(broker);
    }
  }
View Full Code Here

  public Collection getCollection(String uuid) throws EXistException, PermissionDeniedException {
    MetasImpl ms = docByUUID.get(uuid);
    if (ms == null) return null;
   
    BrokerPool db = null;
    DBBroker broker = null;
    try {
      db = BrokerPool.getInstance();
      broker = db.get(null);
     
      XmldbURI uri = XmldbURI.create(ms.uri);
      return broker.getCollection(uri);
    } finally {
      if (db != null)
        db.release(broker);
    }
  }
View Full Code Here

TOP

Related Classes of org.exist.storage.BrokerPool

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.