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