Package com.dbxml.db.core.transaction

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


   }

   public static final String[] PARAMS_listGroupContents = {"group"};

   public String[] listGroupContents(String group) throws DBException {
      Transaction tx = new Transaction();
      try {
         XMLSerializableAdapter col = getContentCollection();
         ResultSet res = col.queryCollection(tx, XPathQueryResolver.STYLE_XPATH, "/content[@status='active']/groups/group[.='"+group+"']", EmptyNSMap);
         Set s = new TreeSet();
         while ( res.next() )
            s.add(res.getResultKey().toString());
      return (String[])s.toArray(EmptyStrings);
      }
      catch ( DBException e ) {
         tx.cancel();
         throw e;
      }
    finally {
       if ( tx.getStatus() == Transaction.ACTIVE )
           tx.commit();
    }
   }
View Full Code Here


   private void checkAccess(Adapter col, int permissions) throws SecurityException {
      database.getSecurityManager().access(col.getCanonicalName(), permissions);
   }

   public String[] listUsers() throws DBException {
      Transaction tx = new Transaction();
      try {
      XMLSerializableAdapter col = getUsersCollection();
      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

   }

   public static final String[] PARAMS_listGroupChanges = {"date", "groups"};

   public Document listGroupChanges(Date date, String[] groups) throws DBException {
      Transaction tx = new Transaction();

      try {
         Date start = new Date();

         Set grpSet = new HashSet();
         for ( int i = 0; groups != null && i < groups.length; i++ )
            grpSet.add(groups[i]);

         String d = new Variant(date).getString();
         StringBuffer sb = new StringBuffer(64);
         sb.append("/" + Constants.CONTENT + "[" + Constants.MODIFIED + " > '" + d + "'");
         if ( groups != null ) {
            sb.append(" and " + Constants.GROUPS + "/" + Constants.GROUP + "[");
            for ( int i = 0; i < groups.length; i++ ) {
               if ( i > 0 )
                  sb.append(" or ");
               sb.append(".='" + groups[i] + "'");
            }
            sb.append("]");
         }
         sb.append("]");

         XMLSerializableAdapter col = getContentCollection();
         ResultSet rs = col.queryCollection(tx, XPathQueryResolver.STYLE_XPATH, sb.toString(), null);
         Map grpMap = new HashMap(); // of String to List of Element

         while ( rs.next() ) {
            try {
               DocumentTable dt = rs.getResult();
               Element elem = (Element)DTSMHelper.tableToNode(dt);
               NodeList nl = elem.getElementsByTagName(Constants.GROUP);
               for ( int i = 0; i < nl.getLength(); i++ ) {
                  Element e = (Element)nl.item(i);
                  String grpName = DOMUtils.getText(e);
                  if ( groups != null && !grpSet.contains(grpName) )
                     continue;
                  List l = (List)grpMap.get(grpName);
                  if ( l == null ) {
                     l = new ArrayList();
                     grpMap.put(grpName, l);
                  }
                  l.add(elem);
               }
            }
            catch ( DTSMException e ) {
               throw new DBException(FaultCodes.GEN_GENERAL_ERROR, "Can't convert DocumentTable", e);
            }
         }

         Document doc = DOMHelper.newDocument();
         Element rootElem = doc.createElement(Constants.MANIFEST);
         rootElem.setAttribute(Constants.DATE, new Variant(start).getString());
         doc.appendChild(rootElem);

         Iterator iter = grpMap.keySet().iterator();
         while ( iter.hasNext() ) {
            String key = (String)iter.next();
            Group g = getGroup(key, true);
            Element groupElem = doc.createElement(Constants.GROUP);
            groupElem.setAttribute(Constants.NAME, key);
            groupElem.setAttribute(Constants.VERSION, Double.toString(g.getVersion()));
            groupElem.setAttribute(Constants.STATUS, Constants.getStatusString(g.getStatus()));
            rootElem.appendChild(groupElem);
            List l = (List)grpMap.get(key);
            Iterator i = l.iterator();
            while ( i.hasNext() ) {
               Node n = doc.importNode((Element)i.next(), true);
               groupElem.appendChild(n);
            }
         }

      return doc;
      }
      catch ( DBException e ) {
         tx.cancel();
         throw e;
      }
    finally {
       if ( tx.getStatus() == Transaction.ACTIVE )
           tx.commit();
    }
   }
View Full Code Here

        tx.commit();
    }
   }

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

   public Document listAllChanges(Date date) throws DBException {
      return listGroupChanges(date, null);
   }

   void storeGroup(Group group) throws DBException {
      Transaction tx = new Transaction();
      try {
         XMLSerializableAdapter col = getGroupsCollection();
         col.setObject(tx, group.getName(), group);
      }
      catch ( DBException e ) {
         tx.cancel();
         throw e;
      }
    finally {
       if ( tx.getStatus() == Transaction.ACTIVE )
           tx.commit();
    }
   }
View Full Code Here

           tx.commit();
    }
   }

   Group getGroup(String group, boolean create) throws DBException {
      Transaction tx = new Transaction();
      try {
         XMLSerializableAdapter col = getGroupsCollection();
         Group g = (Group)col.getObject(tx, group);
         if ( g == null && create ) {
            g = new Group(group);
            storeGroup(g);
         }
         return g;
      }
      catch ( DBException e ) {
         tx.cancel();
         throw e;
      }
    finally {
       if ( tx.getStatus() == Transaction.ACTIVE )
           tx.commit();
    }
   }
View Full Code Here

      }
    }
   }

   public void storeUser(User user) throws DBException {
      Transaction tx = new Transaction();
      try {
         XMLSerializableAdapter col = getUsersCollection();
         String userID = user.getId();
         col.setObject(tx, userID, user);
         userCache.put(userID, user);
      }
      catch ( DBException e ) {
         tx.cancel();
         throw e;
      }
    finally {
      if ( tx.getStatus() == Transaction.ACTIVE )
        tx.commit();
    }
   }
View Full Code Here

           tx.commit();
    }
   }

   void storeContent(Content content) throws DBException {
      Transaction tx = new Transaction();
      try {
         XMLSerializableAdapter col = getContentCollection();
         col.setObject(tx, content.getPath(), content);
      }
      catch ( DBException e ) {
         tx.cancel();
         throw e;
      }
    finally {
       if ( tx.getStatus() == Transaction.ACTIVE )
           tx.commit();
    }
   }
View Full Code Here

        tx.commit();
    }
   }

   public void removeUser(User user) throws DBException {
      Transaction tx = new Transaction();
      try {
         XMLSerializableAdapter col = getUsersCollection();
      String userID = user.getId();

         col.remove(tx, userID);
         userCache.remove(userID);
      }
      catch ( DBException e ) {
         tx.cancel();
         throw e;
      }
    finally {
      if ( tx.getStatus() == Transaction.ACTIVE )
        tx.commit();
    }
   }
View Full Code Here

        tx.commit();
    }
   }

   public String[] listRoles() throws DBException {
      Transaction tx = new Transaction();
      try {
         XMLSerializableAdapter col = getRolesCollection();
      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

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.