Package org.exist.storage.txn

Examples of org.exist.storage.txn.TransactionManager


 
    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);
        } catch (Exception e) {
            if (transact != null)
                transact.abort(transaction);
            e.printStackTrace();
            fail(e.getMessage());
        } finally {
            pool.release(broker);
        }
View Full Code Here


                    }

                    remove_account.setRemoved(true);
                    remove_account.setCollection(broker, collectionRemovedAccounts, XmldbURI.create(UUIDGenerator.getUUID()+".xml"));

                    final TransactionManager transaction = getDatabase().getTransactionManager();
                    Txn txn = null;
                    try {
                        txn = transaction.beginTransaction();

                        collectionAccounts.removeXMLResource(txn, broker, XmldbURI.create( remove_account.getName() + ".xml"));

                        transaction.commit(txn);
                    } catch(final Exception e) {
                        transaction.abort(txn);
                        e.printStackTrace();
                        LOG.debug("loading configuration failed: " + e.getMessage());
                    } finally {
                        transaction.close(txn);
                    }

                    getSecurityManager().addUser(remove_account.getId(), remove_account);
                    principalDb.remove(remove_account.getName());
                } finally {
View Full Code Here

                ((Group)remove_group).assertCanModifyGroup(subject);
   
                remove_group.setRemoved(true);
                remove_group.setCollection(broker, collectionRemovedGroups, XmldbURI.create(UUIDGenerator.getUUID() + ".xml"));
   
                final TransactionManager transaction = getDatabase().getTransactionManager();
                Txn txn = null;
                try {
                    txn = transaction.beginTransaction();

                    collectionGroups.removeXMLResource(txn, broker, XmldbURI.create(remove_group.getName() + ".xml" ));

                    transaction.commit(txn);
                } catch (final Exception e) {
                    transaction.abort(txn);
                    LOG.debug(e);
                } finally {
                    transaction.close(txn);
                }

                getSecurityManager().addGroup(remove_group.getId(), (Group)remove_group);
                principalDb.remove(remove_group.getName());
            }
View Full Code Here

//      groups = new Int2ObjectHashMap<Group>(65);
//      users = new Int2ObjectHashMap<User>(65);

      this.pool = pool;
     
        final TransactionManager transaction = pool.getTransactionManager();
        Txn txn = null;
   
        Collection systemCollection = null;
        try {
          systemCollection = broker.getCollection(XmldbURI.SYSTEM_COLLECTION_URI);
                if(systemCollection == null) {
                    txn = transaction.beginTransaction();
                    systemCollection = broker.getOrCreateCollection(txn, XmldbURI.SYSTEM_COLLECTION_URI);
                    if (systemCollection == null)
                            {return;}
                    systemCollection.setPermissions(Permission.DEFAULT_SYSTEM_COLLECTION_PERM);
                    broker.saveCollection(txn, systemCollection);

                    transaction.commit(txn);
                }
        } catch (final Exception e) {
            transaction.abort(txn);
            e.printStackTrace();
            LOG.debug("loading acl failed: " + e.getMessage());
        } finally {
            transaction.close(txn);
        }

        try {
            collection = broker.getCollection(SECURITY_COLLECTION_URI);
            if (collection == null) {
                txn = transaction.beginTransaction();
                collection = broker.getOrCreateCollection(txn, SECURITY_COLLECTION_URI);
                if (collection == null){
                    return;
                }
                //if db corrupted it can lead to unrunnable issue
                //throw new ConfigurationException("Collection '/db/system/security' can't be created.");

                collection.setPermissions(Permission.DEFAULT_SYSTEM_SECURITY_COLLECTION_PERM);
                broker.saveCollection(txn, collection);

                transaction.commit(txn);
            }
        } catch (final Exception e) {
            transaction.abort(txn);
            e.printStackTrace();
            LOG.debug("loading configuration failed: " + e.getMessage());
        } finally {
            transaction.close(txn);
        }
     
        final Configuration _config_ = Configurator.parse(this, broker, collection, CONFIG_FILE_URI);
        configuration = Configurator.configure(this, _config_);
View Full Code Here

        @Override
        public void apply() {
            try {
              getTarget().getLock().acquire(Lock.WRITE_LOCK);

                final TransactionManager txnManager = broker.getDatabase().getTransactionManager();
                final Txn txn = txnManager.beginTransaction();
              try {
                    final Permission permission = getTarget().getPermissions();
                  permission.setOwner(getOwner());
                  permission.setGroup(getGroup());
                  permission.setMode(getMode());
                  if(permission instanceof ACLPermission) {
                      final ACLPermission aclPermission = (ACLPermission)permission;
                      aclPermission.clear();
                      for(final ACEAider ace : getAces()) {
                          aclPermission.addACE(ace.getAccessType(), ace.getTarget(), ace.getWho(), ace.getMode());
                      }
                  }
                  broker.saveCollection(txn, getTarget());
                 
                  txnManager.commit(txn);
               
              } catch (final Exception xe) {
                  txnManager.abort(txn);
                 
                  throw xe;

              } finally {
                    txnManager.close(txn);
                  getTarget().release(Lock.WRITE_LOCK);
                }
               
            } catch (final Exception xe) {
                final String msg = "ERROR: Failed to set permissions on Collection '" + getTarget().getURI() + "'.";
View Full Code Here

        @Override
        public void apply() {
            try {
              getTarget().getUpdateLock().acquire(Lock.WRITE_LOCK);

              final TransactionManager txnManager = broker.getDatabase().getTransactionManager();
                final Txn txn = txnManager.beginTransaction();

              try {
               
                final Permission permission = getTarget().getPermissions();
                  permission.setOwner(getOwner());
                  permission.setGroup(getGroup());
                  permission.setMode(getMode());
                  if(permission instanceof ACLPermission) {
                      final ACLPermission aclPermission = (ACLPermission)permission;
                      aclPermission.clear();
                      for(final ACEAider ace : getAces()) {
                          aclPermission.addACE(ace.getAccessType(), ace.getTarget(), ace.getWho(), ace.getMode());
                      }
                  }
                  broker.storeXMLResource(txn, getTarget());
                  txnManager.commit(txn);
               
              } catch(final Exception xe) {
                txnManager.abort(txn);
               
                throw xe;
               
              } finally {
                    txnManager.close(txn);
                  getTarget().getUpdateLock().release(Lock.WRITE_LOCK);
              }
           
            } catch (final Exception xe) {
                final String msg = "ERROR: Failed to set permissions on Document '" + getTarget().getURI() + "'.";
View Full Code Here

    /**
     * @see org.w3c.dom.Node#appendChild(org.w3c.dom.Node)
     */
    @Override
    public Node appendChild(Node child) throws DOMException {
        final TransactionManager transact = ownerDocument.getBrokerPool().getTransactionManager();
        final Txn transaction = transact.beginTransaction();
        final NodeListImpl nl = new NodeListImpl();
        nl.add(child);
        DBBroker broker = null;
        try {
            broker = ownerDocument.getBrokerPool().get(null);
            appendChildren(transaction, nl, 0);
            broker.storeXMLResource(transaction, (DocumentImpl) getOwnerDocument());
            transact.commit(transaction); // bugID 3419602
            return getLastChild();
        } catch (final Exception e) {
            transact.abort(transaction);
            throw new DOMException(DOMException.INVALID_STATE_ERR, e.getMessage());
        } finally {
          if (broker != null) {
            try {
              transact.close(transaction);
            } finally {
              broker.release();
            }
          }
        }
View Full Code Here

            {return appendChild(newChild);}
        if (!(refChild instanceof StoredNode))
            {throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "Wrong node type");}
        final NodeListImpl nl = new NodeListImpl();
        nl.add(newChild);
        final TransactionManager transact = ownerDocument.getBrokerPool().getTransactionManager();
        final Txn transaction = transact.beginTransaction();
        DBBroker broker = null;
        try {
            broker = ownerDocument.getBrokerPool().get(null);
            insertBefore(transaction, nl, refChild);
            broker.storeXMLResource(transaction, (DocumentImpl) getOwnerDocument());
            transact.commit(transaction);
            return refChild.getPreviousSibling();
        } catch(final TransactionException e) {
            transact.abort(transaction);
            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, e.getMessage());
        } catch (final EXistException e) {
            transact.abort(transaction);
            LOG.warn("Exception while inserting node: " + e.getMessage(), e);
        } finally {
          if (broker != null) {
          try {
            transact.close(transaction);
          } finally {
            broker.release();
          }
          }
        }
View Full Code Here

                targetCollection = XmldbURI.create(getTargetCollection(targetPath));
            } catch (final Exception e) {
                throw new PackageException("Bad collection URI for <target> element: " + targetPath);
            }
        }
        final TransactionManager mgr = broker.getBrokerPool().getTransactionManager();
        final Txn txn = mgr.beginTransaction();
        try {
            Collection collection = broker.getOrCreateCollection(txn, targetCollection);
            if (collection != null)
                {broker.removeCollection(txn, collection);}
            if (target != null) {
                final XmldbURI configCollection = XmldbURI.CONFIG_COLLECTION_URI.append(targetCollection);
                collection = broker.getOrCreateCollection(txn, configCollection);
                if (collection != null)
                    {broker.removeCollection(txn, collection);}
            }
            mgr.commit(txn);
        } catch (final Exception e) {
            LOG.error("Exception occurred while removing package.", e);
            mgr.abort(txn);
        } finally {
            mgr.close(txn);
        }
    }
View Full Code Here

            throw new PackageException("Error while updating repo.xml: " + e.getMessage());
        }
        builder.endDocument();
        final DocumentImpl updatedXML = builder.getDocument();

        final TransactionManager mgr = broker.getBrokerPool().getTransactionManager();
        final Txn txn = mgr.beginTransaction();
        try {
            final Collection collection = broker.getOrCreateCollection(txn, targetCollection);
            final XmldbURI name = XmldbURI.createInternal("repo.xml");
            final IndexInfo info = collection.validateXMLResource(txn, broker, name, updatedXML);
            final Permission permission = info.getDocument().getPermissions();
            setPermissions(false, MimeType.XML_TYPE, permission);

            collection.store(txn, broker, info, updatedXML, false);

            mgr.commit(txn);
        } catch (final Exception e) {
            mgr.abort(txn);
        } finally {
            mgr.close(txn);
        }
    }
View Full Code Here

TOP

Related Classes of org.exist.storage.txn.TransactionManager

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.