Search in sources :

Example 41 with DtField

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

the class SqlDataStorePlugin method createUpdateQuery.

/**
 * Creates the update request.
 *
 * @param dtDefinition the dtDefinition
 * @return the sql request
 */
private static String createUpdateQuery(final DtDefinition dtDefinition) {
    final String tableName = getTableName(dtDefinition);
    final DtField idField = getIdField(dtDefinition);
    return new StringBuilder().append("update ").append(tableName).append(" set ").append(dtDefinition.getFields().stream().filter(dtField -> dtField.isPersistent() && !dtField.getType().isId()).map(dtField -> dtField.getName() + " =#DTO." + dtField.getName() + '#').collect(Collectors.joining(", "))).append(" where ").append(idField.getName()).append(" = #DTO.").append(idField.getName()).append('#').toString();
}
Also used : AssociationNode(io.vertigo.dynamo.domain.metamodel.association.AssociationNode) DtListURIForNNAssociation(io.vertigo.dynamo.domain.metamodel.association.DtListURIForNNAssociation) TaskBuilder(io.vertigo.dynamo.task.model.TaskBuilder) CriteriaCtx(io.vertigo.dynamo.criteria.CriteriaCtx) DtField(io.vertigo.dynamo.domain.metamodel.DtField) TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) URI(io.vertigo.dynamo.domain.model.URI) DtObjectUtil(io.vertigo.dynamo.domain.util.DtObjectUtil) TaskEngine(io.vertigo.dynamo.task.model.TaskEngine) VSystemException(io.vertigo.lang.VSystemException) Criteria(io.vertigo.dynamo.criteria.Criteria) Task(io.vertigo.dynamo.task.model.Task) SqlDialect(io.vertigo.database.sql.vendor.SqlDialect) Inject(javax.inject.Inject) Home(io.vertigo.app.Home) StoreManager(io.vertigo.dynamo.store.StoreManager) Criterions(io.vertigo.dynamo.criteria.Criterions) DtListURIForSimpleAssociation(io.vertigo.dynamo.domain.metamodel.association.DtListURIForSimpleAssociation) AssociationUtil(io.vertigo.dynamo.domain.util.AssociationUtil) Assertion(io.vertigo.lang.Assertion) AssociationNNDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition) Named(javax.inject.Named) DataStorePlugin(io.vertigo.dynamo.impl.store.datastore.DataStorePlugin) DataType(io.vertigo.dynamo.domain.metamodel.DataType) TaskDefinitionBuilder(io.vertigo.dynamo.task.metamodel.TaskDefinitionBuilder) Tuples(io.vertigo.lang.Tuples) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) Domain(io.vertigo.dynamo.domain.metamodel.Domain) DtList(io.vertigo.dynamo.domain.model.DtList) TaskEngineInsertWithGeneratedKeys(io.vertigo.dynamox.task.sqlserver.TaskEngineInsertWithGeneratedKeys) Collectors(java.util.stream.Collectors) Definition(io.vertigo.core.definition.Definition) Serializable(java.io.Serializable) SqlDataBaseManager(io.vertigo.database.sql.SqlDataBaseManager) List(java.util.List) Entity(io.vertigo.dynamo.domain.model.Entity) DefinitionUtil(io.vertigo.core.definition.DefinitionUtil) TaskManager(io.vertigo.dynamo.task.TaskManager) AbstractTaskEngineSQL(io.vertigo.dynamox.task.AbstractTaskEngineSQL) TaskEngineSelect(io.vertigo.dynamox.task.TaskEngineSelect) Optional(java.util.Optional) TaskEngineProc(io.vertigo.dynamox.task.TaskEngineProc) DtListURIForCriteria(io.vertigo.dynamo.domain.model.DtListURIForCriteria) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 42 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 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 43 with DtField

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

the class AbstractDbFileStorePlugin method setIdValue.

/**
 * @param dto DtObject
 * @param value Pk value
 */
protected static void setIdValue(final DtObject dto, final Object value) {
    final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(dto);
    final DtField idField = dtDefinition.getIdField().get();
    idField.getDataAccessor().setValue(dto, value);
}
Also used : DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 44 with DtField

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

the class FsFileStorePlugin method setValue.

/**
 * Fixe une valeur d'un champ d'un DtObject.
 *
 * @param dto DtObject
 * @param field Nom du champs
 * @param value Valeur
 */
private static void setValue(final DtObject dto, final DtoFields field, final Object value) {
    final DtField dtField = DtObjectUtil.findDtDefinition(dto).getField(field.name());
    dtField.getDataAccessor().setValue(dto, value);
}
Also used : DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 45 with DtField

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

the class CollectionsManagerTest method testFilterFullTextElision.

@Test
public void testFilterFullTextElision() {
    final DtList<SmartItem> dtc = createItems();
    final Collection<DtField> searchedDtFields = dtDefinitionItem.getFields();
    final SmartItem mock1 = new SmartItem();
    mock1.setId(seqId++);
    mock1.setLabel("Agence de l'Ouest");
    dtc.add(mock1);
    final SmartItem mock2 = new SmartItem();
    mock2.setId(seqId++);
    mock2.setLabel("Hôpital et autres accents çava où àpied");
    dtc.add(mock2);
    Assert.assertTrue("La recherche ne supporte pas l'elision", filter(dtc, "ouest", 1000, searchedDtFields).size() == 1);
}
Also used : SmartItem(io.vertigo.dynamo.collections.data.domain.SmartItem) DtField(io.vertigo.dynamo.domain.metamodel.DtField) Test(org.junit.Test)

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