Refine search
@Override public <S extends T> List<S> findAll(Example<S> example, Sort sort) { Assert.notNull(example, "Sample must not be null!"); Assert.notNull(sort, "Sort must not be null!"); Query q = new Query(new Criteria().alike(example)).with(sort); return mongoOperations.find(q, example.getProbeType(), entityInformation.getCollectionName()); }
@Override public void deleteById(ID id) { Assert.notNull(id, "The given id must not be null!"); mongoOperations.remove(getIdQuery(id), entityInformation.getJavaType(), entityInformation.getCollectionName()); }
@Override public <S extends T> S save(S entity) { Assert.notNull(entity, "Entity must not be null!"); if (entityInformation.isNew(entity)) { return mongoOperations.insert(entity, entityInformation.getCollectionName()); } return mongoOperations.save(entity, entityInformation.getCollectionName()); }
/** * Clean up resources on shutdown */ @PreDestroy public void cleanUpWhenShuttingDown() { // Disable profiling setProfilingLevel(0); if (operations.collectionExists(SYSTEM_PROFILE_DB)) { operations.dropCollection(SYSTEM_PROFILE_DB); } }
Assert.isTrue(this.initialized, "This class is not yet initialized. Invoke its afterPropertiesSet() method"); AbstractIntegrationMessageBuilder<Object> messageBuilder = null; Object value = this.queryExpression.getValue(this.evaluationContext); Assert.notNull(value, "'queryExpression' must not evaluate to null"); Query query; if (value instanceof String) { Assert.notNull(query, "'queryExpression' must not evaluate to null"); String collectionName = this.collectionNameExpression.getValue(this.evaluationContext, String.class); Assert.notNull(collectionName, "'collectionNameExpression' must not evaluate to null"); if (this.expectSingleResult) { result = this.mongoTemplate. findOne(query, this.entityClass, collectionName); find(query, this.entityClass, collectionName); if (!CollectionUtils.isEmpty(results)) { result = results;
@Override public Optional<T> findById(ID id) { Assert.notNull(id, "The given id must not be null!"); return Optional.ofNullable( mongoOperations.findById(id, entityInformation.getJavaType(), entityInformation.getCollectionName())); }
@Override public <S extends T> S insert(S entity) { Assert.notNull(entity, "Entity must not be null!"); return mongoOperations.insert(entity, entityInformation.getCollectionName()); }
private void createCollectionIfNotExists(String collection, MongoOperations mongoTemplate) { Assert.notNull(collection); if (!mongoTemplate.collectionExists(collection)) { mongoTemplate.createCollection(collection); } }
@Override @SuppressWarnings("unchecked") public T findOneNoJoin(ID id) { Class<T> entityType = getEntityInformation().getJavaType(); Query q = query(where(getEntityInformation().getIdAttribute()).is(id)); org.springframework.data.mongodb.core.query.Field fields = q.fields(); for (String include : INCLUDED_FIELDS.getUnchecked(entityType)) { fields.include(include); } return getMongoOperations().findOne(q, entityType); }
@Override public Page<User> findByTypeAndLastSynchronizedBefore(UserType type, Date lastSynchronized, Pageable pageable) { Query q = query(where("type").is(type).and(MetaInfo.SYNCHRONIZATION_DATE).lt(lastSynchronized)).with(pageable); long count = mongoOperations.count(q, User.class); return new PageImpl<>(mongoOperations.find(q, User.class), pageable, count); }
@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)); }
@SuppressWarnings("unchecked") @Override public List<T> findByProject(String projectName) { if (null == projectName) { return emptyList(); } Query query = Query.query(Criteria.where("projectName").is(projectName)); Class<T> entityType = getEntityInformation().getJavaType(); return getMongoOperations().find(query, entityType); }
@Override public void deleteAll() { mongoOperations.remove(new Query(), entityInformation.getCollectionName()); }
@Override public long count() { return mongoOperations.count(new Query(), entityInformation.getCollectionName()); }