Search in sources :

Example 21 with TaskDefinition

use of io.vertigo.dynamo.task.metamodel.TaskDefinition in project vertigo by KleeGroup.

the class TaskEngineSelectDynamicTest method testTrim.

/**
 * Test du preprocessor trim.
 * Note: nous n'avons pas accès à la chaine trimée, on check juste que la requete est valide.
 */
@Test
public void testTrim() {
    try (final VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        final TaskDefinition taskDefinition = registerTaskObject("TK_SCRIPT_TEST", "select * from SUPER_HERO  \n<%if(false) {%>\nwhere ID = #DTO_SUPER_HERO.ID#\n<%}%>\n");
        final SuperHero superHero = new SuperHero();
        superHero.setId(10001L + 1);
        final Task task = Task.builder(taskDefinition).addValue(DTO_SUPER_HERO, superHero).build();
        final DtList<SuperHero> resultList = taskManager.execute(task).getResult();
        Assert.assertEquals(10, resultList.size());
    }
}
Also used : SuperHero(io.vertigo.dynamo.task.data.domain.SuperHero) TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Task(io.vertigo.dynamo.task.model.Task) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) Test(org.junit.Test)

Example 22 with TaskDefinition

use of io.vertigo.dynamo.task.metamodel.TaskDefinition in project vertigo by KleeGroup.

the class TaskEngineSelectDynamicTest method testWhereIn2200.

/**
 * Test where in avec 2200 Id a inclure.
 */
@Test
public void testWhereIn2200() {
    superHeroDataBase.populateSuperHero(storeManager, 4500);
    try (final VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        final TaskDefinition taskDefinition = registerTaskList("TK_WHERE_ID_TEST", "select * from SUPER_HERO  where ID in (#DTC_SUPER_HERO_IN.ROWNUM.ID#)");
        final DtList<SuperHero> ids = new DtList<>(SuperHero.class);
        for (int i = 0; i < 2200; i++) {
            ids.add(createSuperHero(10001L + 2 * i));
        }
        final Task task = Task.builder(taskDefinition).addValue(DTC_SUPER_HERO_IN, ids).build();
        final DtList<SuperHero> resultList = taskManager.execute(task).getResult();
        Assert.assertEquals(2200, resultList.size());
    }
}
Also used : SuperHero(io.vertigo.dynamo.task.data.domain.SuperHero) TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Task(io.vertigo.dynamo.task.model.Task) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) DtList(io.vertigo.dynamo.domain.model.DtList) Test(org.junit.Test)

Example 23 with TaskDefinition

use of io.vertigo.dynamo.task.metamodel.TaskDefinition in project vertigo by KleeGroup.

the class TaskEngineSelectDynamicTest method testWhereInTab.

/**
 * Test exécution d'une tache.
 */
@Test
public void testWhereInTab() {
    try (final VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        final TaskDefinition taskDefinition = registerTaskList("TK_WHERE_ID_TEST", "select * from SUPER_HERO  where\tID in\t(#DTC_SUPER_HERO_IN.ROWNUM.ID#)");
        final DtList<SuperHero> ids = DtList.of(createSuperHero(10001L + 1), createSuperHero(10001L + 3));
        final Task task = Task.builder(taskDefinition).addValue(DTC_SUPER_HERO_IN, ids).build();
        final DtList<SuperHero> resultList = taskManager.execute(task).getResult();
        Assert.assertEquals(2, resultList.size());
        Assert.assertEquals(10001L + 1, resultList.get(0).getId().longValue());
        Assert.assertEquals(10001L + 3, resultList.get(1).getId().longValue());
    }
}
Also used : SuperHero(io.vertigo.dynamo.task.data.domain.SuperHero) TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Task(io.vertigo.dynamo.task.model.Task) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) Test(org.junit.Test)

Example 24 with TaskDefinition

use of io.vertigo.dynamo.task.metamodel.TaskDefinition in project vertigo by KleeGroup.

the class TaskEngineSelectDynamicTest method testScriptVar.

/**
 * Test des scripts.
 */
@Test
public void testScriptVar() {
    try (final VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        final TaskDefinition taskDefinition = registerTaskObject("TK_SCRIPT_TEST", "select * from SUPER_HERO <%if(dtoSuperHero.getId() == 10002L) {%>where ID = #DTO_SUPER_HERO.ID#<%}%>");
        final SuperHero superHero = new SuperHero();
        superHero.setId(10001L + 1);
        final Task task = Task.builder(taskDefinition).addValue(DTO_SUPER_HERO, superHero).build();
        final DtList<SuperHero> resultList = taskManager.execute(task).getResult();
        Assert.assertEquals(1, resultList.size());
        Assert.assertEquals(10001L + 1, resultList.get(0).getId().longValue());
    }
}
Also used : SuperHero(io.vertigo.dynamo.task.data.domain.SuperHero) TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Task(io.vertigo.dynamo.task.model.Task) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) Test(org.junit.Test)

Example 25 with TaskDefinition

use of io.vertigo.dynamo.task.metamodel.TaskDefinition in project vertigo by KleeGroup.

the class SqlDataStorePlugin method readNullable.

/**
 * {@inheritDoc}
 */
@Override
public <E extends Entity> E readNullable(final DtDefinition dtDefinition, final URI<E> uri) {
    final String tableName = getTableName(dtDefinition);
    final String taskName = TASK.TK_SELECT + "_" + dtDefinition.getLocalName() + "_BY_URI";
    final String requestedFields = getRequestedFields(dtDefinition);
    final DtField idField = getIdField(dtDefinition);
    final String idFieldName = idField.getName();
    final String request = new StringBuilder().append(" select ").append(requestedFields).append(" from ").append(tableName).append(" where ").append(idFieldName).append(" = #").append(idFieldName).append('#').toString();
    final TaskDefinition taskDefinition = TaskDefinition.builder(taskName).withEngine(TaskEngineSelect.class).withDataSpace(dataSpace).withRequest(request).addInRequired(idFieldName, idField.getDomain()).withOutOptional("dto", Home.getApp().getDefinitionSpace().resolve(DOMAIN_PREFIX + SEPARATOR + uri.getDefinition().getName() + "_DTO", Domain.class)).build();
    final Task task = Task.builder(taskDefinition).addValue(idFieldName, uri.getId()).build();
    return taskManager.execute(task).getResult();
}
Also used : TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Task(io.vertigo.dynamo.task.model.Task) TaskEngineSelect(io.vertigo.dynamox.task.TaskEngineSelect) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Aggregations

TaskDefinition (io.vertigo.dynamo.task.metamodel.TaskDefinition)52 Task (io.vertigo.dynamo.task.model.Task)39 Test (org.junit.Test)26 VTransactionWritable (io.vertigo.commons.transaction.VTransactionWritable)24 SuperHero (io.vertigo.dynamo.task.data.domain.SuperHero)17 Domain (io.vertigo.dynamo.domain.metamodel.Domain)11 TaskEngineSelect (io.vertigo.dynamox.task.TaskEngineSelect)11 DtList (io.vertigo.dynamo.domain.model.DtList)10 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)7 DefinitionSpace (io.vertigo.core.definition.DefinitionSpace)6 TaskEngineProc (io.vertigo.dynamox.task.TaskEngineProc)6 ArrayList (java.util.ArrayList)6 DtField (io.vertigo.dynamo.domain.metamodel.DtField)5 List (java.util.List)5 URI (io.vertigo.dynamo.domain.model.URI)4 VTransactionManager (io.vertigo.commons.transaction.VTransactionManager)3 TaskManager (io.vertigo.dynamo.task.TaskManager)3 TaskResult (io.vertigo.dynamo.task.model.TaskResult)3 Collectors (java.util.stream.Collectors)3 Inject (javax.inject.Inject)3