Search in sources :

Example 26 with TaskDefinition

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

the class SqlDataStorePlugin method delete.

/**
 * {@inheritDoc}
 */
@Override
public void delete(final DtDefinition dtDefinition, final URI uri) {
    Assertion.checkNotNull(dtDefinition);
    Assertion.checkNotNull(uri);
    // ---
    final DtField idField = getIdField(dtDefinition);
    final String tableName = getTableName(dtDefinition);
    final String taskName = TASK.TK_DELETE + "_" + tableName;
    final String idFieldName = idField.getName();
    final String request = new StringBuilder().append("delete from ").append(tableName).append(" where ").append(idFieldName).append(" = #").append(idFieldName).append('#').toString();
    final TaskDefinition taskDefinition = TaskDefinition.builder(taskName).withEngine(TaskEngineProc.class).withDataSpace(dataSpace).withRequest(request).addInRequired(idFieldName, idField.getDomain()).withOutRequired(AbstractTaskEngineSQL.SQL_ROWCOUNT, integerDomain).build();
    final Task task = Task.builder(taskDefinition).addValue(idFieldName, uri.getId()).build();
    final int sqlRowCount = taskManager.execute(task).getResult();
    if (sqlRowCount > 1) {
        throw new VSystemException("more than one row has been deleted");
    } else if (sqlRowCount == 0) {
        throw new VSystemException("no row has been deleted");
    }
}
Also used : TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Task(io.vertigo.dynamo.task.model.Task) TaskEngineProc(io.vertigo.dynamox.task.TaskEngineProc) VSystemException(io.vertigo.lang.VSystemException) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 27 with TaskDefinition

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

the class SqlDataStorePlugin method findAll.

/**
 * {@inheritDoc}
 */
@Override
public <E extends Entity> DtList<E> findAll(final DtDefinition dtDefinition, final DtListURIForNNAssociation dtcUri) {
    Assertion.checkNotNull(dtDefinition);
    Assertion.checkNotNull(dtcUri);
    // -----
    final String tableName = getTableName(dtDefinition);
    final String taskName = TASK.TK_SELECT + "_N_N_LIST_" + tableName + "_BY_URI";
    // PK de la DtList recherchée
    final String idFieldName = getIdField(dtDefinition).getName();
    // FK dans la table nn correspondant à la collection recherchée. (clé de jointure ).
    final AssociationNNDefinition associationNNDefinition = dtcUri.getAssociationDefinition();
    final String joinTableName = associationNNDefinition.getTableName();
    final DtDefinition joinDtDefinition = AssociationUtil.getAssociationNode(associationNNDefinition, dtcUri.getRoleName()).getDtDefinition();
    final DtField joinDtField = getIdField(joinDtDefinition);
    // La condition s'applique sur l'autre noeud de la relation (par rapport à la collection attendue)
    final AssociationNode associationNode = AssociationUtil.getAssociationNodeTarget(associationNNDefinition, dtcUri.getRoleName());
    final DtField fkField = getIdField(associationNode.getDtDefinition());
    final String fkFieldName = fkField.getName();
    final String request = new StringBuilder(" select t.* from ").append(tableName).append(" t").append(" join ").append(joinTableName).append(" j on j.").append(joinDtField.getName()).append(" = t.").append(idFieldName).append(" where j.").append(fkFieldName).append(" = #").append(fkFieldName).append('#').toString();
    final TaskDefinition taskDefinition = TaskDefinition.builder(taskName).withEngine(TaskEngineSelect.class).withDataSpace(dataSpace).withRequest(request).addInRequired(fkFieldName, fkField.getDomain()).withOutRequired("dtc", Home.getApp().getDefinitionSpace().resolve(DOMAIN_PREFIX + SEPARATOR + dtDefinition.getName() + "_DTC", Domain.class)).build();
    final URI uri = dtcUri.getSource();
    final Task task = Task.builder(taskDefinition).addValue(fkFieldName, 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) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) URI(io.vertigo.dynamo.domain.model.URI) AssociationNNDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition) DtField(io.vertigo.dynamo.domain.metamodel.DtField) AssociationNode(io.vertigo.dynamo.domain.metamodel.association.AssociationNode)

Example 28 with TaskDefinition

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

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

the class TaskGeneratorPlugin method buildPackageMap.

private static Map<String, List<TaskDefinition>> buildPackageMap() {
    final Collection<TaskDefinition> taskDefinitions = Home.getApp().getDefinitionSpace().getAll(TaskDefinition.class);
    final Map<String, List<TaskDefinition>> taskDefinitionsMap = new LinkedHashMap<>();
    // ---
    for (final TaskDefinition taskDefinition : taskDefinitions) {
        final TaskDefinitionModel templateTaskDefinition = new TaskDefinitionModel(taskDefinition);
        final DtDefinition dtDefinition = getDtDefinition(templateTaskDefinition);
        // Correction bug : task avec retour DtObject (non persistant) non générée
        // Les taches sont générées dans les pao
        // - si il n'esxiste pas de définition associées à la tache
        // - ou si la définition est considérée comme non persistante.
        final boolean pao = dtDefinition == null || !dtDefinition.isPersistent();
        if (pao) {
            // La tache est liée au package. (PAO)
            final List<TaskDefinition> list = taskDefinitionsMap.computeIfAbsent(taskDefinition.getPackageName(), k -> new ArrayList<>());
            // on ajoute la tache aux taches du package.
            list.add(taskDefinition);
        }
    }
    return taskDefinitionsMap;
}
Also used : TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) ArrayList(java.util.ArrayList) List(java.util.List) TaskDefinitionModel(io.vertigo.studio.plugins.mda.task.model.TaskDefinitionModel) LinkedHashMap(java.util.LinkedHashMap)

Example 30 with TaskDefinition

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

the class SqlUtil method execRequests.

public static void execRequests(final VTransactionManager transactionManager, final TaskManager taskManager, final List<String> requests, final String taskName, final Optional<String> optDataSpace) {
    // A chaque test on recrée la table famille
    try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        for (final String request : requests) {
            final TaskDefinition taskDefinition = TaskDefinition.builder(taskName).withEngine(TaskEngineProc.class).withRequest(request).withDataSpace(optDataSpace.orElse(null)).build();
            final Task task = Task.builder(taskDefinition).build();
            taskManager.execute(task);
        }
        transaction.commit();
    }
}
Also used : TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Task(io.vertigo.dynamo.task.model.Task) TaskEngineProc(io.vertigo.dynamox.task.TaskEngineProc) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable)

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