Examples of BrokerPool


Examples of org.exist.storage.BrokerPool

        }
    }
   
    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 {
                tm.close(transaction);
            }
        } catch (final Exception e) {
      return false;
     
    } finally {
      if (db != null)
        {db.release(broker);}
    }
     
      return true;
    }
View Full Code Here

Examples of org.exist.storage.BrokerPool

      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 {
                tm.close(transaction);
            }

    } catch (final Exception e) {
      return false;
   
    } finally {
      if (db != null)
        {db.release(broker);}
    }
     
      return true;
    }
View Full Code Here

Examples of org.exist.storage.BrokerPool

   
    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();
            if (transaction != null) {tm.abort(transaction);}
            return false;
          } finally {
                tm.close(transaction);
            if(source != null) {source.release(Lock.WRITE_LOCK);}
            if(destination != null) {destination.release(Lock.WRITE_LOCK);}
          }
        } finally {
          if (db != null)
            {db.release( broker );}
        }
    }
View Full Code Here

Examples of org.exist.storage.BrokerPool

//      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();
   
                transaction = tm.beginTransaction();
                moveResource(broker, transaction, doc, source, destination, newName);

//                resource = null;
//                collection = null;
//                initialized = false;
//                uri = ((Resource)dest).uri;

                tm.commit(transaction);
                return true;
               
            } catch ( final Exception e ) {
                e.printStackTrace();
                if (transaction != null) {tm.abort(transaction);}
                return false;
            } finally {
                tm.close(transaction);
                if(source != null) {source.release(Lock.WRITE_LOCK);}
                if(destination != null) {destination.release(Lock.WRITE_LOCK);}
            }
        } finally {
            if (db != null)
                {db.release( broker );}
        }
    }
View Full Code Here

Examples of org.exist.storage.BrokerPool

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

            FileInputSource is = new FileInputSource(file);
         
            final IndexInfo info = collection.validateXMLResource(txn, broker, uri.lastSegment(), is);
//          info.getDocument().getMetadata().setMimeType(mimeType.getName());
 
          is = new FileInputSource(file);
          collection.store(txn, broker, info, is, false);

            tm.commit(txn);
           
        } catch ( final Exception e ) {
            e.printStackTrace();
            if (txn != null) {tm.abort(txn);}
      } finally {
            tm.close(txn);
          if (db != null)
              {db.release( broker );}
      }
    }
View Full Code Here

Examples of org.exist.storage.BrokerPool

        }
    }
   
    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);
 
              final DocumentImpl doc = collection.getDocument(broker, uri.lastSegment());
              if (doc == null) {
                return true;
              }
             
              txn = tm.beginTransaction();
              if(doc.getResourceType() == DocumentImpl.BINARY_FILE)
                  {collection.removeBinaryResource(txn, broker, doc);}
              else
                  {collection.removeXMLResource(txn, broker, uri.lastSegment());}
             
              tm.commit(txn);
              return true;
 
          } catch (final Exception e) {
            if (txn != null) {tm.abort(txn);}
              return false;
          } finally {
                tm.close(txn);
            }
        } finally {
          if (db != null)
            {db.release(broker);}

            resource = null;
            collection = null;
            initialized = false;
        }
View Full Code Here

Examples of org.exist.storage.BrokerPool

        }
    }

    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();
          initialized = true;
         
          return false;
        }
      }

      MimeType mimeType = MimeTable.getInstance().getContentTypeFor(fileName);
 
      if (mimeType == null) {
        mimeType = MimeType.BINARY_TYPE;
      }
     
      tm = db.getTransactionManager();
      final Txn transaction = tm.beginTransaction();
 
      InputStream is = null;
      try {
        if (mimeType.isXMLType()) {
          // store as xml resource
          final String str = "<empty/>";
          final IndexInfo info = collection.validateXMLResource(transaction, broker, fileName, str);
          info.getDocument().getMetadata().setMimeType(mimeType.getName());
          info.getDocument().getPermissions().setMode(DEFAULT_RESOURCE_PERM);
          collection.store(transaction, broker, info, str, false);
 
        } else {
          // store as binary resource
          is = new ByteArrayInputStream("".getBytes(UTF_8));
         
          final BinaryDocument blob = new BinaryDocument(db, collection, fileName);
 
          blob.getPermissions().setMode(DEFAULT_RESOURCE_PERM);

          collection.addBinaryResource(transaction, broker, blob, is,
              mimeType.getName(), 0L , new Date(), new Date());
 
        }
        tm.commit(transaction);
      } catch (final Exception e) {
        tm.abort(transaction);
        throw new IOException(e);
      } finally {
                tm.close(transaction);
        closeFile(is);
 
        if (resource != null)
          {resource.getUpdateLock().release(Lock.READ_LOCK);}
      }
     
    } catch (final Exception e) {
      return false;
     
    } finally {
      if (db != null)
        {db.release(broker);}
    }
   
    return true;
    }
View Full Code Here

Examples of org.exist.storage.BrokerPool

       
        //TODO why are these values not used from the class members?
        final String xqueryresource = (String)jobDataMap.get("xqueryresource");
        final Subject user = (Subject)jobDataMap.get("user");
       
        final BrokerPool pool = (BrokerPool)jobDataMap.get("brokerpool");
        final Properties params = (Properties)jobDataMap.get("params");
        final boolean unschedule = ((Boolean)jobDataMap.get("unschedule")).booleanValue();

        //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);

                if(compiled == null) {
                    context = xquery.newContext(AccessContext.REST); //TODO should probably have its own AccessContext.SCHEDULER
                } else {
                    context = compiled.getContext();
                }

                //TODO: don't hardcode this?
                if(resource != null) {
                    context.setModuleLoadPath(XmldbURI.EMBEDDED_SERVER_URI.append(resource.getCollection().getURI()).toString());
                    context.setStaticallyKnownDocuments(new XmldbURI[] {
                        resource.getCollection().getURI()
                    });
                }

                if(compiled == null) {

                    try {
                        compiled = xquery.compile(context, source);
                    }
                    catch(final IOException e) {
                        abort("Failed to read query from " + xqueryresource);
                    }
                }

                //declare any parameters as external variables
                if(params != null) {
                    String bindingPrefix = params.getProperty("bindingPrefix");

                    if(bindingPrefix == null) {
                        bindingPrefix = "local";
                    }
                   

                    for(final Entry param : params.entrySet()) {
                        final String key = (String)param.getKey();
                        final String value = (String)param.getValue();
                        context.declareVariable( bindingPrefix + ":" + key, new StringValue(value));
                    }
                }

                xquery.execute(compiled, null);

            } else {
                LOG.warn("XQuery User Job not found: " + xqueryresource + ", job not scheduled");
            }
        } catch(final EXistException ee) {
            abort("Could not get DBBroker!");
        } catch(final PermissionDeniedException pde) {
            abort("Permission denied for the scheduling user: " + user.getName() + "!");
        } catch(final XPathException xpe) {
            abort("XPathException in the Job: " + xpe.getMessage() + "!", unschedule);
        } catch(final MalformedURLException e) {
            abort("Could not load XQuery: " + e.getMessage());
        } catch(final IOException e) {
            abort("Could not load XQuery: " + e.getMessage());
        } finally {

            if(context != null) {
                context.runCleanupTasks();
            }
           
            //return the compiled query to the pool
            if(xqPool != null && source != null && compiled != null) {
                xqPool.returnCompiledXQuery(source, compiled);
            }

            //release the lock on the xquery resource
            if(resource != null) {
                resource.getUpdateLock().release(Lock.READ_LOCK);
            }

            // Release the DBBroker
            if(pool != null && broker != null) {
                pool.release(broker);
            }
        }

    }
View Full Code Here

Examples of org.exist.storage.BrokerPool

        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();
          }
        }
      } catch (final IOException e) {
        throw e;
      } catch (final Exception e) {
        throw new IOException(e);
      } finally {
        if (resource != null)
          {resource.getUpdateLock().release(Lock.READ_LOCK);}
      }
    } finally {
      if (db != null)
        {db.release(broker);}
    }
   
    initialized = true;
    }
View Full Code Here

Examples of org.exist.storage.BrokerPool

      throw new IOException("this never should happen");
    }
   
    private Subject getBrokerUser() throws IOException {
      DBBroker broker = null;
    BrokerPool db = null;

    try {
      db = BrokerPool.getInstance();
      broker = db.get(null);
     
      return broker.getSubject();
    } catch (final EXistException e) {
      throw new IOException(e);
    } finally {
      if (db != null)
        {db.release(broker);}
    }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.