Package com.dbxml.db.core.transaction

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


   private void checkLoaded() {
      if ( loaded )
         return;

      Transaction tx = new Transaction();
      try {
         sysObj = collection.getSystemCollection().getCollection(SystemCollection.OBJECTS);
         docKey = PREFIX + collection.getCanonicalName();
         doc = (Document)sysObj.getDocument(tx, docKey);
         if ( doc != null ) {
            Element e = doc.getDocumentElement();
            NodeList nl = e.getElementsByTagName(SEQUENCE);
            for ( int i = 0; i < nl.getLength(); i++ ) {
               Element elem = (Element)nl.item(i);
               String name = elem.getAttribute(NAME);
               long val = Long.parseLong(elem.getAttribute(VALUE));
               values.put(name, new SequenceValue(elem, val));
            }
         }
         else {
            doc = DOMHelper.newDocument();
            doc.appendChild(doc.createElement(SEQUENCES));
         }
         loaded = true;
      }
      catch ( Exception e ) {
         try {
             tx.cancel();
         }
         catch ( DBException ex ) {
            e.printStackTrace(System.err);
         }
      }
    finally {
      if ( tx.getStatus() == Transaction.ACTIVE ) {
        try {
           tx.commit();
        }
        catch ( DBException e ) {
          e.printStackTrace(System.err);
        }
      }
View Full Code Here


      checkLoaded();
      return (String[])values.keySet().toArray(EmptyStrings);
   }

   private void write() {
      Transaction tx = new Transaction();
      try {
         DocumentTable dt = DTSMHelper.documentToTable(doc, sysObj.getSymbols());
         sysObj.setDocument(tx, docKey, dt);
      }
      catch ( Exception e ) {
         try {
             tx.cancel();
         }
         catch ( DBException ex ) {
            e.printStackTrace(System.err);
         }
      }
    finally {
      if ( tx.getStatus() == Transaction.ACTIVE ) {
        try {
           tx.commit();
        }
        catch ( DBException e ) {
          e.printStackTrace(System.err);
        }
      }
View Full Code Here

      else
         throw new dbXMLException("Collection '" + path + "' not found");
   }

   public ContentClient getContent(String path) throws dbXMLException {
      Transaction tx = new Transaction();
      try {
         int idx = path.lastIndexOf('/');
         if ( idx != -1 ) {
            String docName = path.substring(idx + 1);
            path = path.substring(0, idx);
            Collection col = getAbsoluteCollection(path);
            if ( col != null ) {
               Container con = col.getContainer(tx, docName);
               if ( con != null )
                  return new ContentClientImpl(new CollectionClientImpl(this, col), con);
               else
                  throw new dbXMLException("Document '" + docName + "' not found");
            }
            else
               throw new dbXMLException("Collection '" + path + "' not found");
         }
         else
            throw new dbXMLException("Invalid Document Path '" + path + "'");
      }
      catch ( dbXMLException e ) {
         tx.cancel();
         throw e;
      }
    finally {
      if ( tx.getStatus() == Transaction.ACTIVE )
        tx.commit();
    }
   }
View Full Code Here

         }
      }
      catch ( DBException e ) {
      }

      Transaction tx = new Transaction();
      try {
         Element docsElem = doc.createElement(DOCUMENTS);
         rootElem.appendChild(docsElem);
         Key[] keys = col.listKeys(tx);
         for ( int i = 0; i < keys.length; i++ ) {
            Element docElem = doc.createElement(DOCUMENT);
            docElem.appendChild(doc.createTextNode(keys[i].toString()));
            docsElem.appendChild(docElem);
         }
      }
      catch ( DBException e ) {
         try {
            tx.cancel();
         }
         catch ( DBException ex ) {
         }
      }
      finally {
         if ( tx.getStatus() == Transaction.ACTIVE )
            tx.commit();
      }

      return doc;
   }
View Full Code Here

   public static final String[] PARAMS_getDocument = {"docKey"};
   public static final String REST_CONTENT_TYPE_getDocument = Headers.TYPE_TEXT_XML;

   public String getDocument(String docKey) throws DBException {
      Transaction tx = new Transaction();
      try {
         DocumentTable dt = col.getDocument(tx, docKey);
         if ( dt == null )
            throw new DBException(FaultCodes.COL_CANNOT_RETRIEVE, "Document '"+docKey+"' not found");

         return DTSMHelper.tableToText(dt);
      }
      catch ( DBException e ) {
         tx.cancel();
         throw e;
      }
      catch ( DTSMException e ) {
         tx.cancel();
         throw new DBException(FaultCodes.COL_CANNOT_RETRIEVE, "Can't convert Document '" + docKey + "' to text", e);
      }
      finally {
         if ( tx.getStatus() == Transaction.ACTIVE )
            tx.commit();
      }
   }
View Full Code Here

   }

   public static final String[] PARAMS_insertDocument = {"document"};

   public String insertDocument(String document) throws DBException {
      Transaction tx = new Transaction();
      try {
         DocumentTable doc = DTSMHelper.textToTable(document, col.getSymbols());
         return col.insertDocument(tx, doc).toString();
      }
      catch ( DBException e ) {
         tx.cancel();
         throw e;
      }
      catch ( DTSMException e ) {
         tx.cancel();
         throw new DBException(FaultCodes.COL_CANNOT_STORE, "Can't parse Document", e);
      }
      finally {
         if ( tx.getStatus() == Transaction.ACTIVE )
            tx.commit();
      }
   }
View Full Code Here

   }

   public static final String[] PARAMS_setDocument = {"docKey", "document"};

   public void setDocument(String docKey, String document) throws DBException {
      Transaction tx = new Transaction();
      try {
         DocumentTable dt = DTSMHelper.textToTable(document, col.getSymbols());
         col.setDocument(tx, docKey, dt);
         tx.commit();
      }
      catch ( DBException e ) {
         tx.cancel();
         throw e;
      }
      catch ( DTSMException e ) {
         tx.cancel();
         throw new DBException(FaultCodes.COL_CANNOT_STORE, "Can't parse Document '" + docKey + "'", e);
      }
      finally {
         if ( tx.getStatus() == Transaction.ACTIVE )
            tx.commit();
      }
   }
View Full Code Here

   }

   public static final String[] PARAMS_remove = {"docKey"};

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

            tx.commit();
      }
   }

   public String[] listKeys() throws DBException {
      Transaction tx = new Transaction();
      try {
         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 long getKeyCount() throws DBException {
      Transaction tx = new Transaction();
      try {
         return col.getKeyCount(tx);
      }
      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.