Search in sources :

Example 1 with Task

use of io.vertigo.dynamo.task.model.Task in project vertigo by KleeGroup.

the class CarSearchLoader method loadCarList.

private DtList<Car> loadCarList(final SearchChunk<Car> searchChunk) {
    final TaskDefinition taskLoadCars = getTaskLoadCarList(searchChunk);
    final Task task = Task.builder(taskLoadCars).build();
    return getTaskManager().execute(task).getResult();
}
Also used : TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Task(io.vertigo.dynamo.task.model.Task)

Example 2 with Task

use of io.vertigo.dynamo.task.model.Task in project vertigo by KleeGroup.

the class SqlDataStorePlugin method count.

/**
 * {@inheritDoc}
 */
@Override
public int count(final DtDefinition dtDefinition) {
    Assertion.checkNotNull(dtDefinition);
    Assertion.checkArgument(dtDefinition.isPersistent(), "DtDefinition is not  persistent");
    // -----
    final String tableName = getTableName(dtDefinition);
    final String taskName = TASK.TK_COUNT + "_" + tableName;
    final Domain countDomain = Domain.builder("DO_COUNT", DataType.Long).build();
    final String request = "select count(*) from " + tableName;
    final TaskDefinition taskDefinition = TaskDefinition.builder(taskName).withEngine(TaskEngineSelect.class).withDataSpace(dataSpace).withRequest(request).withOutRequired("count", countDomain).build();
    final Task task = Task.builder(taskDefinition).build();
    final Long count = taskManager.execute(task).getResult();
    return count.intValue();
}
Also used : TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Task(io.vertigo.dynamo.task.model.Task) Domain(io.vertigo.dynamo.domain.metamodel.Domain)

Example 3 with Task

use of io.vertigo.dynamo.task.model.Task in project vertigo by KleeGroup.

the class SqlDataStorePlugin method readNullableForUpdate.

/**
 * {@inheritDoc}
 */
@Override
public <E extends Entity> E readNullableForUpdate(final DtDefinition dtDefinition, final URI<?> uri) {
    final String tableName = getTableName(dtDefinition);
    final String taskName = TASK.TK_LOCK + "_" + tableName;
    final String requestedFields = getRequestedFields(dtDefinition);
    final DtField idField = getIdField(dtDefinition);
    final String idFieldName = idField.getName();
    final String request = sqlDialect.createSelectForUpdateQuery(tableName, requestedFields, idFieldName);
    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)

Example 4 with Task

use of io.vertigo.dynamo.task.model.Task in project vertigo by KleeGroup.

the class SqlDataStorePlugin method put.

/**
 * @param entity Objet à persiter
 * @param insert Si opération de type insert (update sinon)
 */
private void put(final Entity entity, final boolean insert) {
    final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(entity);
    final String tableName = getTableName(dtDefinition);
    final String taskName = (insert ? TASK.TK_INSERT : TASK.TK_UPDATE) + "_" + tableName;
    final String request = insert ? sqlDialect.createInsertQuery(dtDefinition.getIdField().get().getName(), getDataFields(dtDefinition), sequencePrefix, tableName) : createUpdateQuery(dtDefinition);
    final TaskDefinition taskDefinition = TaskDefinition.builder(taskName).withEngine(getTaskEngineClass(insert)).withDataSpace(dataSpace).withRequest(request).addInRequired("DTO", Home.getApp().getDefinitionSpace().resolve(DOMAIN_PREFIX + SEPARATOR + dtDefinition.getName() + "_DTO", Domain.class)).withOutRequired(AbstractTaskEngineSQL.SQL_ROWCOUNT, integerDomain).build();
    final Task task = Task.builder(taskDefinition).addValue("DTO", entity).build();
    final int sqlRowCount = taskManager.execute(task).getResult();
    if (sqlRowCount > 1) {
        throw new VSystemException("more than one row has been " + (insert ? "created" : "updated"));
    }
    if (sqlRowCount == 0) {
        throw new VSystemException("no data " + (insert ? "created" : "updated"));
    }
}
Also used : TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Task(io.vertigo.dynamo.task.model.Task) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) Domain(io.vertigo.dynamo.domain.metamodel.Domain) VSystemException(io.vertigo.lang.VSystemException)

Example 5 with Task

use of io.vertigo.dynamo.task.model.Task in project vertigo by KleeGroup.

the class AbstractStoreManagerTest method nativeLoadCarList.

protected final DtList<Car> nativeLoadCarList() {
    final DefinitionSpace definitionSpace = getApp().getDefinitionSpace();
    final Domain doCarList = definitionSpace.resolve("DO_DT_CAR_DTC", Domain.class);
    final TaskDefinition taskDefinition = TaskDefinition.builder("TK_LOAD_ALL_CARS").withEngine(TaskEngineSelect.class).withRequest("select * from CAR").withOutRequired("dtc", doCarList).build();
    final Task task = Task.builder(taskDefinition).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) DefinitionSpace(io.vertigo.core.definition.DefinitionSpace) Domain(io.vertigo.dynamo.domain.metamodel.Domain)

Aggregations

Task (io.vertigo.dynamo.task.model.Task)38 TaskDefinition (io.vertigo.dynamo.task.metamodel.TaskDefinition)37 VTransactionWritable (io.vertigo.commons.transaction.VTransactionWritable)22 Test (org.junit.Test)19 SuperHero (io.vertigo.dynamo.task.data.domain.SuperHero)17 Domain (io.vertigo.dynamo.domain.metamodel.Domain)9 TaskEngineSelect (io.vertigo.dynamox.task.TaskEngineSelect)9 DtList (io.vertigo.dynamo.domain.model.DtList)8 DtField (io.vertigo.dynamo.domain.metamodel.DtField)5 TaskEngineProc (io.vertigo.dynamox.task.TaskEngineProc)5 DefinitionSpace (io.vertigo.core.definition.DefinitionSpace)3 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)3 TaskResult (io.vertigo.dynamo.task.model.TaskResult)3 URI (io.vertigo.dynamo.domain.model.URI)2 TaskEngineProcBatch (io.vertigo.dynamox.task.TaskEngineProcBatch)2 VSystemException (io.vertigo.lang.VSystemException)2 ArrayList (java.util.ArrayList)2 AbstractTestCaseJU4 (io.vertigo.AbstractTestCaseJU4)1 MetricBuilder (io.vertigo.commons.analytics.metric.MetricBuilder)1 Transactional (io.vertigo.commons.transaction.Transactional)1