Package org.exist.storage

Examples of org.exist.storage.BrokerPool


  class GetRelease implements Runnable {

    @Override
    public void run() {
          try {
            BrokerPool db = BrokerPool.getInstance();
       
            Subject subject = db.getSecurityManager().getSystemSubject();
           
            DBBroker broker = null;
        try {
          broker = db.get(subject);
              System.out.println("get broker "+Thread.currentThread());
         
          //do something
          Thread.sleep(rd.nextInt(5000));
         
          try {
            assertEquals(broker, db.get(null));
 
            //do something
            Thread.sleep(rd.nextInt(5000));
          } finally {
            db.release(broker);
          }

        } finally {
              System.out.println("releasing broker "+Thread.currentThread());
          db.release(broker);
        }
       
      } catch (Throwable e) {
        ex = e;
      }
View Full Code Here


        return (XPathQueryService) root.getService( "XQueryService", "1.0" );
    }

    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 */
            org.exist.collections.Collection testCollection = broker.getOrCreateCollection(txn, XmldbURI.create(VALIDATION_HOME_COLLECTION_URI));
            testCollection.getPermissions().setOwner(GUEST_UID);
            broker.saveCollection(txn, testCollection);

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

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

            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 createTestDocuments() throws Exception {

        BrokerPool pool = BrokerPool.getInstance();
        DBBroker broker = null;
        TransactionManager transact = null;
        Txn txn = null;
        try {

            broker = pool.get(pool.getSecurityManager().getGuestSubject());

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

            /** create necessary documents  */

            //hamlet
            String sb = new String(TestTools.getHamlet());
            sb = sb.replaceAll("\\Q<!\\E.*DOCTYPE.*\\Q-->\\E",
                "<!DOCTYPE PLAY PUBLIC \"-//PLAY//EN\" \"play.dtd\">" );

            org.exist.collections.Collection tmpCol = broker.getCollection(XmldbURI.create(VALIDATION_HOME_COLLECTION_URI + "/" + TestTools.VALIDATION_TMP_COLLECTION));
            storeDocument(broker, txn, tmpCol, "hamlet_valid.xml", sb);
            broker.saveCollection(txn, tmpCol);

            config.setProperty(XMLReaderObjectFactory.PROPERTY_VALIDATION_MODE, "no");

            org.exist.collections.Collection dtdCol = broker.getCollection(XmldbURI.create(VALIDATION_HOME_COLLECTION_URI + "/" + TestTools.VALIDATION_DTD_COLLECTION));
            storeTextDocument(broker, txn, dtdCol, "hamlet.dtd", new String(TestTools.loadSample("validation/dtd/hamlet.dtd")));
            storeDocument(broker, txn, dtdCol, "catalog.xml", new String(TestTools.loadSample("validation/dtd/catalog.xml")));
            broker.saveCollection(txn, dtdCol);

            org.exist.collections.Collection homeCol = broker.getCollection(XmldbURI.create(VALIDATION_HOME_COLLECTION_URI));
            storeDocument(broker, txn, homeCol, "hamlet_valid.xml", new String(TestTools.loadSample("validation/dtd/hamlet_valid.xml")));
            storeDocument(broker, txn, homeCol, "hamlet_invalid.xml", new String(TestTools.loadSample("validation/dtd/hamlet_invalid.xml")));
            broker.saveCollection(txn, homeCol);

            config.setProperty(XMLReaderObjectFactory.PROPERTY_VALIDATION_MODE, "yes");

            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

        collection.addBinaryResource(txn, broker, docUri, data.getBytes(), "text/plain");
    }

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

            org.exist.collections.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

                    "    <?echo \"A processing instruction\"?>\n" +
                    "    <para>Another <b>paragraph</b>.</para>\n" +
                    "</test>";

    public void testNodeStorage() throws Exception {
        BrokerPool pool = BrokerPool.getInstance();
        DBBroker broker = null;
        try {
            broker = pool.get(pool.getSecurityManager().getSystemSubject());
            XQuery xquery = broker.getXQueryService();
            assertNotNull(xquery);
            // test element ids
            Sequence seq = xquery.execute("doc('/db/test/test_string.xml')/test/para",
                    null, AccessContext.TEST);
            assertEquals(3, seq.getItemCount());
            NodeProxy comment = (NodeProxy) seq.itemAt(0);
            assertEquals(comment.getNodeId().toString(), "1.1");
            comment = (NodeProxy) seq.itemAt(1);
            assertEquals(comment.getNodeId().toString(), "1.3");
            comment = (NodeProxy) seq.itemAt(2);
            assertEquals(comment.getNodeId().toString(), "1.5");

            seq = xquery.execute("doc('/db/test/test_string.xml')/test//a",
                    null, AccessContext.TEST);
            assertEquals(1, seq.getItemCount());
            NodeProxy a = (NodeProxy) seq.itemAt(0);
            assertEquals("1.3.2", a.getNodeId().toString());

            // test attribute id
            seq = xquery.execute("doc('/db/test/test_string.xml')/test//a/@href",
                    null, AccessContext.TEST);
            assertEquals(1, seq.getItemCount());
            NodeProxy href = (NodeProxy) seq.itemAt(0);
            System.out.println(StorageAddress.toString(href.getInternalAddress()));
            assertEquals("1.3.2.1", href.getNodeId().toString());
            // test Attr deserialization
            Attr attr = (Attr) href.getNode();
            System.out.println(StorageAddress.toString(((StoredNode)attr).getInternalAddress()));
            // test Attr fields
            assertEquals(attr.getNodeName(), "href");
            assertEquals(attr.getName(), "href");
            assertEquals(attr.getValue(), "#");
             // test DOMFile.getNodeValue()
            assertEquals(href.getStringValue(), "#");

            // test text node
            seq = xquery.execute("doc('/db/test/test_string.xml')/test//b/text()",
                    null, AccessContext.TEST);
            assertEquals(1, seq.getItemCount());
            NodeProxy text = (NodeProxy) seq.itemAt(0);
            assertEquals("1.5.2.1", text.getNodeId().toString());
            // test DOMFile.getNodeValue()
            assertEquals(text.getStringValue(), "paragraph");
            // test Text deserialization
            Text node = (Text) text.getNode();
            assertEquals(node.getNodeValue(), "paragraph");
            assertEquals(node.getData(), "paragraph");
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage());
        } finally {
            pool.release(broker);
        }
    }
View Full Code Here

            BrokerPool.configure(1, 5, config);
        } catch (Exception e) {
            fail(e.getMessage());
        }

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

            Collection test = broker.getOrCreateCollection(transaction, TEST_COLLECTION);
            broker.saveCollection(transaction, test);

            IndexInfo info = test.validateXMLResource(transaction, broker, XmldbURI.create("test_string.xml"),
                TEST_XML);
            //TODO : unlock the collection here ?
            assertNotNull(info);

            test.store(transaction, broker, info, TEST_XML, false);

            transact.commit(transaction);
            System.out.println("Transaction commited ...");
        } catch (Exception e) {
          transact.abort(transaction);
            fail(e.getMessage());
        } finally {
            pool.release(broker);
        }
    }
View Full Code Here

        this.realm = realm;
        this.id = id;
        this.name = name;

        if (collection != null) {
            BrokerPool database;
            try {
                database = BrokerPool.getInstance();
            } catch (final EXistException e) {
                throw new ConfigurationException(e);
            }

            DBBroker broker = null;
            try {
                broker = database.get(null);

                final Configuration _config_ = Configurator.parse(this, broker, collection, XmldbURI.create(name + ".xml"));
                configuration = Configurator.configure(this, _config_);
            } catch (final EXistException e) {
                throw new ConfigurationException(e);
            } finally {
                database.release(broker);
            }
        }
    }
View Full Code Here

        decoder.reset();
        return outBuf.flip().toString();
    }

    private static Subject getUser() throws SVNException {
      BrokerPool database;
      try {
      database = BrokerPool.getInstance();
    } catch (EXistException e) {
            SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.IO_ERROR,
                    "Cannot get current user: {0}", e.getMessage());
            SVNErrorManager.error(err, e, Level.FINE, SVNLogType.DEFAULT);
            return null;
    }
   
      DBBroker broker = null;
    try {
      broker = database.get(null);
          return broker.getSubject();
    } catch (EXistException e) {
            SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.IO_ERROR,
                    "Cannot get current user: {0}", e.getMessage());
            SVNErrorManager.error(err, e, Level.FINE, SVNLogType.DEFAULT);
    } finally {
      database.release(broker);
    }
   
    return null;
    }
View Full Code Here

                    break;
                }
            }
        }

        final BrokerPool pool = startDB( dbConfig );

        if( pool == null ) {
            System.exit( 1 );
        }
        int      retval = 0; // return value
        DBBroker broker = null;

        try {
            broker = pool.get(pool.getSecurityManager().getSystemSubject());
            List<ErrorReport> errors  = null;
           
            if(!nocheck) {
                final ConsistencyCheck  checker = new ConsistencyCheck( broker, direct, checkDocs );
                errors = checker.checkAll( new CheckCallback() );
            }

            if( errors != null && errors.size() > 0 ) {
                System.err.println( "ERRORS FOUND." );
                retval = 1;
            } else {
                System.out.println( "No errors." );
            }

            if( export ) {
                final File dir = new File( exportTarget );

                if( !dir.exists() ) {
                    dir.mkdirs();
                }
                final SystemExport sysexport = new SystemExport( broker, new Callback(verbose), null, direct );
                sysexport.export( exportTarget, incremental, zip, errors );
            }
        }
        catch( final EXistException e ) {
            System.err.println( "ERROR: Failed to retrieve database broker: " + e.getMessage() );
            retval = 2;
        }
        catch( final TerminatedException e ) {
            System.err.println( "WARN: Export was terminated by db." );
            retval = 3;
        }
        catch(final PermissionDeniedException pde) {
            System.err.println( "ERROR: Failed to retrieve database data: " + pde.getMessage() );
            retval = 4;
        }
        finally {
            pool.release( broker );
            BrokerPool.stopAll( false );
        }
        System.exit( retval );
    }
View Full Code Here

        }

        @Override
        public Sequence call() throws XPathException {
         
          BrokerPool db = null;
            DBBroker broker = null;
           
            try {
        db = BrokerPool.getInstance();
      } catch (final EXistException e) {
                throw new XPathException("Unable to get new broker: " + e.getMessage(), e);
      }
           
            try {
                final XQueryContext context = callersContext.copyContext(); //make a copy
                broker = db.get(subject); //get a new broker

                return doEval(context, contextSequence, args);
            } catch(final EXistException ex) {
                throw new XPathException("Unable to get new broker: " + ex.getMessage(), ex);
            } finally {
              db.release(broker); //release the 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.