Search in sources :

Example 21 with Query

use of org.springframework.data.mongodb.core.query.Query in project commons-dao by reportportal.

the class ReportPortalRepositoryImpl method findByFilterWithSorting.

@Override
public List<T> findByFilterWithSorting(Queryable filter, Sort sorting) {
    Class<T> entityType = getEntityInformation().getJavaType();
    Query query = QueryBuilder.newBuilder().with(filter).with(sorting).build();
    return getMongoOperations().find(query, entityType);
}
Also used : Query(org.springframework.data.mongodb.core.query.Query)

Example 22 with Query

use of org.springframework.data.mongodb.core.query.Query in project commons-dao by reportportal.

the class ShareableRepositoryImpl method findOnlyOwnedEntities.

@SuppressWarnings("unchecked")
@Override
public List<T> findOnlyOwnedEntities(Set<String> ids, String owner) {
    if (owner == null) {
        return emptyList();
    }
    Query query = createOwnedEntityQuery(owner);
    if (Preconditions.NOT_EMPTY_COLLECTION.test(ids)) {
        query.addCriteria(Criteria.where(Shareable.ID).in(ids));
    }
    Class<T> entityType = getEntityInformation().getJavaType();
    return getMongoOperations().find(query, entityType);
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) ShareableRepositoryUtils.createSharedEntityQuery(com.epam.ta.reportportal.database.dao.ShareableRepositoryUtils.createSharedEntityQuery) ShareableRepositoryUtils.createOwnedEntityQuery(com.epam.ta.reportportal.database.dao.ShareableRepositoryUtils.createOwnedEntityQuery)

Example 23 with Query

use of org.springframework.data.mongodb.core.query.Query in project commons-dao by reportportal.

the class ShareableRepositoryImpl method findSharedEntities.

@SuppressWarnings("unchecked")
@Override
public Page<T> findSharedEntities(String projectName, List<String> fields, Sort sort, Pageable pageable) {
    if (projectName == null || fields == null || sort == null) {
        return new PageImpl<>(emptyList(), pageable, 0);
    }
    Query query = createSharedEntityQuery(projectName).with(sort).with(pageable);
    if (Preconditions.NOT_EMPTY_COLLECTION.test(fields)) {
        for (String field : fields) {
            query.fields().include(field);
        }
    }
    Class<T> entityType = getEntityInformation().getJavaType();
    return new PageImpl<>(getMongoOperations().find(query, entityType), pageable, getMongoOperations().count(query, entityType));
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) Query(org.springframework.data.mongodb.core.query.Query) ShareableRepositoryUtils.createSharedEntityQuery(com.epam.ta.reportportal.database.dao.ShareableRepositoryUtils.createSharedEntityQuery) ShareableRepositoryUtils.createOwnedEntityQuery(com.epam.ta.reportportal.database.dao.ShareableRepositoryUtils.createOwnedEntityQuery)

Example 24 with Query

use of org.springframework.data.mongodb.core.query.Query in project commons-dao by reportportal.

the class ShareableRepositoryImpl method findSharedEntitiesByName.

@Override
public Page<T> findSharedEntitiesByName(String projectName, String term, Pageable pageable) {
    final String regex = "(?i).*" + Pattern.quote(term.toLowerCase()) + ".*";
    Query query = createSharedEntityQuery(projectName).with(pageable);
    Criteria name = Criteria.where(ENTITY_NAME_FIELD).regex(regex);
    Criteria owner = Criteria.where(ENTITY_OWNER_FIELD).regex(regex);
    Criteria description = Criteria.where(ENTITY_DESCRIPTION_FIELD).regex(regex);
    query.addCriteria(new Criteria().orOperator(name, owner, description));
    Class<T> entityType = getEntityInformation().getJavaType();
    List<T> searchResults = getMongoOperations().find(query, entityType);
    return new PageImpl<>(searchResults, pageable, getMongoOperations().count(query, entityType));
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) Query(org.springframework.data.mongodb.core.query.Query) ShareableRepositoryUtils.createSharedEntityQuery(com.epam.ta.reportportal.database.dao.ShareableRepositoryUtils.createSharedEntityQuery) ShareableRepositoryUtils.createOwnedEntityQuery(com.epam.ta.reportportal.database.dao.ShareableRepositoryUtils.createOwnedEntityQuery) Criteria(org.springframework.data.mongodb.core.query.Criteria)

Example 25 with Query

use of org.springframework.data.mongodb.core.query.Query in project commons-dao by reportportal.

the class ShareableRepositoryImpl method findNonSharedEntities.

@SuppressWarnings("unchecked")
@Override
public List<T> findNonSharedEntities(String owner) {
    if (null == owner || owner.isEmpty()) {
        return emptyList();
    }
    Query query = ShareableRepositoryUtils.createUnsharedEntityQuery(owner);
    Class<T> entityType = getEntityInformation().getJavaType();
    return getMongoOperations().find(query, entityType);
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) ShareableRepositoryUtils.createSharedEntityQuery(com.epam.ta.reportportal.database.dao.ShareableRepositoryUtils.createSharedEntityQuery) ShareableRepositoryUtils.createOwnedEntityQuery(com.epam.ta.reportportal.database.dao.ShareableRepositoryUtils.createOwnedEntityQuery)

Aggregations

Query (org.springframework.data.mongodb.core.query.Query)488 Test (org.junit.Test)312 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)156 Update (org.springframework.data.mongodb.core.query.Update)79 NearQuery (org.springframework.data.mongodb.core.query.NearQuery)66 Document (org.bson.Document)56 Criteria (org.springframework.data.mongodb.core.query.Criteria)47 PartTree (org.springframework.data.repository.query.parser.PartTree)44 Sort (org.springframework.data.domain.Sort)30 ObjectId (org.bson.types.ObjectId)27 BasicDBObject (com.mongodb.BasicDBObject)22 DBObject (com.mongodb.DBObject)20 Before (org.junit.Before)18 List (java.util.List)17 Autowired (org.springframework.beans.factory.annotation.Autowired)17 GeoJsonPoint (org.springframework.data.mongodb.core.geo.GeoJsonPoint)17 Collectors (java.util.stream.Collectors)16 ArrayList (java.util.ArrayList)15 OptimisticLockingFailureException (org.springframework.dao.OptimisticLockingFailureException)15 MappingException (org.springframework.data.mapping.MappingException)15