1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
/*****************************************************************************
* Copyright (c) 2014, 2016 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
* Christian W. Damus - bug 485220
*
*****************************************************************************/
package org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.utils;
import java.util.Collections;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.RollbackException;
import org.eclipse.emf.transaction.Transaction;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.impl.InternalTransactionalEditingDomain;
/**
* This helper can be used to run (safe) transactions outside the CommandStack
*
* @author Camille Letavernier
* @deprecated Use the {@code org.eclipse.papyrus.infra.core.util.TransactionHelper}, instead
*/
@Deprecated
public class TransactionHelper {
public static void run(EditingDomain domain, Runnable writeOperation) throws InterruptedException, RollbackException {
if (domain instanceof TransactionalEditingDomain) {
run((TransactionalEditingDomain) domain, writeOperation);
} else {
writeOperation.run();
}
}
public static void run(TransactionalEditingDomain domain, final Runnable writeOperation) throws InterruptedException, RollbackException {
if (domain instanceof InternalTransactionalEditingDomain) {
run((InternalTransactionalEditingDomain) domain, writeOperation);
} else {
// Shouldn't happen, as all TransactionalEditingDomain implementations should also implement InternalTransactionalEditingDomain
domain.getCommandStack().execute(new RecordingCommand(domain) {
@Override
protected void doExecute() {
writeOperation.run();
}
});
}
}
public static void run(InternalTransactionalEditingDomain domain, Runnable writeOperation) throws InterruptedException, RollbackException {
Transaction transaction = domain.startTransaction(false, Collections.emptyMap());
try {
writeOperation.run();
} finally {
transaction.commit();
}
}
}
|