/** * Set the isolation level by the name of the corresponding constant in * TransactionDefinition, e.g. "ISOLATION_DEFAULT". * @param constantName name of the constant * @throws IllegalArgumentException if the supplied value is not resolvable * to one of the {@code ISOLATION_} constants or is {@code null} * @see #setIsolationLevel * @see #ISOLATION_DEFAULT */ public final void setIsolationLevelName(String constantName) throws IllegalArgumentException { if (!constantName.startsWith(PREFIX_ISOLATION)) { throw new IllegalArgumentException("Only isolation constants allowed"); } setIsolationLevel(constants.asNumber(constantName).intValue()); }
/** * Set the isolation level by the name of the corresponding constant in * TransactionDefinition, e.g. "ISOLATION_DEFAULT". * @param constantName name of the constant * @throws IllegalArgumentException if the supplied value is not resolvable * to one of the {@code ISOLATION_} constants or is {@code null} * @see #setIsolationLevel * @see #ISOLATION_DEFAULT */ public final void setIsolationLevelName(String constantName) throws IllegalArgumentException { if (!constantName.startsWith(PREFIX_ISOLATION)) { throw new IllegalArgumentException("Only isolation constants allowed"); } setIsolationLevel(constants.asNumber(constantName).intValue()); }
public static TransactionStatus createTransaction(int propagationBehavior, int isolationLevel, PlatformTransactionManager transactionManager, boolean isReadOnly) { DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setReadOnly(isReadOnly); def.setPropagationBehavior(propagationBehavior); def.setIsolationLevel(isolationLevel); return transactionManager.getTransaction(def); }
@Test public void testDefaultTransactionDefinition() throws Exception { DefaultTransactionDefinition definition = new DefaultTransactionDefinition(); definition.setIsolationLevel(TransactionDefinition.ISOLATION_REPEATABLE_READ); try { dialect.beginTransaction(null, definition); fail("expected exception"); } catch (TransactionException e) { // ok } }
public static TransactionStatus createTransaction(String name, int propagationBehavior, int isolationLevel, PlatformTransactionManager transactionManager, boolean isReadOnly) { DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName(name); def.setReadOnly(isReadOnly); def.setPropagationBehavior(propagationBehavior); def.setIsolationLevel(isolationLevel); return transactionManager.getTransaction(def); }
/** * Gets DB transaction isolation level based on ongoing cache transaction isolation. * * @return DB transaction isolation. */ private TransactionDefinition definition(Transaction tx, String cacheName) { assert tx != null; DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("Ignite Tx [cache=" + (cacheName != null ? cacheName : "<default>") + ", id=" + tx.xid() + ']'); def.setIsolationLevel(isolationLevel(tx.isolation())); long timeoutSec = (tx.timeout() + 500) / 1000; if (timeoutSec > 0 && timeoutSec < Integer.MAX_VALUE) def.setTimeout((int)timeoutSec); return def; }
@Test public void testTransactionAttributesForCreateMethod() throws Exception { testCreateRepository(); JobRepository repository = factory.getObject(); DefaultTransactionDefinition transactionDefinition = new DefaultTransactionDefinition( DefaultTransactionDefinition.PROPAGATION_REQUIRES_NEW); transactionDefinition.setIsolationLevel(DefaultTransactionDefinition.ISOLATION_SERIALIZABLE); when(transactionManager.getTransaction(transactionDefinition)).thenReturn(null); Connection conn = mock(Connection.class); when(dataSource.getConnection()).thenReturn(conn); try { repository.createJobExecution("foo", new JobParameters()); // we expect an exception but not from the txControl because we // provided the correct meta data fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { // expected exception from DataSourceUtils assertEquals("No Statement specified", e.getMessage()); } }
@Test public void testSetTransactionAttributesForCreateMethod() throws Exception { factory.setIsolationLevelForCreate("ISOLATION_READ_UNCOMMITTED"); testCreateRepository(); JobRepository repository = factory.getObject(); DefaultTransactionDefinition transactionDefinition = new DefaultTransactionDefinition( DefaultTransactionDefinition.PROPAGATION_REQUIRES_NEW); transactionDefinition.setIsolationLevel(DefaultTransactionDefinition.ISOLATION_READ_UNCOMMITTED); when(transactionManager.getTransaction(transactionDefinition)).thenReturn(null); Connection conn = mock(Connection.class); when(dataSource.getConnection()).thenReturn(conn); try { repository.createJobExecution("foo", new JobParameters()); // we expect an exception but not from the txControl because we // provided the correct meta data fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { // expected exception from DataSourceUtils assertEquals("No Statement specified", e.getMessage()); } }
public JobDAO(DataSource dataSource, JobSchema jobSchema, IdentityManager identManager, StringIDGenerator idGenerator) { this.jobSchema = jobSchema; this.identManager = identManager; this.idGenerator = idGenerator; this.defaultTransactionDef = new DefaultTransactionDefinition(); defaultTransactionDef.setIsolationLevel(DefaultTransactionDefinition.ISOLATION_REPEATABLE_READ); this.transactionManager = new DataSourceTransactionManager(dataSource); this.jdbc = new JdbcTemplate(dataSource); }
private void setIsolationLevel(final DefaultTransactionDefinition definition, final TransactionIsolation isolationLevel) { if (isolationLevel!=TransactionIsolation.DEFAULT) { definition.setIsolationLevel(isolationLevel.getTransactionIsolation()); } } }
/** * Set the isolation level by the name of the corresponding constant in * TransactionDefinition, e.g. "ISOLATION_DEFAULT". * @param constantName name of the constant * @throws java.lang.IllegalArgumentException if an invalid constant was specified * @see #setIsolationLevel * @see #ISOLATION_DEFAULT */ public final void setIsolationLevelName(String constantName) throws IllegalArgumentException { if (constantName == null || !constantName.startsWith(ISOLATION_CONSTANT_PREFIX)) { throw new IllegalArgumentException("Only isolation constants allowed"); } setIsolationLevel(constants.asNumber(constantName).intValue()); }
/** * Set the isolation level by the name of the corresponding constant in * TransactionDefinition, e.g. "ISOLATION_DEFAULT". * @param constantName name of the constant * @throws IllegalArgumentException if the supplied value is not resolvable * to one of the {@code ISOLATION_} constants or is {@code null} * @see #setIsolationLevel * @see #ISOLATION_DEFAULT */ public final void setIsolationLevelName(String constantName) throws IllegalArgumentException { if (!constantName.startsWith(PREFIX_ISOLATION)) { throw new IllegalArgumentException("Only isolation constants allowed"); } setIsolationLevel(constants.asNumber(constantName).intValue()); }
/** * Set the isolation level by the name of the corresponding constant in * TransactionDefinition, e.g. "ISOLATION_DEFAULT". * @param constantName name of the constant * @throws IllegalArgumentException if the supplied value is not resolvable * to one of the {@code ISOLATION_} constants or is {@code null} * @see #setIsolationLevel * @see #ISOLATION_DEFAULT */ public final void setIsolationLevelName(String constantName) throws IllegalArgumentException { if (!constantName.startsWith(PREFIX_ISOLATION)) { throw new IllegalArgumentException("Only isolation constants allowed"); } setIsolationLevel(constants.asNumber(constantName).intValue()); }
private static DefaultTransactionDefinition getCustomTransactionDefinition(int IsolationLevel,int propagationBehavior){ DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setIsolationLevel(IsolationLevel); def.setPropagationBehavior(propagationBehavior); return def; }
public void dbTranNestRollbackAndThrow() throws Exception{ PlatformTransactionManager transactionManager=MicroTranManagerHolder.getTransactionManager(dbName); DefaultTransactionDefinition def =new DefaultTransactionDefinition(); def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus status=transactionManager.getTransaction(def); transactionManager.rollback(status); throw new RuntimeException("dbTranNestRollbackAndThrow"); } public void checkRollbackAndThrow() throws Exception{
/** * Start a transaction * @throws TransactionException If an error occurred */ protected void startTransaction() throws TransactionException { if (getTransactionStatus().isPresent()) { throw new TransactionException("The transaction has already been started"); } // transaction definition DefaultTransactionDefinition definition = new DefaultTransactionDefinition(); getIsolationLevel(getConfiguration()).ifPresent(i -> { definition.setIsolationLevel(i); }); // start transaction transactionStatus = getTransactionManager().getTransaction(definition); }
public void dbTranNestRollback() throws Exception{ PlatformTransactionManager transactionManager=MicroTranManagerHolder.getTransactionManager(dbName); DefaultTransactionDefinition def =new DefaultTransactionDefinition(); def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus status=transactionManager.getTransaction(def); transactionManager.rollback(status); } public void dbTranNestRollbackAndThrow() throws Exception{
/** * The constructor. * * @param settings are the settings to use. */ public SpringTransactionAdapter(TransactionSettings settings) { super(); this.transactionDefinition = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED); if (settings.getIsolationLevel() != null) { this.transactionDefinition.setIsolationLevel(settings.getIsolationLevel().getJdbcCode()); } if (settings.getTimeout() != null) { this.transactionDefinition.setTimeout(settings.getTimeout().intValue()); } }
private DefaultTransactionDefinition convert(TransactionDefinition td) { DefaultTransactionDefinition std; if(null == td) { std = new DefaultTransactionDefinition(); std.setPropagationBehavior(td.getPropagation().getValue()); std.setIsolationLevel(td.getIsolation().getValue()); }else { std = new DefaultTransactionDefinition(); } return std; } }
/** * Gets DB transaction isolation level based on ongoing cache transaction isolation. * * @return DB transaction isolation. */ private TransactionDefinition definition(Transaction tx, String cacheName) { assert tx != null; DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("Ignite Tx [cache=" + (cacheName != null ? cacheName : "<default>") + ", id=" + tx.xid() + ']'); def.setIsolationLevel(isolationLevel(tx.isolation())); long timeoutSec = (tx.timeout() + 500) / 1000; if (timeoutSec > 0 && timeoutSec < Integer.MAX_VALUE) def.setTimeout((int)timeoutSec); return def; }