Search in sources :

Example 6 with DtField

use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.

the class TSMasterDataValueModel method getFieldValue.

public String getFieldValue(final String fieldName) {
    final DtField dtField = dtDefinition.getField(fieldName);
    final String camelCaseFieldName = StringUtil.constToLowerCamelCase(fieldName);
    // ---
    Assertion.when(dtField.isRequired()).check(() -> allFieldValues.containsKey(camelCaseFieldName), "Field '{0}' is required on '{1}' and no value was provided. Provided values '{2}'", fieldName, dtDefinition.getName(), allFieldValues);
    // ---
    return allFieldValues.getOrDefault(camelCaseFieldName, "null");
}
Also used : DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 7 with DtField

use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.

the class SqlMasterDataValueModel method getFieldValue.

public String getFieldValue(final String fieldName) {
    final DtField dtField = dtDefinition.getField(fieldName);
    final String camelCaseFieldName = StringUtil.constToLowerCamelCase(fieldName);
    // ---
    Assertion.when(dtField.isRequired()).check(() -> allFieldValues.containsKey(camelCaseFieldName), "Field '{0}' is required on '{1}' and no value was provided. Provided values '{2}'", fieldName, dtDefinition.getName(), allFieldValues);
    // ---
    return allFieldValues.getOrDefault(camelCaseFieldName, "null");
}
Also used : DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 8 with DtField

use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.

the class JpaDataStorePlugin method doFindAll.

private <E extends Entity> DtList<E> doFindAll(final ProcessAnalyticsTracer tracer, final DtDefinition dtDefinition, final DtListURIForNNAssociation dtcUri) {
    final Class<E> resultClass = (Class<E>) ClassUtil.classForName(dtDefinition.getClassCanonicalName());
    // PK de la DtList recherchée
    final String idFieldName = dtDefinition.getIdField().get().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 = joinDtDefinition.getIdField().get();
    // 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 = associationNode.getDtDefinition().getIdField().get();
    final String fkFieldName = fkField.getName();
    final String request = new StringBuilder(" select t.* from ").append(dtDefinition.getLocalName()).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).toString();
    final URI uri = dtcUri.getSource();
    final Query q = getEntityManager().createNativeQuery(request, resultClass);
    q.setParameter(fkFieldName, uri.getId());
    final List<E> results = q.getResultList();
    final DtList<E> dtc = new DtList<>(dtDefinition);
    dtc.addAll(results);
    tracer.setMeasure("nbSelectedRow", dtc.size());
    return dtc;
}
Also used : TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) 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) DtList(io.vertigo.dynamo.domain.model.DtList)

Example 9 with DtField

use of io.vertigo.dynamo.domain.metamodel.DtField 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 10 with DtField

use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.

the class SqlDataStorePlugin method findAll.

/**
 * {@inheritDoc}
 */
@Override
public <E extends Entity> DtList<E> findAll(final DtDefinition dtDefinition, final DtListURIForSimpleAssociation dtcUri) {
    Assertion.checkNotNull(dtDefinition);
    Assertion.checkNotNull(dtcUri);
    // ---
    final DtField fkField = dtcUri.getAssociationDefinition().getFKField();
    final Serializable value = dtcUri.getSource().getId();
    return findByCriteria(dtDefinition, Criterions.isEqualTo(fkField::getName, value), null);
}
Also used : Serializable(java.io.Serializable) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Aggregations

DtField (io.vertigo.dynamo.domain.metamodel.DtField)77 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)28 DtObject (io.vertigo.dynamo.domain.model.DtObject)14 DtList (io.vertigo.dynamo.domain.model.DtList)13 URI (io.vertigo.dynamo.domain.model.URI)12 HashMap (java.util.HashMap)11 Map (java.util.Map)8 TaskDefinition (io.vertigo.dynamo.task.metamodel.TaskDefinition)7 Task (io.vertigo.dynamo.task.model.Task)7 ArrayList (java.util.ArrayList)7 Entity (io.vertigo.dynamo.domain.model.Entity)6 TaskEngineSelect (io.vertigo.dynamox.task.TaskEngineSelect)6 Serializable (java.io.Serializable)6 LinkedHashMap (java.util.LinkedHashMap)6 List (java.util.List)6 MessageText (io.vertigo.core.locale.MessageText)5 FacetValue (io.vertigo.dynamo.collections.model.FacetValue)5 Date (java.util.Date)4 SearchHit (org.elasticsearch.search.SearchHit)4 JsonObject (com.google.gson.JsonObject)3