Search in sources :

Example 41 with VTransactionWritable

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

the class AbstractSqlSearchLoader method loadNextURI.

/**
 * {@inheritDoc}
 */
@Override
@Transactional
protected final List<URI<S>> loadNextURI(final P lastId, final DtDefinition dtDefinition) {
    try (final VTransactionWritable tx = transactionManager.createCurrentTransaction()) {
        final String tableName = getTableName(dtDefinition);
        final String taskName = "TK_SELECT_" + tableName + "_NEXT_SEARCH_CHUNK";
        final DtField idField = dtDefinition.getIdField().get();
        final String idFieldName = idField.getName();
        final String request = getNextIdsSqlQuery(tableName, idFieldName);
        final TaskDefinition taskDefinition = TaskDefinition.builder(taskName).withEngine(TaskEngineSelect.class).withDataSpace(dtDefinition.getDataSpace()).withRequest(request).addInRequired(idFieldName, idField.getDomain()).withOutRequired("dtc", Home.getApp().getDefinitionSpace().resolve(DOMAIN_PREFIX + SEPARATOR + dtDefinition.getName() + "_DTC", Domain.class)).build();
        final Task task = Task.builder(taskDefinition).addValue(idFieldName, lastId).build();
        final DtList<S> resultDtc = taskManager.execute(task).getResult();
        final List<URI<S>> uris = new ArrayList<>(resultDtc.size());
        for (final S dto : resultDtc) {
            uris.add(new URI<S>(dtDefinition, DtObjectUtil.getId(dto)));
        }
        return uris;
    }
}
Also used : TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Task(io.vertigo.dynamo.task.model.Task) TaskEngineSelect(io.vertigo.dynamox.task.TaskEngineSelect) ArrayList(java.util.ArrayList) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) URI(io.vertigo.dynamo.domain.model.URI) DtField(io.vertigo.dynamo.domain.metamodel.DtField) Transactional(io.vertigo.commons.transaction.Transactional)

Example 42 with VTransactionWritable

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

the class SqlCriteriaTest method initMainStore.

private void initMainStore() {
    // A chaque test on recrée la table famille
    SqlUtil.execRequests(transactionManager, taskManager, getCreateMovies(), "TK_INIT_MAIN", Optional.empty());
    final Movie2DataBase movie2DataBase = new Movie2DataBase();
    try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        movie2DataBase.getAllMovies().forEach(movie2 -> storeManager.getDataStore().create(movie2));
        transaction.commit();
    }
}
Also used : VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) Movie2DataBase(io.vertigo.dynamo.criteria.data.movies.Movie2DataBase)

Example 43 with VTransactionWritable

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

the class CarSearchLoader method loadData.

/**
 * {@inheritDoc}
 */
@Override
public List<SearchIndex<Car, Car>> loadData(final SearchChunk<Car> searchChunk) {
    final SearchIndexDefinition indexDefinition = searchManager.findFirstIndexDefinitionByKeyConcept(Car.class);
    try (final VTransactionWritable tx = getTransactionManager().createCurrentTransaction()) {
        final List<SearchIndex<Car, Car>> result = new ArrayList<>();
        final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(Car.class);
        for (final Car car : loadCarList(searchChunk)) {
            final URI<Car> uri = new URI<>(dtDefinition, car.getId());
            result.add(SearchIndex.createIndex(indexDefinition, uri, car));
        }
        return result;
    }
}
Also used : Car(io.vertigo.dynamo.search_2_4.data.domain.Car) SearchIndexDefinition(io.vertigo.dynamo.search.metamodel.SearchIndexDefinition) SearchIndex(io.vertigo.dynamo.search.model.SearchIndex) ArrayList(java.util.ArrayList) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) URI(io.vertigo.dynamo.domain.model.URI)

Example 44 with VTransactionWritable

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

the class SearchManagerStoreTest method testIndexDeleteData.

/**
 * Test de mise à jour de l'index après une creation.
 * La création s'effectue dans une seule transaction.
 */
@Test
public void testIndexDeleteData() {
    testIndexAllQuery();
    Assert.assertEquals(1, query("ID:10001"));
    try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        storeManager.getDataStore().delete(createURI(10001L));
        transaction.commit();
    }
    waitIndexation();
    Assert.assertEquals(0, query("ID:10001"));
    Assert.assertEquals(initialDbCarSize - 1, query("*:*"));
}
Also used : VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) Test(org.junit.Test)

Example 45 with VTransactionWritable

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

the class AccountManagerTest method testLoginFail.

@Test
public void testLoginFail() {
    try (VTransactionWritable tx = obtainTx()) {
        final Optional<Account> account = accountManager.getAccountByAuthToken("test");
        Assert.assertFalse("Shouldn't found any account with a bad login", account.isPresent());
    }
}
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