Search in sources :

Example 11 with VTransactionWritable

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

the class BerkeleyKVStoreManagerTest method testFindAll.

@Test
public void testFindAll() {
    final List<Flower> flowers = new ListBuilder<Flower>().add(buildFlower("daisy", 60)).add(buildFlower("tulip", 100)).add(buildFlower("rose", 110)).add(buildFlower("lily", 120)).add(buildFlower("orchid", 200)).build();
    try (final VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        final List<Flower> foundFlowers = kvStoreManager.findAll("flowers", 0, null, Flower.class);
        Assert.assertTrue(foundFlowers.isEmpty());
        int i = 0;
        for (final Flower flower : flowers) {
            final String id = "" + i++;
            kvStoreManager.put("flowers", id, flower);
        }
        final List<Flower> foundFlowers2 = kvStoreManager.findAll("flowers", 0, 1000, Flower.class);
        Assert.assertEquals(flowers.size(), foundFlowers2.size());
        transaction.commit();
    }
}
Also used : Flower(io.vertigo.dynamo.kvstore.data.Flower) ListBuilder(io.vertigo.util.ListBuilder) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) AbstractKVStoreManagerTest(io.vertigo.dynamo.kvstore.AbstractKVStoreManagerTest) Test(org.junit.Test)

Example 12 with VTransactionWritable

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

the class AbstractStoreManagerTest method testGetFamilliesCars.

/**
 * Test que les listes 1N ne reste pas en cache après une mise à jour.
 * Ici l'entité en cache est la destination de la navigation : Car
 */
@Test
public void testGetFamilliesCars() {
    // on crée une famille
    final Famille famille = new Famille();
    famille.setLibelle("Ma famille");
    final DtList<Car> firstResult;
    try (final VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        final Famille createdFamille = storeManager.getDataStore().create(famille);
        // on récupère la liste des voitures
        final DtList<Car> cars = storeManager.getDataStore().findAll(allCarsUri);
        Assert.assertNotNull(cars);
        Assert.assertFalse("La liste des cars est vide", cars.isEmpty());
        // on associe la liste de voiture à la famille en 1N
        for (final Car car : cars) {
            car.setFamId(createdFamille.getFamId());
            storeManager.getDataStore().update(car);
        }
        // On garde le résultat de l'association 1N
        firstResult = createdFamille.getVoituresFamilleList();
        // On met à jour l'association en retirant le premier élément
        final Car firstCar = cars.get(0);
        firstCar.setFamId(null);
        storeManager.getDataStore().update(firstCar);
        // sans commit le cache n'est pas rafraichit
        transaction.commit();
    }
    try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        // on garde le résultat en lazy : il doit avoir le meme nombre de voiture qu'au début
        final DtList<Car> lazyResult = famille.getVoituresFamilleList();
        Assert.assertEquals("Test tailles du nombre de voiture pour une 1-N", firstResult.size(), lazyResult.size());
        // on recharge la famille et on recharge la liste issus de l'association 1N : il doit avoir une voiture de moins qu'au début
        final DtDefinition dtFamille = DtObjectUtil.findDtDefinition(Famille.class);
        final Famille famille2 = storeManager.getDataStore().readOne(new URI<Famille>(dtFamille, famille.getFamId()));
        final DtList<Car> secondResult = famille2.getVoituresFamilleList();
        Assert.assertEquals("Test tailles du nombre de voiture pour une 1-N", firstResult.size() - 1, secondResult.size());
        transaction.commit();
    }
}
Also used : Famille(io.vertigo.dynamo.store.data.domain.famille.Famille) Car(io.vertigo.dynamo.store.data.domain.car.Car) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) Test(org.junit.Test)

Example 13 with VTransactionWritable

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

the class AbstractStoreManagerTest method testSelectCarAndTestMasterDataEnum.

@Test
public void testSelectCarAndTestMasterDataEnum() {
    try (VTransactionWritable tx = transactionManager.createCurrentTransaction()) {
        final DtList<Car> dtcEssence = storeManager.getDataStore().find(DtObjectUtil.findDtDefinition(Car.class), Criterions.isEqualTo(CarFields.MTY_CD, MotorTypeEnum.essence.getEntityUri().getId()));
        // ---
        Assert.assertEquals(1, dtcEssence.size());
        Assert.assertTrue(dtcEssence.get(0).motorType().getEnumValue() == MotorTypeEnum.essence);
    }
}
Also used : Car(io.vertigo.dynamo.store.data.domain.car.Car) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) Test(org.junit.Test)

Example 14 with VTransactionWritable

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

the class AbstractStoreManagerTest method testSelectCarCachedRowMax.

@Test
public void testSelectCarCachedRowMax() {
    try (VTransactionWritable tx = transactionManager.createCurrentTransaction()) {
        final DtListURI someCars = new DtListURIForCriteria<>(dtDefinitionCar, null, 3);
        final DtList<Car> dtc1 = storeManager.getDataStore().findAll(someCars);
        Assert.assertEquals(3, dtc1.size());
        // -----
        final DtListURI allCars = new DtListURIForCriteria<>(dtDefinitionCar, null, null);
        final DtList<Car> dtc = storeManager.getDataStore().findAll(allCars);
        Assert.assertEquals(9, dtc.size());
    }
}
Also used : Car(io.vertigo.dynamo.store.data.domain.car.Car) DtListURI(io.vertigo.dynamo.domain.model.DtListURI) DtListURIForCriteria(io.vertigo.dynamo.domain.model.DtListURIForCriteria) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) Test(org.junit.Test)

Example 15 with VTransactionWritable

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

the class AbstractStoreManagerTest method testCrudCountCars.

@Test
public void testCrudCountCars() {
    try (VTransactionWritable tx = transactionManager.createCurrentTransaction()) {
        final long count = storeManager.getDataStore().count(dtDefinitionCar);
        // -----
        Assert.assertEquals(9, count);
    }
}
Also used : VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) 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