Search in sources :

Example 46 with VTransactionWritable

use of io.vertigo.commons.transaction.VTransactionWritable in project vertigo by KleeGroup.

the class AccountManagerTest method testGroups.

@Test
public void testGroups() {
    try (VTransactionWritable tx = obtainTx()) {
        // Assert.assertEquals(2, identityManager.getGroupsCount());
        // ----
        Assert.assertEquals(1, accountManager.getGroupURIs(accountURI0).size());
        if (!database) {
            Assert.assertEquals(2, accountManager.getGroupURIs(accountURI1).size());
            Assert.assertEquals(2, accountManager.getGroupURIs(accountURI2).size());
        }
        Assert.assertEquals(2, accountManager.getAccountURIs(groupURI).size());
        Assert.assertEquals(database ? 8 : 10 + 4, accountManager.getAccountURIs(groupAllURI).size());
    // ---
    /*identityManager.attach(accountURI0, groupURI);
			Assert.assertEquals(2, identityManager.getGroupURIs(accountURI0).size());
			Assert.assertEquals(2, identityManager.getGroupURIs(accountURI1).size());
			Assert.assertEquals(2, identityManager.getGroupURIs(accountURI2).size());
			Assert.assertEquals(3, identityManager.getAccountURIs(groupURI).size());
			Assert.assertEquals(10 + 3, identityManager.getAccountURIs(groupAllURI).size());*/
    }
}
Also used : VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) Test(org.junit.Test)

Example 47 with VTransactionWritable

use of io.vertigo.commons.transaction.VTransactionWritable in project vertigo by KleeGroup.

the class SqlUtil method execRequests.

public static void execRequests(final VTransactionManager transactionManager, final TaskManager taskManager, final List<String> requests, final String taskName, final Optional<String> optDataSpace) {
    // A chaque test on recrée la table famille
    try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        for (final String request : requests) {
            final TaskDefinition taskDefinition = TaskDefinition.builder(taskName).withEngine(TaskEngineProc.class).withRequest(request).withDataSpace(optDataSpace.orElse(null)).build();
            final Task task = Task.builder(taskDefinition).build();
            taskManager.execute(task);
        }
        transaction.commit();
    }
}
Also used : TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Task(io.vertigo.dynamo.task.model.Task) TaskEngineProc(io.vertigo.dynamox.task.TaskEngineProc) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable)

Example 48 with VTransactionWritable

use of io.vertigo.commons.transaction.VTransactionWritable in project vertigo by KleeGroup.

the class VTransactionAspect method invoke.

@Override
public Object invoke(final Object[] args, final AspectMethodInvocation methodInvocation) {
    // La transaction est REQUIRED : si elle existe on l'utilise, sinon on la crée.
    if (transactionManager.hasCurrentTransaction()) {
        return methodInvocation.proceed(args);
    }
    // Dans le cas ou il n'existe pas de transaction on en crée une.
    try (final VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        final Object o = methodInvocation.proceed(args);
        transaction.commit();
        return o;
    }
}
Also used : VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable)

Example 49 with VTransactionWritable

use of io.vertigo.commons.transaction.VTransactionWritable in project vertigo by KleeGroup.

the class AbstractKVStoreManagerTest method testFind.

@Test
public void testFind() {
    try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        final Optional<Flower> foundFlower = kvStoreManager.find("flowers", "1", Flower.class);
        Assert.assertEquals(Optional.empty(), foundFlower);
        final Flower tulip = buildFlower("tulip", 100);
        kvStoreManager.put("flowers", "1", tulip);
        final Optional<Flower> foundFlower2 = kvStoreManager.find("flowers", "1", Flower.class);
        Assert.assertTrue(foundFlower2.isPresent());
        Assert.assertEquals("tulip", foundFlower2.get().getName());
        // "Price must be excatly 100",
        Assert.assertEquals(100d, foundFlower2.get().getPrice(), 0);
    }
}
Also used : Flower(io.vertigo.dynamo.kvstore.data.Flower) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) Test(org.junit.Test)

Example 50 with VTransactionWritable

use of io.vertigo.commons.transaction.VTransactionWritable in project vertigo by KleeGroup.

the class BerkeleyKVStoreManagerTest method testRollback.

@Test(expected = RuntimeException.class)
public void testRollback() {
    try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        final Flower tulip = buildFlower("tulip", 100);
        kvStoreManager.put("flowers", "1", tulip);
        transaction.commit();
    }
    final Optional<Flower> flower1 = kvStoreManager.find("flowers", "1", Flower.class);
    Assert.assertTrue("Flower id 1 not found", flower1.isPresent());
    final Optional<Flower> flower2 = kvStoreManager.find("flowers", "2", Flower.class);
    Assert.assertFalse("There is already a flower id 2", flower2.isPresent());
    try {
        try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
            final Flower tulip = buildFlower("rose", 100);
            kvStoreManager.put("flowers", "2", tulip);
            throw new VSystemException("Error");
        }
    } catch (final RuntimeException e) {
    // on doit passer par là
    }
    final Optional<Flower> flower2bis = kvStoreManager.find("flowers", "2", Flower.class);
    Assert.assertFalse("Rollback flower id 2 failed", flower2bis.isPresent());
}
Also used : Flower(io.vertigo.dynamo.kvstore.data.Flower) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) VSystemException(io.vertigo.lang.VSystemException) AbstractKVStoreManagerTest(io.vertigo.dynamo.kvstore.AbstractKVStoreManagerTest) Test(org.junit.Test)

Aggregations

VTransactionWritable (io.vertigo.commons.transaction.VTransactionWritable)80 Test (org.junit.Test)63 Car (io.vertigo.dynamo.store.data.domain.car.Car)22 TaskDefinition (io.vertigo.dynamo.task.metamodel.TaskDefinition)22 Task (io.vertigo.dynamo.task.model.Task)22 SuperHero (io.vertigo.dynamo.task.data.domain.SuperHero)18 DtList (io.vertigo.dynamo.domain.model.DtList)7 Flower (io.vertigo.dynamo.kvstore.data.Flower)6 Famille (io.vertigo.dynamo.store.data.domain.famille.Famille)6 SqlConnection (io.vertigo.database.sql.connection.SqlConnection)5 DtListURI (io.vertigo.dynamo.domain.model.DtListURI)5 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)4 DtListURIForCriteria (io.vertigo.dynamo.domain.model.DtListURIForCriteria)4 URI (io.vertigo.dynamo.domain.model.URI)4 Item (io.vertigo.dynamo.search.data.domain.Item)4 SearchIndexDefinition (io.vertigo.dynamo.search.metamodel.SearchIndexDefinition)4 Car (io.vertigo.dynamo.search_2_4.data.domain.Car)4 TaskEngineSelect (io.vertigo.dynamox.task.TaskEngineSelect)4 ArrayList (java.util.ArrayList)4 Domain (io.vertigo.dynamo.domain.metamodel.Domain)3