Search in sources :

Example 1 with DocumentWriteAccessException

use of org.openntf.domino.exceptions.DocumentWriteAccessException in project org.openntf.domino by OpenNTF.

the class Document method save.

/*
	 * (non-Javadoc)
	 *
	 * @see org.openntf.domino.Document#save(boolean, boolean, boolean)
	 */
@Override
public boolean save(final boolean force, final boolean makeResponse, final boolean markRead) {
    // System.out.println("Starting save operation on " + this.getMetaversalID() + ". isNew: " + String.valueOf(isNewNote()));
    // Throwable t = new Throwable();
    // t.printStackTrace();
    // checkMimeOpen();
    // System.out.println("TEMP DEBUG Starting save operation on " + unid_ + " in " + this.getAncestorDatabase().getApiPath() + " as user "
    // + this.getAncestorSession().getCommonUserName());
    boolean result = false;
    if (removeType_ != null) {
        log_.log(Level.INFO, "Save called on a document marked for a transactional delete. So there's no point...");
        return true;
    }
    // START SPECIAL DEBUG SECTION FOR NTF IN GRAPH2 ENGINE
    if (getAncestorDatabase().getFileName().equalsIgnoreCase("factproxy.nsf")) {
        if (getItemValueString("form").equalsIgnoreCase("vertexframe")) {
            Throwable t = new Throwable();
            writeStackTraceToItem("stackTrace", t);
        } else if (Strings.isBlankString(getItemValueString("$$key")) || getItemValueString("$$key").length() < 48) {
            Throwable t = new Throwable();
            writeStackTraceToItem("stackTrace", t);
        }
    }
    if (isNewNote() || isDirty()) {
        boolean go = true;
        Database db = getAncestorDatabase();
        go = !db.hasListeners() ? true : db.fireListener(generateEvent(Events.BEFORE_UPDATE_DOCUMENT, null));
        if (go) {
            writeItemInfo();
            // fieldNames_ = null;
            isNew_ = false;
            try {
                lotus.domino.Document del = getDelegate();
                if (del != null) {
                    result = del.save(force, makeResponse, markRead);
                    // complex cases are not needed unless you want to log
                    // if (noteid_ == null || !noteid_.equals(del.getNoteID())) {
                    // // System.out.println("Resetting note id from " + noteid_ + " to " + del.getNoteID());
                    // noteid_ = del.getNoteID();
                    // }
                    // if (unid_ == null || !unid_.equals(del.getUniversalID())) {
                    // // System.out.println("Resetting unid from " + unid_ + " to " + del.getUniversalID());
                    // unid_ = del.getUniversalID();
                    // }
                    // so we can do that in every case
                    noteid_ = del.getNoteID();
                    unid_ = del.getUniversalID();
                    // don't set to true, save may fail!
                    isNew_ = noteid_.equals("0") || noteid_.isEmpty();
                    invalidateCaches();
                } else {
                    log_.severe("Delegate document for " + unid_ + " is NULL!??!");
                }
            } catch (NotesException e) {
                // e.printStackTrace();
                if (e.text.contains("Database already contains a document with this ID")) {
                    // Throwable t = new RuntimeException();
                    String newunid = DominoUtils.toUnid(new Date().getTime());
                    String message = "Unable to save a document with id " + getUniversalID() + " because that id already exists. Saving a " + this.getFormName() + (this.hasItem("$$Key") ? " (key: '" + getItemValueString("$$Key") + "')" : "") + " to a different unid instead: " + newunid;
                    setUniversalID(newunid);
                    try {
                        getDelegate().save(force, makeResponse, markRead);
                        noteid_ = getDelegate().getNoteID();
                        isNew_ = noteid_.equals("0") || noteid_.isEmpty();
                        System.out.println(message);
                        log_.log(Level.WARNING, message);
                    } catch (NotesException ne) {
                        log_.log(Level.SEVERE, "Okay, now it's time to really panic. Sorry...");
                        DominoUtils.handleException(e, this);
                    }
                } else if (e.text.contains("You are not authorized")) {
                    throw new DocumentWriteAccessException(this);
                } else {
                    DominoUtils.handleException(e, this);
                }
            }
            if (result) {
                clearDirty();
                getAncestorDatabase().fireListener(generateEvent(Events.AFTER_UPDATE_DOCUMENT, null));
            }
        } else {
            // System.out.println("Before Update listener blocked save.");
            if (log_.isLoggable(Level.FINE)) {
                log_.log(Level.FINE, "Document " + getNoteID() + " was not saved because the DatabaseListener for update returned false.");
            }
            result = false;
        }
    } else {
        // System.out.println("No changes occured therefore not saving.");
        if (log_.isLoggable(Level.FINE)) {
            log_.log(Level.FINE, "Document " + getNoteID() + " was not saved because nothing on it was changed.");
        }
        // because nothing changed, we don't want to activate any potential failure behavior in the caller
        result = true;
    }
    return result;
}
Also used : OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) NotesException(lotus.domino.NotesException) Database(org.openntf.domino.Database) DocumentWriteAccessException(org.openntf.domino.exceptions.DocumentWriteAccessException) Date(java.util.Date)

Example 2 with DocumentWriteAccessException

use of org.openntf.domino.exceptions.DocumentWriteAccessException in project org.openntf.domino by OpenNTF.

the class DGraph method commit.

@Override
public void commit() {
    GraphTransaction txn = localTxn.get();
    if (txn != null) {
        Iterator<Element> it = txn.iterator();
        int count = 0;
        while (it.hasNext()) {
            Element elem = it.next();
            if (elem instanceof DElement) {
                DElement delem = (DElement) elem;
                try {
                    delem.applyChanges();
                // delem.uncache();
                } catch (DocumentWriteAccessException t) {
                    System.err.println(t.getMessage());
                } catch (Throwable t) {
                    t.printStackTrace();
                }
                // DElementStore store = findElementStore(elem.getId());
                // store.uncache(delem);
                count++;
            }
            it.remove();
        }
    // System.out.println("TEMP DEBUG: Transaction committed changes to " + count + " elements");
    }
    localTxn.set(null);
}
Also used : Element(com.tinkerpop.blueprints.Element) DocumentWriteAccessException(org.openntf.domino.exceptions.DocumentWriteAccessException)

Example 3 with DocumentWriteAccessException

use of org.openntf.domino.exceptions.DocumentWriteAccessException in project org.openntf.domino by OpenNTF.

the class DGraph method rollback.

@Override
public void rollback() {
    GraphTransaction txn = localTxn.get();
    if (txn != null) {
        Iterator<Element> it = txn.iterator();
        int count = 0;
        while (it.hasNext()) {
            Element elem = it.next();
            if (elem instanceof DElement) {
                DElement delem = (DElement) elem;
                try {
                    delem.uncache();
                } catch (DocumentWriteAccessException t) {
                    System.err.println(t.getMessage());
                } catch (Throwable t) {
                    t.printStackTrace();
                }
                count++;
            }
            it.remove();
        }
    }
    localTxn.set(null);
}
Also used : Element(com.tinkerpop.blueprints.Element) DocumentWriteAccessException(org.openntf.domino.exceptions.DocumentWriteAccessException)

Aggregations

DocumentWriteAccessException (org.openntf.domino.exceptions.DocumentWriteAccessException)3 Element (com.tinkerpop.blueprints.Element)2 Date (java.util.Date)1 NotesException (lotus.domino.NotesException)1 Database (org.openntf.domino.Database)1 OpenNTFNotesException (org.openntf.domino.exceptions.OpenNTFNotesException)1