Package com.dbxml.db.core.transaction

Examples of com.dbxml.db.core.transaction.Transaction


           tx.commit();
    }
   }

   Content getContent(String path, boolean create) throws DBException {
      Transaction tx = new Transaction();
      try {
         XMLSerializableAdapter col = getContentCollection();
         Content c = (Content)col.getObject(tx, path);
         if ( c == null && create ) {
            c = new Content(path);
            storeContent(c);
         }
         return c;
      }
      catch ( DBException e ) {
         tx.cancel();
         throw e;
      }
    finally {
       if ( tx.getStatus() == Transaction.ACTIVE )
           tx.commit();
    }
   }
View Full Code Here


        tx.commit();
    }
   }

   public String[] listUsersForRole(String roleID) throws DBException {
      Transaction tx = new Transaction();
      try {
         XMLSerializableAdapter col = getUsersCollection();
         String queryString = "/user[role[.='"+roleID+"']]/@id";
         ResultSet rs = col.queryCollection(tx, XPathQueryResolver.STYLE_XPATH, queryString, null);
         Set roles = new TreeSet();
         while ( rs.next() ) {
            try {
               String userID = DTSMHelper.tableToText(rs.getResult());
               roles.add(userID);
            }
            catch ( DTSMException e ) {
               // Should never happen
            }
         }
      return (String[])roles.toArray(EmptyStrings);
      }
      catch ( DBException e ) {
         tx.cancel();
         throw e;
      }
    finally {
      if ( tx.getStatus() == Transaction.ACTIVE )
        tx.commit();
    }
   }
View Full Code Here

        tx.commit();
    }
   }

   public Role readRole(String roleID) throws InvalidRoleException {
      Transaction tx = new Transaction();
      try {
      XMLSerializableAdapter col = getRolesCollection();
         Role role = (Role)roleCache.get(roleID);
      if ( role != null ) {
        // Perform access check for cached items
        checkAccess(col, Access.READ);
      }
      else {
            role = (Role)col.getObject(tx, roleID);
        if ( role != null )
              roleCache.put(roleID, role);
        else
             throw new InvalidUserException("Role '"+roleID+"' doesn't exist");
         }
         return role;
      }
      catch ( DBException e ) {
         try {
            tx.cancel();
         }
         catch ( DBException ex ) {
            ex.printStackTrace(System.err);
         }
         throw new InvalidRoleException("Unknown Role '"+roleID+"'", e);
      }
    finally {
      if ( tx.getStatus() == Transaction.ACTIVE ) {
        try {
          tx.commit();
        }
        catch ( DBException e ) {
          e.printStackTrace(System.err);
        }
      }
View Full Code Here

      }
    }
   }

   public void storeRole(Role role) throws DBException {
      Transaction tx = new Transaction();
      try {
         XMLSerializableAdapter col = getRolesCollection();
         String roleID = role.getId();
         col.setObject(tx, roleID, role);
         roleCache.put(roleID, role);
      }
      catch ( DBException e ) {
         tx.cancel();
         throw e;
      }
    finally {
      if ( tx.getStatus() == Transaction.ACTIVE )
        tx.commit();
    }
   }
View Full Code Here

        tx.commit();
    }
   }

   public void removeRole(Role role) throws DBException {
      Transaction tx = new Transaction();
      try {
      String roleID = role.getId();

         XMLSerializableAdapter col = getRolesCollection();
         col.remove(tx, roleID);
         roleCache.remove(roleID);

         col = getUsersCollection();
         String queryString = "/user[role[.='"+roleID+"']]/@id";
         ResultSet rs = col.queryCollection(tx, XPathQueryResolver.STYLE_XPATH, queryString, null);
         while ( rs.next() ) {
            try {
               String userID = DTSMHelper.tableToText(rs.getResult());
               User user = readUser(userID);
               user.removeRole(role);
               storeUser(user);
            }
            catch ( DTSMException e ) {
               // Should never happen
            }
         }

         col = getAccessCollection();
         queryString = "/access[role[.='"+roleID+"']]/path/text()";
         rs = col.queryCollection(tx, XPathQueryResolver.STYLE_XPATH, queryString, null);
         while ( rs.next() ) {
            try {
               String path = DTSMHelper.tableToText(rs.getResult());
               Access access = readAccess(path);
               access.removePermissions(role);
               storeAccess(access);
            }
            catch ( DTSMException e ) {
            }
         }
      }
      catch ( DBException e ) {
         tx.cancel();
         throw e;
      }
    finally {
      if ( tx.getStatus() == Transaction.ACTIVE )
        tx.commit();
    }
   }
View Full Code Here

        tx.commit();
    }
   }

   public String[] listPaths() throws DBException {
      Transaction tx = new Transaction();
      try {
         XMLSerializableAdapter col = getAccessCollection();
      Key[] keys = col.listKeys(tx);
      String[] result = new String[keys.length];
      for ( int i = 0; i < keys.length; i++ )
        result[i] = keys[i].toString();
         return result;
      }
      catch ( DBException e ) {
         tx.cancel();
         throw e;
      }
    finally {
      if ( tx.getStatus() == Transaction.ACTIVE )
        tx.commit();
    }
   }
View Full Code Here

        tx.commit();
    }
   }

   public Access readAccess(String path) throws InvalidAccessException {
      Transaction tx = new Transaction();
      try {
         XMLSerializableAdapter col = getAccessCollection();
         Access access = (Access)accessCache.get(path);
      if ( access != null ) {
        // Perform access check for cached items
        checkAccess(col, Access.READ);
      }
      else {
            access = (Access)col.getObject(tx, path);
        if ( access == null ) {
          access = new Access();
          access.setPath(path);
        }
            accessCache.put(path, access);
         }
         return access;
      }
      catch ( DBException e ) {
         try {
            tx.cancel();
         }
         catch ( DBException ex ) {
            ex.printStackTrace(System.err);
         }
         throw new InvalidAccessException("Can't retrieve Access list for '"+path+"'", e);
      }
    finally {
      if ( tx.getStatus() == Transaction.ACTIVE ) {
        try {
          tx.commit();
        }
        catch ( DBException e ) {
          e.printStackTrace(System.err);
        }
      }
View Full Code Here

      }
    }
   }

   public void storeAccess(Access access) throws DBException {
      Transaction tx = new Transaction();
      try {
         XMLSerializableAdapter col = getAccessCollection();
         String path = access.getPath();
         col.setObject(tx, path, access);
         accessCache.put(path, access);
      }
      catch ( DBException e ) {
         tx.cancel();
         throw e;
      }
    finally {
      if ( tx.getStatus() == Transaction.ACTIVE )
        tx.commit();
    }
   }
View Full Code Here

        tx.commit();
    }
   }

   public void removeAccess(String path) throws DBException {
      Transaction tx = new Transaction();
      try {
         XMLSerializableAdapter col = getAccessCollection();
         col.remove(tx, path);
         accessCache.remove(path);
      }
      catch ( DBException e ) {
         tx.cancel();
         throw e;
      }
    finally {
      if ( tx.getStatus() == Transaction.ACTIVE )
        tx.commit();
    }
   }
View Full Code Here

   }

   @Override
   public boolean open() throws DBException {
      if ( super.open() ) {
         Transaction tx = new Transaction();
         try {
            long p = fileHeader.getRootPage();
            rootInfo = new BTreeRootInfo(p);
            rootNode = getBTreeNode(tx, rootInfo, p, null);
            tx.commit();
            return true;
         }
         catch ( DBException e ) {
            tx.cancel();
            throw e;
         }
      }
      else
         return false;
View Full Code Here

TOP

Related Classes of com.dbxml.db.core.transaction.Transaction

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.