本文整理汇总了Java中com.mendix.systemwideinterfaces.core.IContext.rollbackTransAction方法的典型用法代码示例。如果您正苦于以下问题:Java IContext.rollbackTransAction方法的具体用法?Java IContext.rollbackTransAction怎么用?Java IContext.rollbackTransAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mendix.systemwideinterfaces.core.IContext
的用法示例。
在下文中一共展示了IContext.rollbackTransAction方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findOrCreateSynchronized
import com.mendix.systemwideinterfaces.core.IContext; //导入方法依赖的package包/类
public T findOrCreateSynchronized(Object... keysAndValues) throws CoreException, InterruptedException {
T res = findFirst(keysAndValues);
if (res != null) {
return res;
} else {
synchronized (Core.getMetaObject(entity)) {
IContext synchronizedContext = context.getSession().createContext().createSudoClone();
try {
synchronizedContext.startTransaction();
res = createProxy(synchronizedContext, proxyClass, XPath.create(synchronizedContext, entity).findOrCreate(keysAndValues));
synchronizedContext.endTransaction();
return res;
} catch (CoreException e) {
if (synchronizedContext.isInTransaction()) {
synchronizedContext.rollbackTransAction();
}
throw e;
}
}
}
}
示例2: getSessionFor
import com.mendix.systemwideinterfaces.core.IContext; //导入方法依赖的package包/类
private static ISession getSessionFor(IContext context, String username) {
ISession session = Core.getActiveSession(username);
if (session == null) {
IContext newContext = context.getSession().createContext().getSudoContext();
newContext.startTransaction();
try {
session = initializeSessionForUser(newContext, username);
} catch (CoreException e) {
newContext.rollbackTransAction();
throw new RuntimeException("Failed to initialize session for user: " + username + ": " + e.getMessage(), e);
} finally {
newContext.endTransaction();
}
}
return session;
}
示例3: findOrCreateSynchronized
import com.mendix.systemwideinterfaces.core.IContext; //导入方法依赖的package包/类
public T findOrCreateSynchronized(Object... keysAndValues) throws CoreException, InterruptedException {
T res = findFirst(keysAndValues);
if (res != null) {
return res;
} else {
synchronized (Core.getMetaObject(entity)) {
IContext synchronizedContext = context.getSession().createContext().getSudoContext();
try {
synchronizedContext.startTransaction();
res = createProxy(synchronizedContext, proxyClass, XPath.create(synchronizedContext, entity).findOrCreate(keysAndValues));
synchronizedContext.endTransaction();
return res;
} catch (CoreException e) {
if (synchronizedContext.isInTransaction()) {
synchronizedContext.rollbackTransAction();
}
throw e;
}
}
}
}
示例4: runMicroflowTest
import com.mendix.systemwideinterfaces.core.IContext; //导入方法依赖的package包/类
private boolean runMicroflowTest(String mf, UnitTest test, TestSuite testSuite) throws CoreException
{
/**
* Prepare...
*/
LOG.info("Starting unittest for microflow " + mf);
reportStep("Starting microflow test '" + mf + "'");
test.setResult(UnitTestResult._1_Running);
test.setName(mf);
test.setResultMessage("");
test.setLastRun(new Date());
if (Core.getInputParameters(mf).size() != 0) {
test.setResultMessage("Unable to start test '" + mf + "', microflow has parameters");
test.setResult(UnitTestResult._2_Failed);
}
else if (Core.getReturnType(mf).getType() != IDataType.DataTypeEnum.Boolean &&
Core.getReturnType(mf).getType() != IDataType.DataTypeEnum.String &&
Core.getReturnType(mf).getType() != IDataType.DataTypeEnum.Nothing) {
test.setResultMessage("Unable to start test '" + mf + "', microflow should return either a boolean or a string or nothing at all");
test.setResult(UnitTestResult._2_Failed);
}
commitSilent(test);
IContext mfContext = Core.createSystemContext();
if (testSuite.getAutoRollbackMFs())
mfContext.startTransaction();
long start = System.currentTimeMillis();
try {
Object resultObject = Core.execute(mfContext, mf, emptyArguments);
start = System.currentTimeMillis() - start;
boolean res = resultObject == null || Boolean.TRUE.equals(resultObject) || "".equals(resultObject);
test.setResult(res ? UnitTestResult._3_Success : UnitTestResult._2_Failed);
if (res) {
test.setResultMessage("Microflow completed successfully");
}
return res;
}
catch(Exception e) {
start = System.currentTimeMillis() - start;
test.setResult(UnitTestResult._2_Failed);
Throwable cause = ExceptionUtils.getRootCause(e);
if (cause != null && cause instanceof AssertionException)
test.setResultMessage(cause.getMessage());
else
test.setResultMessage("Exception: " + e.getMessage() + "\n\n" + ExceptionUtils.getStackTrace(e));
return false;
}
finally {
if (testSuite.getAutoRollbackMFs())
mfContext.rollbackTransAction();
test.setLastStep(lastStep);
test.setReadableTime((start > 10000 ? Math.round(start / 1000) + " seconds" : start + " milliseconds"));
commitSilent(test);
LOG.info("Finished unittest " + mf + ": " + test.getResult());
}
}