Package org.exist.storage

Examples of org.exist.storage.BrokerPool


        }
    }

    private static void removeTestCollections() throws Exception {

        BrokerPool pool = BrokerPool.getInstance();
        DBBroker broker = null;
        TransactionManager transact = null;
        Txn txn = null;
        try {
            Subject admin = pool.getSecurityManager().authenticate(ADMIN_UID, ADMIN_PWD);

            broker = pool.get(admin);

            transact = pool.getTransactionManager();
            txn = transact.beginTransaction();

            /** create nessecary collections if they dont exist */
            Collection testCollection = broker.getOrCreateCollection(txn, XmldbURI.create(VALIDATION_HOME_COLLECTION_URI));
            broker.removeCollection(txn, testCollection);

            transact.commit(txn);

        } catch (Exception e) {
            if(transact != null && txn != null) {
                transact.abort(txn);
            }
            throw e;
        } finally {
            if(broker != null) {
                pool.release(broker);
            }
        }
    }
View Full Code Here


        BrokerPool.stopAll(true);
    }

    private static void createTestCollections() throws Exception {

        BrokerPool pool = BrokerPool.getInstance();
        DBBroker broker = null;
        TransactionManager transact = null;
        Txn txn = null;
        try {
            Subject admin = pool.getSecurityManager().authenticate(ADMIN_UID, ADMIN_PWD);

            broker = pool.get(admin);

            transact = pool.getTransactionManager();
            txn = transact.beginTransaction();


            /** create nessecary collections if they dont exist */
            Collection testCollection = broker.getOrCreateCollection(txn, XmldbURI.create(VALIDATION_HOME_COLLECTION_URI));
            testCollection.getPermissions().setOwner(GUEST_UID);
            broker.saveCollection(txn, testCollection);

            Collection col = broker.getOrCreateCollection(txn, XmldbURI.create(VALIDATION_HOME_COLLECTION_URI + "/" + TestTools.VALIDATION_TMP_COLLECTION));
            col.getPermissions().setOwner(GUEST_UID);
            broker.saveCollection(txn, col);

            transact.commit(txn);

        } catch (Exception e) {
            if(transact != null && txn != null) {
                transact.abort(txn);
            }
            throw e;
        } finally {
            if(broker != null) {
                pool.release(broker);
            }
        }
    }
View Full Code Here

        }
    }

    private static void removeTestCollections() throws Exception {

        BrokerPool pool = BrokerPool.getInstance();
        DBBroker broker = null;
        TransactionManager transact = null;
        Txn txn = null;
        try {
            Subject admin = pool.getSecurityManager().authenticate(ADMIN_UID, ADMIN_PWD);

            broker = pool.get(admin);

            transact = pool.getTransactionManager();
            txn = transact.beginTransaction();

            Collection testCollection = broker.getOrCreateCollection(txn, XmldbURI.create(VALIDATION_HOME_COLLECTION_URI));
            broker.removeCollection(txn, testCollection);

            transact.commit(txn);

        } catch (Exception e) {
            if(transact != null && txn != null) {
                transact.abort(txn);
            }
            throw e;
        } finally {
            if(broker != null) {
                pool.release(broker);
            }
        }
    }
View Full Code Here

    public XSL() {
  }
   
    protected static XSLStylesheet compile(ElementAtExist source) throws XPathException {
      BrokerPool pool = null;
      DBBroker broker = null;
      try {
          pool = BrokerPool.getInstance();
        broker = pool.get(null);
      return compile(source, broker);
    } catch (EXistException e) {
      throw new XPathException(e);
    } finally {
      if (pool != null) pool.release(broker);
    }
    }
View Full Code Here

                pool.release(broker);
        }
    }

    protected void tearDown() {
        BrokerPool pool = null;
        DBBroker broker = null;
        TransactionManager transact = null;
        Txn transaction = null;
        try {
            pool = BrokerPool.getInstance();
            assertNotNull(pool);
            broker = pool.get(pool.getSecurityManager().getSystemSubject());
            assertNotNull(broker);
            transact = pool.getTransactionManager();
            assertNotNull(transact);
            transaction = transact.beginTransaction();
            assertNotNull(transaction);
            System.out.println("Transaction started ...");

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

            Collection config = broker.getOrCreateCollection(transaction,
                XmldbURI.create(CollectionConfigurationManager.CONFIG_COLLECTION + "/db"));
            assertNotNull(config);
            broker.removeCollection(transaction, config);
           
            transact.commit(transaction);
        } catch (Exception e) {
          transact.abort(transaction);
            e.printStackTrace();
            fail(e.getMessage());
        } finally {
            if (pool != null) pool.release(broker);
        }
        BrokerPool.stopAll(false);
    }
View Full Code Here

            return true;
        }
        xqueryResourcePath = xqueryResourcePath.trim();
        LOG.info("org.exist.security.openid.verify_logging_script = \"" + xqueryResourcePath + "\"");
       
        BrokerPool pool = null;
        DBBroker broker = null;

        try {
            DocumentImpl resource = null;
            Source source = null;

            pool = BrokerPool.getInstance();

            broker = pool.get(principal);
            if (broker == null) {
                LOG.error("Unable to retrieve DBBroker for " + principal.getMetadataValue(AXSchemaType.ALIAS_USERNAME));
                return false;
            }

            XmldbURI pathUri = XmldbURI.create(xqueryResourcePath);


            resource = broker.getXMLResource(pathUri, Lock.READ_LOCK);

            if(resource != null) {
                LOG.info("Resource " + xqueryResourcePath + " exists.");
                source = new DBSource(broker, (BinaryDocument)resource, true);
            } else {
                LOG.info("Resource " + xqueryResourcePath + " does not exist.");
                LOG.info("pathURI " + pathUri );
                return true;
            }


            XQuery xquery = broker.getXQueryService();

            if (xquery == null) {
                LOG.error("broker unable to retrieve XQueryService");
                return false;
            }

            XQueryContext context = xquery.newContext(AccessContext.REST);

            CompiledXQuery compiled = xquery.compile(context, source);

            Properties outputProperties = new Properties();

            Sequence result = xquery.execute(compiled, null, outputProperties);
            LOG.info("XQuery execution results: " + result.toString());

        } catch (Exception e) {
            LOG.error("Exception while executing OpenID registration script for " + principal.getMetadataValue(AXSchemaType.ALIAS_USERNAME), e);
            return false;
        }
        finally {
            if (pool != null)
                pool.release(broker);
        }
        return true;
    }
View Full Code Here

      throw new TransformerException("The source type "+xmlSource.getClass()+" do not supported.");
    }
  }

  private void transformStream(StAXSource source, StAXResult out) throws TransformerException {
    BrokerPool db = null;
    DBBroker broker = null;
    try {
      db = BrokerPool.getInstance();
      broker = db.get(null);
     
      StAXSequenceIterator sequenceIterator = new StAXSequenceIterator(source);
     
      XSLContext context = new XSLContext(db);
      context.setOutput(out);

      context.getResultWriter().writeStartDocument("UTF-8", "1.0");
     
      if (compiled.rootTemplate != null)
        compiled.rootTemplate.process(context, sequenceIterator);
      else
        ApplyTemplates.searchAndProcess(sequenceIterator, context);
     
      context.getResultWriter().writeEndDocument();
     
    } catch (EXistException e) {
      e.printStackTrace();
    } catch (XMLStreamException e) {
      e.printStackTrace();
    } finally {
      if (db != null)
        db.release(broker);
    }

//    try {
//      for (int event = staxXmlReader.next(); event != XMLStreamConstants.END_DOCUMENT; event = staxXmlReader.next()) {
//        switch (event) {
View Full Code Here

        XMLUnit.setXpathNamespaceContext(ctx);
    }

    @AfterClass
    public static void closeDB() {
        BrokerPool pool = null;
        DBBroker broker = null;
        TransactionManager transact = null;
        Txn transaction = null;
        try {
            pool = BrokerPool.getInstance();
            assertNotNull(pool);
            broker = pool.get(pool.getSecurityManager().getSystemSubject());
            assertNotNull(broker);
            transact = pool.getTransactionManager();
            assertNotNull(transact);
            transaction = transact.beginTransaction();
            assertNotNull(transaction);
            System.out.println("Transaction started ...");

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

            Collection config = broker.getOrCreateCollection(transaction,
                XmldbURI.create(CollectionConfigurationManager.CONFIG_COLLECTION + "/db"));
            assertNotNull(config);
            broker.removeCollection(transaction, config);

            transact.commit(transaction);
        } catch (Exception e) {
          transact.abort(transaction);
            e.printStackTrace();
            fail(e.getMessage());
        } finally {
            if (pool != null) pool.release(broker);
        }
        BrokerPool.stopAll(false);
    }
View Full Code Here

    this.uri = XmldbURI.create(uri);
  }

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

                pool.release(broker);
        }
    }
   
    public void testScanIndex() {
        BrokerPool pool = null;
        DBBroker broker = null;
        try {
            pool = BrokerPool.getInstance();
            broker = pool.get(pool.getSecurityManager().getSystemSubject());
            XQuery xquery = broker.getXQueryService();
            assertNotNull(xquery);
            Sequence seq = xquery.execute(
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "declare function local:key-callback($term as xs:string, $data as xs:int+) as element() { " +
                "   <entry>" +
                "     <term>{$term}</term>" +
                "     <frequency>{$data[1]}</frequency>" +
                "     <documents>{$data[2]}</documents>" +
                "     <position>{$data[3]}</position>" +
                "   </entry> " +
                "}; " +
                //"util:index-keys(//gml:*, '', util:function(xs:QName('local:key-callback'), 2), 1000, 'spatial-index')[entry/frequency > 1] ",
                "util:index-keys(//gml:*, '', util:function(xs:QName('local:key-callback'), 2), 1000, 'spatial-index') ",
                null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() > 1);
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage());
        } finally {
            if (pool!=null) pool.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.