Package org.openntf.domino.transactions

Examples of org.openntf.domino.transactions.DatabaseTransaction


  public static void transactionTest(boolean successOrFail) {
    StringBuilder sb = new StringBuilder();
    Database db = Factory.getSession().getCurrentDatabase();
    Utils.addAllListeners(db);
    DatabaseTransaction txn = db.startTransaction();
    try {
      String selVal = (String) ExtLibUtil.getViewScope().get("selectedState");
      boolean toggle = true;
      int count = 0;
      if ("".equals(selVal)) {
        ExtLibUtil.getViewScope().put("javaTest", "First select a value");
        return;
      }
      sb.append("Starting update with " + selVal);
      View view = db.getView("allStates");
      Document state = view.getFirstDocumentByKey(selVal, true);
      state.replaceItemValue("txnTest", new Date());
      sb.append("...Updated State pending committal, value is " + state.get("txnTest").toString());
      View contacts = db.getView("AllContactsByState");
      DocumentCollection dc = contacts.getAllDocumentsByKey(selVal, true);
      for (Document doc : dc) {
        if (toggle) {
          doc.replaceItemValue("txnTest", new Date());
          count += 1;
        }
        toggle = !toggle;
      }
      sb.append("...Updated " + Integer.toString(count) + " Contacts pending committal.");
      if (successOrFail) {
        txn.commit();
        sb.append("...Committed");
        ExtLibUtil.getViewScope().put("javaTest", sb.toString());
      } else {
        throw new Exception("Now roll back");
      }
    } catch (Exception e) {
      sb.append("Rolling back");
      txn.rollback();
      ExtLibUtil.getViewScope().put("javaTest", sb.toString());
    }
  }
View Full Code Here


  };

  @Override
  public DatabaseTransaction startTransaction() {
    if (txnHolder_.get() == null) {
      DatabaseTransaction txn = new DatabaseTransaction(this);
      //      System.out.println("******START Creating a new DatabaseTransaction for " + getApiPath());
      //      Throwable t = new Throwable();
      //      t.printStackTrace();
      //      System.out.println("******DONE Creating a new DatabaseTransaction for " + getApiPath());
      //      if (!getFilePath().toLowerCase().contains("graph.nsf") || getServer().contains("Shiva")) {
View Full Code Here

  }

  protected void markDirtyInt() {
    isDirty_ = true;
    if (!isQueued_) {
      DatabaseTransaction txn = getParentDatabase().getTransaction();
      if (txn != null) {
        txn.queueUpdate(this);
        isQueued_ = true;
      }
    }
  }
View Full Code Here

  }

  private boolean queueRemove() {
    if (!isRemoveQueued_) {
      DatabaseTransaction txn = getParentDatabase().getTransaction();
      if (txn != null) {
        //        System.out.println("DEBUG: Found a transaction: " + txn + " from parent Database " + getParentDatabase().getApiPath());
        txn.queueRemove(this);
        isRemoveQueued_ = true;
        return true; // we queued this, so whoever asked shouldn't do it yet.
      } else {
        return false; // calling function should just go ahead and execute
      }
View Full Code Here

    return txnHolder_.get();
  }

  @Override
  public void setTransaction(final DatabaseTransaction txn) {
    DatabaseTransaction current = txnHolder_.get();
    if (current == null) {
      txnHolder_.set(txn);
    } else {
      if (!current.equals(txn)) {
        throw new TransactionAlreadySetException(getServer().length() == 0 ? getFilePath() : (getServer() + "!!" + getFilePath()));
      }
    }
  }
View Full Code Here

    // TODO Auto-generated method stub

  }

  public void commit(final boolean clearCache) {
    DatabaseTransaction txn = getTxn();
    if (txn != null) {
      if (getCache().size() > 0) {
        // System.out.println("Reapplying cache to " + getCache().size() + " elements...");
        int vCount = 0;
        Set<Element> elems = getCacheValues();
        for (Element elem : elems) {
          if (elem instanceof DominoElement) {
            ((DominoElement) elem).reapplyChanges();
          }
        }
      } else {
        // System.out.println("Element cache is empty (so what are we committing?)");
      }
      txn.commit();
      //      setTxn(null);
    }
    if (clearCache)
      clearCache();
    // System.out.println("Transaction complete");
View Full Code Here

   *
   * @see com.tinkerpop.blueprints.TransactionalGraph#rollback()
   */
  @Override
  public void rollback() {
    DatabaseTransaction txn = getTxn();
    if (txn != null) {
      txn.rollback();
      //      setTxn(null);
    }
    clearCache();
    // System.out.println("Transaction rollbacked");
  }
View Full Code Here

    // TODO Check to make sure properties are all set up before running
    Session session = coll.getAncestorSession();
    Database targetDb = session.getDatabase(getTargetServer(), getTargetFilepath());
    View targetView = targetDb.getView(getTargetLookupView());
    Strategy strategy = getStrategy();
    DatabaseTransaction txn = null;
    if (getTransactionRule() == TransactionRule.COMMIT_AT_END) {
      txn = targetDb.startTransaction();
    }
    for (Document source : coll) {
      if (getTransactionRule() == TransactionRule.COMMIT_EVERY_SOURCE) {
        txn = targetDb.startTransaction();
      }
      DateTime sourceLastMod = source.getLastModified();
      // Object lookupKey = Factory.wrappedEvaluate(session, getSourceKeyFormula(), source);
      Object lookupKey = getSourceKeyFormula().getValue(source);
      DocumentCollection targetColl = targetView.getAllDocumentsByKey(lookupKey, true);
      for (Document target : targetColl) {
        // boolean targetDirty = false;
        for (Map.Entry<Formula, String> entry : getSyncMap().entrySet()) {
          String targetItemName = entry.getValue();
          java.util.Vector<?> sourceValue = entry.getKey().getValue(source);
          // Factory.wrappedEvaluate(session, entry.getKey(), source);
          if (strategy == Strategy.CREATE_AND_REPLACE) {
            target.replaceItemValue(targetItemName, sourceValue);
            // targetDirty = true;
          } else {
            Item targetItem = target.getFirstItem(targetItemName);
            if (strategy == Strategy.REPLACE_IF_NEWER) {
              DateTime itemLastMod = targetItem.getLastModified();
              if (sourceLastMod.isAfter(itemLastMod)) {
                targetItem.setValues(sourceValue);
                // targetDirty = true;
              }
            } else if (strategy == Strategy.REPLACE_ONLY) {
              if (targetItem != null) {
                targetItem.setValues(sourceValue);
                // targetDirty = true;
              }
            }
          }
        }
        if (getTransactionRule() == TransactionRule.NO_TRANSACTION || txn == null) {
          target.save();
        }
      }
      if (getTransactionRule() == TransactionRule.COMMIT_EVERY_SOURCE && txn != null) {
        txn.commit();
        txn = null;
      }
    }
    if (getTransactionRule() == TransactionRule.COMMIT_AT_END && txn != null) {
      txn.commit();
      txn = null;
    }
  }
View Full Code Here

TOP

Related Classes of org.openntf.domino.transactions.DatabaseTransaction

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.