當前位置: 首頁>>代碼示例>>Java>>正文


Java TransactionDefinition.ISOLATION_DEFAULT屬性代碼示例

本文整理匯總了Java中org.springframework.transaction.TransactionDefinition.ISOLATION_DEFAULT屬性的典型用法代碼示例。如果您正苦於以下問題:Java TransactionDefinition.ISOLATION_DEFAULT屬性的具體用法?Java TransactionDefinition.ISOLATION_DEFAULT怎麽用?Java TransactionDefinition.ISOLATION_DEFAULT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.springframework.transaction.TransactionDefinition的用法示例。


在下文中一共展示了TransactionDefinition.ISOLATION_DEFAULT屬性的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: beginTransaction

@Override
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
		throws PersistenceException, SQLException, TransactionException {

	OpenJPAEntityManager openJpaEntityManager = getOpenJPAEntityManager(entityManager);

	if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
		// Pass custom isolation level on to OpenJPA's JDBCFetchPlan configuration
		FetchPlan fetchPlan = openJpaEntityManager.getFetchPlan();
		if (fetchPlan instanceof JDBCFetchPlan) {
			IsolationLevel isolation = IsolationLevel.fromConnectionConstant(definition.getIsolationLevel());
			((JDBCFetchPlan) fetchPlan).setIsolation(isolation);
		}
	}

	entityManager.getTransaction().begin();

	if (!definition.isReadOnly()) {
		// Like with EclipseLink, make sure to start the logic transaction early so that other
		// participants using the connection (such as JdbcTemplate) run in a transaction.
		openJpaEntityManager.beginStore();
	}

	// Custom implementation for OpenJPA savepoint handling
	return new OpenJpaTransactionData(openJpaEntityManager);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:26,代碼來源:OpenJpaDialect.java

示例2: beginTransaction

@Override
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
		throws PersistenceException, SQLException, TransactionException {

	if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
		// Pass custom isolation level on to EclipseLink's DatabaseLogin configuration
		// (since Spring 4.1.2)
		UnitOfWork uow = entityManager.unwrap(UnitOfWork.class);
		uow.getLogin().setTransactionIsolation(definition.getIsolationLevel());
	}

	entityManager.getTransaction().begin();

	if (!definition.isReadOnly() && !this.lazyDatabaseTransaction) {
		// Begin an early transaction to force EclipseLink to get a JDBC Connection
		// so that Spring can manage transactions with JDBC as well as EclipseLink.
		entityManager.unwrap(UnitOfWork.class).beginEarlyTransaction();
	}

	return null;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:21,代碼來源:EclipseLinkJpaDialect.java

示例3: getTxn

private UserTransaction getTxn()
{
    return new SpringAwareUserTransaction(
            transactionManager,
            false,
            TransactionDefinition.ISOLATION_DEFAULT,
            TransactionDefinition.PROPAGATION_REQUIRED,
            TransactionDefinition.TIMEOUT_DEFAULT);
}
 
開發者ID:Alfresco,項目名稱:alfresco-core,代碼行數:9,代碼來源:SpringAwareUserTransactionTest.java

示例4: getFailingTxn

private UserTransaction getFailingTxn()
{
    return new SpringAwareUserTransaction(
            failingTransactionManager,
            false,
            TransactionDefinition.ISOLATION_DEFAULT,
            TransactionDefinition.PROPAGATION_REQUIRED,
            TransactionDefinition.TIMEOUT_DEFAULT);
}
 
開發者ID:Alfresco,項目名稱:alfresco-core,代碼行數:9,代碼來源:SpringAwareUserTransactionTest.java

示例5: beginTransaction

/**
 * This implementation invokes the standard JPA {@code Transaction.begin}
 * method. Throws an InvalidIsolationLevelException if a non-default isolation
 * level is set.
 * <p>This implementation does not return any transaction data Object, since there
 * is no state to be kept for a standard JPA transaction. Hence, subclasses do not
 * have to care about the return value ({@code null}) of this implementation
 * and are free to return their own transaction data Object.
 * @see javax.persistence.EntityTransaction#begin
 * @see org.springframework.transaction.InvalidIsolationLevelException
 * @see #cleanupTransaction
 */
@Override
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
		throws PersistenceException, SQLException, TransactionException {

	if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
		throw new InvalidIsolationLevelException(getClass().getSimpleName() +
				" does not support custom isolation levels due to limitations in standard JPA. " +
				"Specific arrangements may be implemented in custom JpaDialect variants.");
	}
	entityManager.getTransaction().begin();
	return null;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:24,代碼來源:DefaultJpaDialect.java

示例6: beginTransaction

@Override
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
		throws PersistenceException, SQLException, TransactionException {

	Session session = getSession(entityManager);

	if (definition.getTimeout() != TransactionDefinition.TIMEOUT_DEFAULT) {
		session.getTransaction().setTimeout(definition.getTimeout());
	}

	boolean isolationLevelNeeded = (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT);
	Integer previousIsolationLevel = null;
	Connection preparedCon = null;

	if (isolationLevelNeeded || definition.isReadOnly()) {
		if (this.prepareConnection) {
			preparedCon = HibernateConnectionHandle.doGetConnection(session);
			previousIsolationLevel = DataSourceUtils.prepareConnectionForTransaction(preparedCon, definition);
		}
		else if (isolationLevelNeeded) {
			throw new InvalidIsolationLevelException(getClass().getSimpleName() +
					" does not support custom isolation levels since the 'prepareConnection' flag is off. " +
					"This is the case on Hibernate 3.6 by default; either switch that flag at your own risk " +
					"or upgrade to Hibernate 4.x, with 4.2+ recommended.");
		}
	}

	// Standard JPA transaction begin call for full JPA context setup...
	entityManager.getTransaction().begin();

	// Adapt flush mode and store previous isolation level, if any.
	FlushMode previousFlushMode = prepareFlushMode(session, definition.isReadOnly());
	return new SessionTransactionData(session, previousFlushMode, preparedCon, previousIsolationLevel);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:34,代碼來源:HibernateJpaDialect.java

示例7: applyIsolationLevel

/**
 * Apply the given transaction isolation level. The default implementation
 * will throw an exception for any level other than ISOLATION_DEFAULT.
 * <p>To be overridden in subclasses for specific JTA implementations,
 * as alternative to overriding the full {@link #doJtaBegin} method.
 * @param txObject the JtaTransactionObject containing the UserTransaction
 * @param isolationLevel isolation level taken from transaction definition
 * @throws InvalidIsolationLevelException if the given isolation level
 * cannot be applied
 * @throws SystemException if thrown by the JTA implementation
 * @see #doJtaBegin
 * @see JtaTransactionObject#getUserTransaction()
 * @see #getTransactionManager()
 */
protected void applyIsolationLevel(JtaTransactionObject txObject, int isolationLevel)
		throws InvalidIsolationLevelException, SystemException {

	if (!this.allowCustomIsolationLevels && isolationLevel != TransactionDefinition.ISOLATION_DEFAULT) {
		throw new InvalidIsolationLevelException(
			"JtaTransactionManager does not support custom isolation levels by default - " +
			"switch 'allowCustomIsolationLevels' to 'true'");
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:JtaTransactionManager.java

示例8: setIsolationLevel

/**
 * Specify the default isolation level to use for Connection retrieval,
 * according to the JDBC {@link java.sql.Connection} constants
 * (equivalent to the corresponding Spring
 * {@link org.springframework.transaction.TransactionDefinition} constants).
 * <p>If not specified, the target DataSource's default will be used.
 * Note that a transaction-specific isolation value will always override
 * any isolation setting specified at the DataSource level.
 * @see java.sql.Connection#TRANSACTION_READ_UNCOMMITTED
 * @see java.sql.Connection#TRANSACTION_READ_COMMITTED
 * @see java.sql.Connection#TRANSACTION_REPEATABLE_READ
 * @see java.sql.Connection#TRANSACTION_SERIALIZABLE
 * @see org.springframework.transaction.TransactionDefinition#ISOLATION_READ_UNCOMMITTED
 * @see org.springframework.transaction.TransactionDefinition#ISOLATION_READ_COMMITTED
 * @see org.springframework.transaction.TransactionDefinition#ISOLATION_REPEATABLE_READ
 * @see org.springframework.transaction.TransactionDefinition#ISOLATION_SERIALIZABLE
 * @see org.springframework.transaction.TransactionDefinition#getIsolationLevel()
 * @see org.springframework.transaction.support.TransactionSynchronizationManager#getCurrentTransactionIsolationLevel()
 */
public void setIsolationLevel(int isolationLevel) {
	if (!constants.getValues(DefaultTransactionDefinition.PREFIX_ISOLATION).contains(isolationLevel)) {
		throw new IllegalArgumentException("Only values of isolation constants allowed");
	}
	this.isolationLevel = (isolationLevel != TransactionDefinition.ISOLATION_DEFAULT ? isolationLevel : null);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:25,代碼來源:IsolationLevelDataSourceAdapter.java


注:本文中的org.springframework.transaction.TransactionDefinition.ISOLATION_DEFAULT屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。