本文整理汇总了Java中org.eclipse.emf.transaction.RollbackException类的典型用法代码示例。如果您正苦于以下问题:Java RollbackException类的具体用法?Java RollbackException怎么用?Java RollbackException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RollbackException类属于org.eclipse.emf.transaction包,在下文中一共展示了RollbackException类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: commitCurrentTransaction
import org.eclipse.emf.transaction.RollbackException; //导入依赖的package包/类
private void commitCurrentTransaction() {
if (currentTransaction != null) {
try {
currentTransaction.commit();
} catch (RollbackException t) {
cleanCurrentTransactionCommand();
// Extracting the real error from the RollbackException
Throwable realT = t.getStatus().getException();
// And we put it inside our own sort of exception, as a cause
SequentialExecutionException enclosingException = new SequentialExecutionException(getCurrentMSEOccurrence(), realT);
enclosingException.initCause(realT);
throw enclosingException;
}
currentTransaction = null;
}
}
示例2: handleRollback
import org.eclipse.emf.transaction.RollbackException; //导入依赖的package包/类
private static RuntimeException handleRollback(RollbackException e) {
Logger logger = Logger.getLogger(TransactionUtils.class);
IStatus status = e.getStatus();
switch (status.getCode()) {
case IStatus.ERROR:
logger.error(status.getMessage(), status.getException());
break;
case IStatus.WARNING:
logger.warn(status.getMessage(), status.getException());
break;
case IStatus.INFO:
logger.info(status.getMessage(), status.getException());
break;
}
final Throwable exception = Option.fromNull(status.getException()).orSome(e);
if (exception instanceof RuntimeException)
return (RuntimeException) exception;
return new RuntimeException(exception);
}
示例3: handleRollback
import org.eclipse.emf.transaction.RollbackException; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.transaction.impl.TransactionalCommandStackImpl#handleRollback(org.eclipse.emf.common.command.Command,
* org.eclipse.emf.transaction.RollbackException)
*/
@Override
protected void handleRollback(Command command, RollbackException rbe) {
super.handleRollback(command, rbe);
Exception exception = null;
if (rbe != null) {
if (rbe.getCause() != null && rbe.getCause() instanceof Exception) {
exception = (Exception) rbe.getCause();
} else {
exception = rbe;
}
}
notifier.notifiyListenersAboutCommandFailed(command, exception);
if (currentCommand == command) {
currentCommand = null;
}
}
示例4: transactionAboutToCommit
import org.eclipse.emf.transaction.RollbackException; //导入依赖的package包/类
/**
* @see org.eclipse.emf.transaction.ResourceSetListener#transactionAboutToCommit(org.eclipse.emf.transaction.ResourceSetChangeEvent)
*/
@SuppressWarnings("unchecked")
public Command transactionAboutToCommit(ResourceSetChangeEvent event) throws RollbackException {
List notifications = event.getNotifications();
CompoundCommand compoundCommand = new CompoundCommand();
Set handledModels = new HashSet();
Notification notification = null;
EObject notifier = null;
for (Iterator i = notifications.iterator(); i.hasNext();) {
notification = (Notification) i.next();
if (notification.getNotifier() instanceof EObject && !handledModels.contains(notification)) {
notifier = (EObject) notification.getNotifier();
if (notifier.eClass() == UMLPackage.eINSTANCE.getModel()) {
final Model model = (Model) notifier;
String name = model.getName();
// Model should have some name
if (name == null || name.equals("")) { //$NON-NLS-1$
// We can use any EMF command here
compoundCommand.append(new SetCommand(event.getEditingDomain(),
model,
(EStructuralFeature) UMLPackage.eINSTANCE.getModel(),
"SomeName")); //$NON-NLS-1$
}
handledModels.add(model);
}
}
}
// It is important to return null if we have nothing to
// contribute to this transaction.
return compoundCommand.isEmpty() ? null : compoundCommand;
}
示例5: handleException
import org.eclipse.emf.transaction.RollbackException; //导入依赖的package包/类
/**
* Documentation copied from the inherited specification
*
* @see org.eclipse.emf.transaction.ExceptionHandler#handleException(java.lang.Exception)
*/
public void handleException(final Exception e) {
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
/**
* @see java.lang.Runnable#run()
*/
public void run() {
Shell shell = null;
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null) {
shell = window.getShell();
}
if (e instanceof RollbackException) {
RollbackException rbe = (RollbackException) e;
ErrorDialog.openError(shell,
UMLMessage.MESSAGE_COMMAND_FAILED,
UMLMessage.MESSAGE_COMMAND_ROLLBACK,
rbe.getStatus());
} else {
ErrorDialog.openError(shell,
UMLMessage.MESSAGE_COMMAND_FAILED,
UMLMessage.MESSAGE_COMMAND_ROLLBACK,
new Status(IStatus.ERROR,
UMLEditorPlugin.getPlugin().getSymbolicName(),
1,
e.getLocalizedMessage(),
e));
}
}
});
}
示例6: dispose
import org.eclipse.emf.transaction.RollbackException; //导入依赖的package包/类
public static void dispose(final EPlan ePlan) {
if (ePlan == null) {
return;
}
EPlanUtils.clearConsolidatedPlanElementsCache();
HibernateMember member = ePlan.getMember(HibernateMember.class, true);
final Plan wrapper = (Plan)member.getWrapper();
TransactionalEditingDomain domain = TransactionUtils.getDomain(ePlan);
if (wrapper != null) {
if (domain != null) {
domain.addResourceSetListener(new PreCommitListener() {
@Override
public Command transactionAboutToCommit(ResourceSetChangeEvent event)
throws RollbackException {
if (event.getNotifications().isEmpty()) {
return null;
}
LogUtil.error("event during disposal of plan: " + ePlan.getName());
throw new RollbackException(Status.CANCEL_STATUS);
}
});
}
if (wrapper != null) {
wrapper.dispose();
}
member.setWrapper(null);
}
Resource resource = ePlan.eResource();
if (domain != null) {
domain.dispose();
domain.getResourceSet().getResources().remove(resource);
}
if (resource != null) {
resource.getContents().remove(ePlan);
}
}
示例7: checkedWriting
import org.eclipse.emf.transaction.RollbackException; //导入依赖的package包/类
public static <T> T checkedWriting(Object object, final RunnableWithResult<T> runnable, Map<Object, Object> options) throws InterruptedException, RollbackException {
final EditingDomain domain = EMFUtils.getAnyDomain(object);
if (domain instanceof TransactionalEditingDomain) {
TransactionalEditingDomain transactionDomain = (TransactionalEditingDomain) domain;
checkForDeadlock(transactionDomain);
InternalTransaction transaction = ((TransactionalEditingDomainImpl) transactionDomain).getActiveTransaction();
if ((transaction != null) && (transaction.getOwner() == Thread.currentThread()) && !transaction.isReadOnly()) {
// nested writing
runnable.run();
return runnable.getResult();
}
TransactionalCommandStack stack = (TransactionalCommandStack) domain.getCommandStack();
if (stack != null) {
Map writingOptions = getWritingOptions(domain);
Map newOptions = new HashMap();
if (options != null) {
newOptions.putAll(options);
}
if (writingOptions != null) {
newOptions.putAll(writingOptions);
}
writingOptions = newOptions;
stack.execute(new RunnableRecordingCommand("writing", runnable), writingOptions);
} else {
runnable.run();
}
} else {
runnable.run();
}
return runnable.getResult();
}
示例8: transactionAboutToCommit
import org.eclipse.emf.transaction.RollbackException; //导入依赖的package包/类
/**
* @see org.eclipse.emf.transaction.ResourceSetListener#transactionAboutToCommit(org.eclipse.emf.transaction.ResourceSetChangeEvent)
*/
public Command transactionAboutToCommit(ResourceSetChangeEvent event) throws RollbackException {
// TODO Auto-generated method stub
return null;
}
示例9: transactionAboutToCommit
import org.eclipse.emf.transaction.RollbackException; //导入依赖的package包/类
public Command transactionAboutToCommit(ResourceSetChangeEvent event)
throws RollbackException {
return null;
}
示例10: transactionAboutToCommit
import org.eclipse.emf.transaction.RollbackException; //导入依赖的package包/类
@Override
public abstract Command transactionAboutToCommit(ResourceSetChangeEvent event) throws RollbackException;
示例11: runExclusive
import org.eclipse.emf.transaction.RollbackException; //导入依赖的package包/类
public static <T> T runExclusive(TransactionalEditingDomain d, Runnable read) throws InterruptedException {
InternalTransactionalEditingDomain domain = (InternalTransactionalEditingDomain) d;
Transaction active = domain.getActiveTransaction();
Transaction tx = null;
long start = -1;
if ((active == null) || !(active.isActive() && active.isReadOnly() && (active.getOwner() == Thread.currentThread()))) {
start = System.currentTimeMillis();
// only need to start a new transaction if we don't already have
// exclusive read-only access
tx = domain.startTransaction(true, getWritingOptions(domain));
}
final RunnableWithResult<?> rwr = (read instanceof RunnableWithResult) ? (RunnableWithResult<?>) read : null;
try {
read.run();
} finally {
if ((tx != null) && (tx.isActive())) {
// commit the transaction now
try {
tx.commit();
if (rwr != null) {
rwr.setStatus(Status.OK_STATUS);
}
} catch (RollbackException e) {
Tracing.catching(TransactionalEditingDomainImpl.class, "runExclusive", e); //$NON-NLS-1$
EMFTransactionPlugin.INSTANCE.log(new MultiStatus(EMFTransactionPlugin.getPluginId(), EMFTransactionStatusCodes.READ_ROLLED_BACK, new IStatus[] { e.getStatus() }, Messages.readTxRollback, null));
if (rwr != null) {
rwr.setStatus(e.getStatus());
}
}
}
}
if (start != -1) {
long duration = System.currentTimeMillis() - start;
if (duration > 2 * 1000) {
LogUtil.warn("runnable " + read + " held transaction for " + (duration / 1000.0) + " seconds");
}
}
if (rwr != null) {
@SuppressWarnings("unchecked")
T result = (T) rwr.getResult();
return result;
}
return null;
}
示例12: doExecute
import org.eclipse.emf.transaction.RollbackException; //导入依赖的package包/类
@Override
protected void doExecute(Command command, Map<?, ?> options) throws InterruptedException, RollbackException {
// default the transaction options to not perform EMF validation or allow undo
if (options == null) {
options = DEFAULT_TRANSACTION_OPTIONS;
}
InternalTransaction tx = createTransaction(command, options);
boolean completed = false;
try {
basicExecute(command);
// new in EMF 2.4: AbortExecutionException can cause the
// command not to be added to the undo stack
completed = mostRecentCommand == command;
// commit the transaction now
TransactionalEditingDomainImpl domain = (TransactionalEditingDomainImpl)tx.getEditingDomain();
if (domain != null && domain.getChangeRecorder() != null) {
tx.commit();
} else {
tx = null;
}
} catch (OperationCanceledException e) {
// snuff the exception, because this is expected (user asked to
// cancel the model change). We will rollback, below
} finally {
if (tx != null) {
if (tx.isActive()) {
// roll back (some exception, possibly being thrown now or
// an operation cancel, has occurred)
rollback(tx);
handleRollback(command, null);
} else {
// the transaction has already incorporated the triggers
// into its change description, so the recording command
// doesn't need them again
if (!(command instanceof RecordingCommand) && completed) {
Command triggerCommand = tx.getTriggers();
if (triggerCommand != null) {
// replace the executed command by a compound of the
// original and the trigger commands
CompoundCommand compound = new ConditionalRedoCommand.Compound();
compound.append(mostRecentCommand);
compound.append(triggerCommand);
mostRecentCommand = compound;
}
}
}
}
}
clearStack(command);
}