protected OrientTransactionalGraph(final ODatabaseDocumentInternal iDatabase, final String iUserName, final String iUserPasswd, final Settings iConfiguration) { super(iDatabase, iUserName, iUserPasswd, iConfiguration); setCurrentGraphInThreadLocal(); super.setAutoStartTx(isAutoStartTx()); if (isAutoStartTx()) ensureTransaction(); }
/** * Commits the current active transaction. */ public void commit() { makeActive(); if (getDatabase() == null) return; getDatabase().commit(); if (isAutoStartTx()) ensureTransaction(); }
/** * Rollbacks the current active transaction. All the pending changes are rollbacked. */ public void rollback() { makeActive(); if (getDatabase() == null) return; getDatabase().rollback(); if (isAutoStartTx()) ensureTransaction(); }
@Override public void begin() { makeActive(); // XXX: Under some circumstances, auto started transactions are committed outside of the graph using the // underlying database and later restarted using the graph. So we have to check the status of the // database transaction to support this behaviour. if (isAutoStartTx() && getDatabase().getTransaction().isActive()) throw new OTransactionException("A mixture of auto started and manually started transactions is not allowed. " + "Disable auto transactions for the graph before starting a manual transaction."); getDatabase().begin(); getDatabase().getTransaction().setUsingLog(settings.isUseLog()); }
@Override protected void autoStartTransaction() { final boolean txBegun = getDatabase().getTransaction().isActive(); if (!isAutoStartTx()) { if (isRequireTransaction() && !txBegun) throw new OTransactionException("Transaction required to change the Graph"); return; } if (!txBegun) { getDatabase().begin(); getDatabase().getTransaction().setUsingLog(settings.isUseLog()); } }
@Override public void setAutoStartTx(boolean autoStartTx) { makeActive(); final boolean showWarning; if (!autoStartTx && isAutoStartTx() && getDatabase() != null && getDatabase().getTransaction().isActive()) { if (getDatabase().getTransaction().getEntryCount() == 0) { getDatabase().getTransaction().rollback(); showWarning = false; } else showWarning = true; } else showWarning = false; super.setAutoStartTx(autoStartTx); if (showWarning) OLogManager.instance().warn(this, "Auto Transaction for graphs setting has been turned off, but a transaction was already started." + " Commit it manually or consider disabling auto transactions while creating the graph."); }