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;
}
}
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();
}
}
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;
}
}
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("*:*"));
}
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());
}
}
Aggregations