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