Search in sources :

Example 6 with TaskDefinition

use of io.vertigo.dynamo.task.metamodel.TaskDefinition 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 7 with TaskDefinition

use of io.vertigo.dynamo.task.metamodel.TaskDefinition 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 8 with TaskDefinition

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

the class DomainMetricsProvider method countTaskDependencies.

private static double countTaskDependencies(final Domain domain) {
    Assertion.checkNotNull(domain);
    // ---
    int count = 0;
    for (final TaskDefinition taskDefinition : Home.getApp().getDefinitionSpace().getAll(TaskDefinition.class)) {
        for (final TaskAttribute taskAttribute : taskDefinition.getInAttributes()) {
            if (domain.equals(taskAttribute.getDomain())) {
                count++;
            }
        }
        if (taskDefinition.getOutAttributeOption().isPresent()) {
            if (domain.equals(taskDefinition.getOutAttributeOption().get().getDomain())) {
                count++;
            }
        }
    }
    return count;
}
Also used : TaskAttribute(io.vertigo.dynamo.task.metamodel.TaskAttribute) TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition)

Example 9 with TaskDefinition

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

the class DomainMetricsProvider method countTaskDependencies.

private static double countTaskDependencies(final DtDefinition dtDefinition) {
    int count = 0;
    for (final TaskDefinition taskDefinition : Home.getApp().getDefinitionSpace().getAll(TaskDefinition.class)) {
        for (final TaskAttribute taskAttribute : taskDefinition.getInAttributes()) {
            count += count(dtDefinition, taskAttribute);
        }
        if (taskDefinition.getOutAttributeOption().isPresent()) {
            final TaskAttribute taskAttribute = taskDefinition.getOutAttributeOption().get();
            count += count(dtDefinition, taskAttribute);
        }
    }
    return count;
}
Also used : TaskAttribute(io.vertigo.dynamo.task.metamodel.TaskAttribute) TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition)

Example 10 with TaskDefinition

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

the class BrokerNNImpl method processNN.

private int processNN(final String taskDefinitionName, final String request, final String dataSpace, final DtField sourceField, final Object sourceValue, final DtField targetField, final Object targetValue) {
    // FieldName
    final String sourceFieldName = sourceField.getName();
    final TaskDefinitionBuilder taskDefinitionBuilder = TaskDefinition.builder(taskDefinitionName).withEngine(TaskEngineProc.class).withDataSpace(dataSpace).withRequest(request).addInRequired(sourceFieldName, sourceField.getDomain());
    if (targetField != null) {
        taskDefinitionBuilder.addInRequired(targetField.getName(), targetField.getDomain());
    }
    // OUT, obligatoire
    final TaskDefinition taskDefinition = taskDefinitionBuilder.withOutRequired(AbstractTaskEngineSQL.SQL_ROWCOUNT, integerDomain).build();
    /* Création de la tache. */
    final TaskBuilder taskBuilder = Task.builder(taskDefinition).addValue(sourceFieldName, sourceValue);
    if (targetField != null) {
        taskBuilder.addValue(targetField.getName(), targetValue);
    }
    return taskManager.execute(taskBuilder.build()).getResult();
}
Also used : TaskBuilder(io.vertigo.dynamo.task.model.TaskBuilder) TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) TaskEngineProc(io.vertigo.dynamox.task.TaskEngineProc) TaskDefinitionBuilder(io.vertigo.dynamo.task.metamodel.TaskDefinitionBuilder)

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