Search in sources :

Example 6 with DtList

use of io.vertigo.dynamo.domain.model.DtList in project vertigo by KleeGroup.

the class JpaDataStorePlugin method doFindByCriteria.

private <E extends Entity> DtList<E> doFindByCriteria(final ProcessAnalyticsTracer tracer, final DtDefinition dtDefinition, final Criteria<E> criteria, final Integer maxRows) {
    final Class<E> resultClass = (Class<E>) ClassUtil.classForName(dtDefinition.getClassCanonicalName());
    final Tuples.Tuple2<String, CriteriaCtx> tuple = criteria.toSql(sqlDataBase.getSqlDialect());
    final String tableName = getTableName(dtDefinition);
    final String request = createLoadAllLikeQuery(tableName, tuple.getVal1());
    final CriteriaCtx ctx = tuple.getVal2();
    final TypedQuery<E> q = getEntityManager().createQuery(request, resultClass);
    // IN, obligatoire
    for (final String attributeName : ctx.getAttributeNames()) {
        q.setParameter(attributeName, ctx.getAttributeValue(attributeName));
    }
    if (maxRows != null) {
        q.setMaxResults(maxRows);
    }
    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 : CriteriaCtx(io.vertigo.dynamo.criteria.CriteriaCtx) Tuples(io.vertigo.lang.Tuples) DtList(io.vertigo.dynamo.domain.model.DtList)

Example 7 with DtList

use of io.vertigo.dynamo.domain.model.DtList 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 8 with DtList

use of io.vertigo.dynamo.domain.model.DtList in project vertigo by KleeGroup.

the class ESFacetedQueryResultBuilder method build.

/**
 * {@inheritDoc}
 */
@Override
public FacetedQueryResult<I, SearchQuery> build() {
    final Map<I, Map<DtField, String>> resultHighlights = new HashMap<>();
    final Map<FacetValue, DtList<I>> resultCluster;
    final DtList<I> dtc = new DtList<>(indexDefinition.getIndexDtDefinition());
    if (searchQuery.isClusteringFacet()) {
        final Map<String, I> dtcIndex = new LinkedHashMap<>();
        resultCluster = createCluster(dtcIndex, resultHighlights);
        dtc.addAll(dtcIndex.values());
    } else {
        for (final SearchHit searchHit : queryResponse.getHits()) {
            final SearchIndex<?, I> index = esDocumentCodec.searchHit2Index(indexDefinition, searchHit);
            final I result = index.getIndexDtObject();
            dtc.add(result);
            final Map<DtField, String> highlights = createHighlight(searchHit, indexDefinition.getIndexDtDefinition());
            resultHighlights.put(result, highlights);
        }
        resultCluster = Collections.emptyMap();
    }
    // On fabrique à la volée le résultat.
    final List<Facet> facets = createFacetList(searchQuery, queryResponse);
    final long count = queryResponse.getHits().getTotalHits();
    return new FacetedQueryResult<>(searchQuery.getFacetedQuery(), count, dtc, facets, searchQuery.isClusteringFacet() ? Optional.of(searchQuery.getClusteringFacetDefinition()) : Optional.empty(), resultCluster, resultHighlights, searchQuery);
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FacetedQueryResult(io.vertigo.dynamo.collections.model.FacetedQueryResult) LinkedHashMap(java.util.LinkedHashMap) DtField(io.vertigo.dynamo.domain.metamodel.DtField) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) DtList(io.vertigo.dynamo.domain.model.DtList) Facet(io.vertigo.dynamo.collections.model.Facet)

Example 9 with DtList

use of io.vertigo.dynamo.domain.model.DtList in project vertigo by KleeGroup.

the class CollectionsManagerTest method testFilterFullTextBigList.

/**
 * Vérifie le comportement quand la recherche en commence par addresse trop de term du dictionnaire.
 * Par défaut Lucene envoi une erreur TooMany...., le collectionsManager limite aux premiers terms.
 */
@Test
public void testFilterFullTextBigList() {
    final UnaryOperator<DtList<SmartItem>> filterFunction = collectionsManager.<SmartItem>createIndexDtListFunctionBuilder().filter("a", 2000, dtDefinitionItem.getFields()).build();
    Assert.assertNotNull(filterFunction);
    final DtList<SmartItem> bigFamillyList = new DtList<>(SmartItem.class);
    for (int i = 0; i < 50000; i++) {
        final SmartItem mocka = new SmartItem();
        mocka.setId(seqId++);
        mocka.setLabel("blabla a" + (char) ('a' + i % 26) + String.valueOf(i % 100));
        bigFamillyList.add(mocka);
    }
    final DtList<SmartItem> result = filterFunction.apply(bigFamillyList);
    Assert.assertEquals(2000, result.size(), 0);
}
Also used : SmartItem(io.vertigo.dynamo.collections.data.domain.SmartItem) DtList(io.vertigo.dynamo.domain.model.DtList) Test(org.junit.Test)

Example 10 with DtList

use of io.vertigo.dynamo.domain.model.DtList in project vertigo by KleeGroup.

the class FacetManagerTest method testFacetListByTerm.

/**
 * Test le facettage par term d'une liste.
 */
@Test
public void testFacetListByTerm() {
    final DtList<SmartCar> cars = smartCarDataBase.getAllCars();
    final FacetedQuery facetedQuery = new FacetedQuery(carFacetQueryDefinition, SelectedFacetValues.empty().build());
    final FacetedQueryResult<SmartCar, DtList<SmartCar>> result = collectionsManager.facetList(cars, facetedQuery);
    testFacetResultByTerm(result);
}
Also used : SmartCar(io.vertigo.dynamo.collections.data.domain.SmartCar) FacetedQuery(io.vertigo.dynamo.collections.model.FacetedQuery) DtList(io.vertigo.dynamo.domain.model.DtList) Test(org.junit.Test)

Aggregations

DtList (io.vertigo.dynamo.domain.model.DtList)49 Test (org.junit.Test)21 FacetValue (io.vertigo.dynamo.collections.model.FacetValue)16 HashMap (java.util.HashMap)14 DtField (io.vertigo.dynamo.domain.metamodel.DtField)13 ArrayList (java.util.ArrayList)13 List (java.util.List)12 Facet (io.vertigo.dynamo.collections.model.Facet)8 FacetedQuery (io.vertigo.dynamo.collections.model.FacetedQuery)8 SearchQuery (io.vertigo.dynamo.search.model.SearchQuery)8 TaskDefinition (io.vertigo.dynamo.task.metamodel.TaskDefinition)8 Task (io.vertigo.dynamo.task.model.Task)8 Map (java.util.Map)8 FacetDefinition (io.vertigo.dynamo.collections.metamodel.FacetDefinition)7 FacetedQueryResult (io.vertigo.dynamo.collections.model.FacetedQueryResult)7 URI (io.vertigo.dynamo.domain.model.URI)7 LinkedHashMap (java.util.LinkedHashMap)7 AbstractTestCaseJU4 (io.vertigo.AbstractTestCaseJU4)6 VTransactionWritable (io.vertigo.commons.transaction.VTransactionWritable)5 ListFilter (io.vertigo.dynamo.collections.ListFilter)5