当前位置: 首页>>代码示例>>Java>>正文


Java IContext.startTransaction方法代码示例

本文整理汇总了Java中com.mendix.systemwideinterfaces.core.IContext.startTransaction方法的典型用法代码示例。如果您正苦于以下问题:Java IContext.startTransaction方法的具体用法?Java IContext.startTransaction怎么用?Java IContext.startTransaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mendix.systemwideinterfaces.core.IContext的用法示例。


在下文中一共展示了IContext.startTransaction方法的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;
			}
		}
	}
}
 
开发者ID:mendix,项目名称:database-connector,代码行数:23,代码来源:XPath.java

示例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;
}
 
开发者ID:appronto,项目名称:RedisConnector,代码行数:20,代码来源:Misc.java

示例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;
			}
		}
	}
}
 
开发者ID:appronto,项目名称:RedisConnector,代码行数:23,代码来源:XPath.java

示例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());
	}
}
 
开发者ID:appronto,项目名称:RedisConnector,代码行数:72,代码来源:TestManager.java


注:本文中的com.mendix.systemwideinterfaces.core.IContext.startTransaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。