Example usage for org.springframework.transaction TransactionDefinition ISOLATION_SERIALIZABLE

List of usage examples for org.springframework.transaction TransactionDefinition ISOLATION_SERIALIZABLE

Introduction

In this page you can find the example usage for org.springframework.transaction TransactionDefinition ISOLATION_SERIALIZABLE.

Prototype

int ISOLATION_SERIALIZABLE

To view the source code for org.springframework.transaction TransactionDefinition ISOLATION_SERIALIZABLE.

Click Source Link

Document

Indicates that dirty reads, non-repeatable reads and phantom reads are prevented.

Usage

From source file:org.springextensions.neodatis.NeoDatisTransactionManagerTest.java

@Test
public void testWrongIsolationLevel() {
    final ODB odb = Mockito.mock(ODB.class);
    Mockito.when(odb.store(Mockito.isNull())).thenThrow(new RuntimeException());
    PlatformTransactionManager tm = new NeoDatisTransactionManager(odb);
    TransactionTemplate tmpl = new TransactionTemplate(tm);

    Assert.assertFalse("Should not have a resource", TransactionSynchronizationManager.hasResource(odb));
    Assert.assertFalse("There should no active synchronizations",
            TransactionSynchronizationManager.isSynchronizationActive());

    tmpl.setIsolationLevel(TransactionDefinition.ISOLATION_SERIALIZABLE);
    try {//  w w  w .  j a va2 s. c  o m
        tmpl.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
                Assert.assertTrue(TransactionSynchronizationManager.hasResource(odb));
                NeoDatisTemplate neoDatisTemplate = new NeoDatisTemplate(odb);
                neoDatisTemplate.store(null);
                transactionStatus.setRollbackOnly();
            }
        });
        Assert.fail("Should throw an exception.");
    } catch (InvalidIsolationLevelException e) {
        // is ok
    }

    Assert.assertFalse("Should not have a resource", TransactionSynchronizationManager.hasResource(odb));
    Assert.assertFalse("There should no active synchronizations",
            TransactionSynchronizationManager.isSynchronizationActive());

}

From source file:org.springextensions.db4o.Db4oTransactionManagerTest.java

@Test
public void testInvalidIsolation() throws Exception {
    final ExtObjectContainer container = mock(ExtObjectContainer.class);

    PlatformTransactionManager tm = new Db4oTransactionManager(container);
    TransactionTemplate tt = new TransactionTemplate(tm);

    Assert.assertTrue(!TransactionSynchronizationManager.hasResource(container), "Has no container");
    Assert.assertTrue(!TransactionSynchronizationManager.isSynchronizationActive(),
            "JTA synchronizations not active");

    tt.setIsolationLevel(TransactionDefinition.ISOLATION_SERIALIZABLE);
    try {//from  ww w  .j a  v  a 2  s.c  om
        tt.execute(new TransactionCallbackWithoutResult() {
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                Assert.assertTrue(TransactionSynchronizationManager.hasResource(container),
                        "Has thread session");
                Db4oTemplate template = new Db4oTemplate(container);
                template.execute(new Db4oCallback() {
                    public Object doInDb4o(ObjectContainer cont) {
                        return null;
                    }
                });
            }
        });
        Assert.fail("Should have thrown InvalidIsolationLevelException");
    } catch (InvalidIsolationLevelException e) {
        // it's okay
    }

    Assert.assertTrue(!TransactionSynchronizationManager.hasResource(container), "Has no container");
    Assert.assertTrue(!TransactionSynchronizationManager.isSynchronizationActive(),
            "JTA synchronizations not active");

    // TODO verify(container)....; exception thrown?
}

From source file:com.newmainsoftech.spray.slingong.datastore.Slim3PlatformTransactionManager.java

protected void validateIsolationLevel(final int isolationLevel) throws TransactionException {
    if ((isolationLevel != TransactionDefinition.ISOLATION_DEFAULT)
            && (isolationLevel != TransactionDefinition.ISOLATION_SERIALIZABLE)) {
        throw new InvalidIsolationLevelException(String.format(
                "%1$d is not among the supported isolation levels; "
                        + "only ISOLATION_DEFAULT (%2$d) and ISOLATION_SERIALIZABLE (%3$d) are supported.",
                isolationLevel, TransactionDefinition.ISOLATION_DEFAULT,
                TransactionDefinition.ISOLATION_SERIALIZABLE));
    }/*from   w w w . ja  va  2s .  c  om*/
}

From source file:uk.ac.ebi.phenotype.solr.indexer.AbstractIndexer.java

protected void initialiseHibernateSession(ApplicationContext applicationContext) {
    // allow hibernate session to stay open the whole execution
    PlatformTransactionManager transactionManager = (PlatformTransactionManager) applicationContext
            .getBean("transactionManager");
    DefaultTransactionAttribute transactionAttribute = new DefaultTransactionAttribute(
            TransactionDefinition.PROPAGATION_REQUIRED);
    transactionAttribute.setIsolationLevel(TransactionDefinition.ISOLATION_SERIALIZABLE);
    transactionManager.getTransaction(transactionAttribute);
}