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


Java TransactionDefinition.isReadOnly方法代碼示例

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


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

示例1: getTransaction

import org.springframework.transaction.TransactionDefinition; //導入方法依賴的package包/類
@Override
public TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException {
    Transaction.IsolationLevel isolationLevel = translateIsolationLevel(definition.getIsolationLevel());
    Transaction t;
    if (isolationLevel == null) {
        t = sql.transaction();
    } else {
        t = sql.transaction(isolationLevel);
    }

    if (definition.isReadOnly()) {
        Wrap.execute(() -> t.getConnection().setReadOnly(true));
    }

    return new SqlStreamTransactionStatus(t);
}
 
開發者ID:bendem,項目名稱:sql-streams-spring,代碼行數:17,代碼來源:SqlStreamsTransactionManager.java

示例2: doBegin

import org.springframework.transaction.TransactionDefinition; //導入方法依賴的package包/類
/**
 * 根據Spring配置的事務設置,為當前線程選擇主庫還是從庫數據源
 */
@Override
protected void doBegin(Object transaction, TransactionDefinition definition)
{
	if(definition.isReadOnly())
	{
		if(log.isDebugEnabled())
		{
			log.debug("DataSourceTransactionManager set slave");
		}
		DataSourceHolder.setSlave();
	}
	else
	{
		if(log.isDebugEnabled())
		{
			log.debug("DataSourceTransactionManager set master");
		}
		DataSourceHolder.setMaster();
	}
	super.doBegin(transaction, definition);
}
 
開發者ID:skeychen,項目名稱:dswork,代碼行數:25,代碼來源:DataSourceTransactionManager.java

示例3: beginTransaction

import org.springframework.transaction.TransactionDefinition; //導入方法依賴的package包/類
@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,代碼行數:27,代碼來源:OpenJpaDialect.java

示例4: beginTransaction

import org.springframework.transaction.TransactionDefinition; //導入方法依賴的package包/類
@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,代碼行數:22,代碼來源:EclipseLinkJpaDialect.java

示例5: beginTransaction

import org.springframework.transaction.TransactionDefinition; //導入方法依賴的package包/類
@Override
public Object beginTransaction(final EntityManager entityManager, final TransactionDefinition definition)
        throws SQLException {

    final boolean readOnly = definition.isReadOnly();
    final Connection connection = this.getJdbcConnection(entityManager, readOnly).getConnection();
    final Deque<ConnectionContext> deque = curContext.get();
    final ConnectionContext context = new ConnectionContext(connection, definition);
    deque.addLast(context);

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

    entityManager.getTransaction().begin();

    return prepareTransaction(entityManager, readOnly, definition.getName());
}
 
開發者ID:subes,項目名稱:invesdwin-context-persistence,代碼行數:19,代碼來源:HibernateExtendedJpaDialect.java

示例6: doBegin

import org.springframework.transaction.TransactionDefinition; //導入方法依賴的package包/類
/**
 * 事務開始前將數據源手動設置進去
 */
@Override
protected void doBegin(Object transaction, TransactionDefinition definition) {
    //若有 @Transaction 注解,並且不是隻讀,設置為主庫
    if (!definition.isReadOnly()) {
        DynamicDataSourceHolder.routeMaster();
    }
    super.doBegin(transaction, definition);
}
 
開發者ID:drtrang,項目名稱:dynamic-data-source-demo,代碼行數:12,代碼來源:DynamicDataSourceTransactionManager.java

示例7: doBegin

import org.springframework.transaction.TransactionDefinition; //導入方法依賴的package包/類
/**
 * 隻讀事務到讀庫,讀寫事務到寫庫
 *
 * @param transaction
 * @param definition
 */
@Override
protected void doBegin(Object transaction, TransactionDefinition definition) {
    //設置數據源
    boolean readOnly = definition.isReadOnly();
    if (readOnly) {
        DynamicDataSourceHolder.putDataSource(DynamicDataSourceType.READ);
    } else {
        DynamicDataSourceHolder.putDataSource(DynamicDataSourceType.WRITE);
    }
    super.doBegin(transaction, definition);
}
 
開發者ID:geeker-lait,項目名稱:tasfe-framework,代碼行數:18,代碼來源:DynamicDataSourceTransactionManager.java

示例8: doBegin

import org.springframework.transaction.TransactionDefinition; //導入方法依賴的package包/類
/**
  * 隻讀事務到從庫
  * 讀寫事務到主庫
  */
@Override
protected void doBegin(Object transaction, TransactionDefinition definition) {
    boolean readOnly = definition.isReadOnly();
    if (readOnly) {
        DynamicDataSourceHolder.setSlave();
    } else {
        DynamicDataSourceHolder.setMaster();
    }
    tryDoBegin(transaction, definition);
    
}
 
開發者ID:w775450,項目名稱:DynamicDataSource,代碼行數:16,代碼來源:DynamicDataSourceTransactionManager.java

示例9: newTransactionStatus

import org.springframework.transaction.TransactionDefinition; //導入方法依賴的package包/類
/**
 * Create a rae TransactionStatus instance for the given arguments.
 */
protected DefaultTransactionStatus newTransactionStatus(
		TransactionDefinition definition, Object transaction, boolean newTransaction,
		boolean newSynchronization, boolean debug, Object suspendedResources) {

	boolean actualNewSynchronization = newSynchronization &&
			!TransactionSynchronizationManager.isSynchronizationActive();
	return new DefaultTransactionStatus(
			transaction, newTransaction, actualNewSynchronization,
			definition.isReadOnly(), debug, suspendedResources);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:14,代碼來源:AbstractPlatformTransactionManager.java

示例10: beginTransaction

import org.springframework.transaction.TransactionDefinition; //導入方法依賴的package包/類
@Override
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
		throws PersistenceException, SQLException, TransactionException {

	super.beginTransaction(entityManager, definition);
	OpenJPAEntityManager em = getOpenJPAEntityManager(entityManager);
	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.
		em.beginStore();
	}
	return new OpenJpaTransactionData(em);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:14,代碼來源:OpenJpaDialect.java

示例11: beginTransaction

import org.springframework.transaction.TransactionDefinition; //導入方法依賴的package包/類
@Override
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
		throws PersistenceException, SQLException, TransactionException {

	super.beginTransaction(entityManager, definition);
	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:lamsfoundation,項目名稱:lams,代碼行數:13,代碼來源:EclipseLinkJpaDialect.java

示例12: doBegin

import org.springframework.transaction.TransactionDefinition; //導入方法依賴的package包/類
@Override
protected void doBegin(Object transaction, TransactionDefinition definition) {

    //設置數據源
    boolean readOnly = definition.isReadOnly();
    //隻讀事務到讀庫,讀寫事務到寫庫
    if (readOnly) {
        DynamicDataSourceHolder.putDataSource(DynamicDataSourceGlobal.READ);
    } else {
        DynamicDataSourceHolder.putDataSource(DynamicDataSourceGlobal.WRITE);
    }
    super.doBegin(transaction, definition);
}
 
開發者ID:ruyangit,項目名稱:angit,代碼行數:14,代碼來源:DynamicDataSourceTransactionManager.java

示例13: beginTransaction

import org.springframework.transaction.TransactionDefinition; //導入方法依賴的package包/類
@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,代碼行數:35,代碼來源:HibernateJpaDialect.java

示例14: newTransactionStatus

import org.springframework.transaction.TransactionDefinition; //導入方法依賴的package包/類
/**
 * Create a TransactionStatus instance for the given arguments.
 */
protected DefaultTransactionStatus newTransactionStatus(
		TransactionDefinition definition, Object transaction, boolean newTransaction,
		boolean newSynchronization, boolean debug, Object suspendedResources) {

	boolean actualNewSynchronization = newSynchronization &&
			!TransactionSynchronizationManager.isSynchronizationActive();
	return new DefaultTransactionStatus(
			transaction, newTransaction, actualNewSynchronization,
			definition.isReadOnly(), debug, suspendedResources);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:14,代碼來源:AbstractPlatformTransactionManager.java

示例15: DefaultTransactionDefinition

import org.springframework.transaction.TransactionDefinition; //導入方法依賴的package包/類
/**
 * Copy constructor. Definition can be modified through bean property setters.
 * @see #setPropagationBehavior
 * @see #setIsolationLevel
 * @see #setTimeout
 * @see #setReadOnly
 * @see #setName
 */
public DefaultTransactionDefinition(TransactionDefinition other) {
	this.propagationBehavior = other.getPropagationBehavior();
	this.isolationLevel = other.getIsolationLevel();
	this.timeout = other.getTimeout();
	this.readOnly = other.isReadOnly();
	this.name = other.getName();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:16,代碼來源:DefaultTransactionDefinition.java


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