List of usage examples for org.springframework.transaction.support DefaultTransactionDefinition PREFIX_ISOLATION
String PREFIX_ISOLATION
To view the source code for org.springframework.transaction.support DefaultTransactionDefinition PREFIX_ISOLATION.
Click Source Link
From source file:com._4dconcept.springframework.data.marklogic.datasource.IsolationLevelContentSourceAdapter.java
/** * Set the default isolation level by the name of the corresponding constant * in {@link TransactionDefinition}, e.g. * "ISOLATION_SERIALIZABLE"./*w ww .j ava2 s . c om*/ * <p>If not specified, the target ContentSource's default will be used. * Note that a transaction-specific isolation value will always override * any isolation setting specified at the ContentSource level. * @param constantName name of the constant * @see TransactionDefinition#ISOLATION_READ_UNCOMMITTED * @see TransactionDefinition#ISOLATION_READ_COMMITTED * @see TransactionDefinition#ISOLATION_REPEATABLE_READ * @see TransactionDefinition#ISOLATION_SERIALIZABLE * @see #setIsolationLevel */ public final void setIsolationLevelName(String constantName) throws IllegalArgumentException { if (constantName == null || !constantName.startsWith(DefaultTransactionDefinition.PREFIX_ISOLATION)) { throw new IllegalArgumentException("Only isolation constants allowed"); } setIsolationLevel(constants.asNumber(constantName).intValue()); }
From source file:com._4dconcept.springframework.data.marklogic.datasource.lookup.IsolationLevelContentSourceRouter.java
/** * Supports Integer values for the isolation level constants * as well as isolation level names as defined on the * {@link TransactionDefinition TransactionDefinition interface}. *//*from w ww . j av a 2 s. c o m*/ @Override protected Object resolveSpecifiedLookupKey(Object lookupKey) { if (lookupKey instanceof Integer) { return lookupKey; } else if (lookupKey instanceof String) { String constantName = (String) lookupKey; if (!constantName.startsWith(DefaultTransactionDefinition.PREFIX_ISOLATION)) { throw new IllegalArgumentException("Only isolation constants allowed"); } return constants.asNumber(constantName); } else { throw new IllegalArgumentException( "Invalid lookup key - needs to be isolation level Integer or isolation level name String: " + lookupKey); } }
From source file:com._4dconcept.springframework.data.marklogic.datasource.IsolationLevelContentSourceAdapter.java
/** * Specify the default isolation level to use for Session retrieval, * according to the XDBC {@link Session} constants * (equivalent to the corresponding Spring * {@link TransactionDefinition} constants). * <p>If not specified, the target ContentSource's default will be used. * Note that a transaction-specific isolation value will always override * any isolation setting specified at the ContentSource level. * @param isolationLevel the default isolation level to use for session retrieval * @see Session.TransactionMode#UPDATE/*from ww w .j a va 2 s . c om*/ * @see Session.TransactionMode#QUERY * @see TransactionDefinition#ISOLATION_READ_UNCOMMITTED * @see TransactionDefinition#ISOLATION_READ_COMMITTED * @see TransactionDefinition#ISOLATION_REPEATABLE_READ * @see TransactionDefinition#ISOLATION_SERIALIZABLE * @see TransactionDefinition#getIsolationLevel() * @see 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); }
From source file:org.springframework.transaction.support.AbstractPlatformTransactionManager.java
/** * Create a TransactionStatus for an existing transaction. *//*from w w w .java 2 s . com*/ private TransactionStatus handleExistingTransaction(TransactionDefinition definition, Object transaction, boolean debugEnabled) throws TransactionException { if (definition.getPropagationBehavior() == TransactionDefinition.PROPAGATION_NEVER) { throw new IllegalTransactionStateException( "Existing transaction found for transaction marked with propagation 'never'"); } if (definition.getPropagationBehavior() == TransactionDefinition.PROPAGATION_NOT_SUPPORTED) { if (debugEnabled) { logger.debug("Suspending current transaction"); } Object suspendedResources = suspend(transaction); boolean newSynchronization = (getTransactionSynchronization() == SYNCHRONIZATION_ALWAYS); return prepareTransactionStatus(definition, null, false, newSynchronization, debugEnabled, suspendedResources); } if (definition.getPropagationBehavior() == TransactionDefinition.PROPAGATION_REQUIRES_NEW) { if (debugEnabled) { logger.debug("Suspending current transaction, creating new transaction with name [" + definition.getName() + "]"); } SuspendedResourcesHolder suspendedResources = suspend(transaction); try { boolean newSynchronization = (getTransactionSynchronization() != SYNCHRONIZATION_NEVER); DefaultTransactionStatus status = newTransactionStatus(definition, transaction, true, newSynchronization, debugEnabled, suspendedResources); doBegin(transaction, definition); prepareSynchronization(status, definition); return status; } catch (RuntimeException | Error beginEx) { resumeAfterBeginException(transaction, suspendedResources, beginEx); throw beginEx; } } if (definition.getPropagationBehavior() == TransactionDefinition.PROPAGATION_NESTED) { if (!isNestedTransactionAllowed()) { throw new NestedTransactionNotSupportedException( "Transaction manager does not allow nested transactions by default - " + "specify 'nestedTransactionAllowed' property with value 'true'"); } if (debugEnabled) { logger.debug("Creating nested transaction with name [" + definition.getName() + "]"); } if (useSavepointForNestedTransaction()) { // Create savepoint within existing Spring-managed transaction, // through the SavepointManager API implemented by TransactionStatus. // Usually uses JDBC 3.0 savepoints. Never activates Spring synchronization. DefaultTransactionStatus status = prepareTransactionStatus(definition, transaction, false, false, debugEnabled, null); status.createAndHoldSavepoint(); return status; } else { // Nested transaction through nested begin and commit/rollback calls. // Usually only for JTA: Spring synchronization might get activated here // in case of a pre-existing JTA transaction. boolean newSynchronization = (getTransactionSynchronization() != SYNCHRONIZATION_NEVER); DefaultTransactionStatus status = newTransactionStatus(definition, transaction, true, newSynchronization, debugEnabled, null); doBegin(transaction, definition); prepareSynchronization(status, definition); return status; } } // Assumably PROPAGATION_SUPPORTS or PROPAGATION_REQUIRED. if (debugEnabled) { logger.debug("Participating in existing transaction"); } if (isValidateExistingTransaction()) { if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) { Integer currentIsolationLevel = TransactionSynchronizationManager .getCurrentTransactionIsolationLevel(); if (currentIsolationLevel == null || currentIsolationLevel != definition.getIsolationLevel()) { Constants isoConstants = DefaultTransactionDefinition.constants; throw new IllegalTransactionStateException("Participating transaction with definition [" + definition + "] specifies isolation level which is incompatible with existing transaction: " + (currentIsolationLevel != null ? isoConstants.toCode(currentIsolationLevel, DefaultTransactionDefinition.PREFIX_ISOLATION) : "(unknown)")); } } if (!definition.isReadOnly()) { if (TransactionSynchronizationManager.isCurrentTransactionReadOnly()) { throw new IllegalTransactionStateException("Participating transaction with definition [" + definition + "] is not marked as read-only but existing transaction is"); } } } boolean newSynchronization = (getTransactionSynchronization() != SYNCHRONIZATION_NEVER); return prepareTransactionStatus(definition, transaction, false, newSynchronization, debugEnabled, null); }