@Override public void deleteAll() { mongoOperations.remove(new Query(), 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()); }
@Test public void testRemoveNoTransactionWithCollection() throws Exception { writer.setDelete(true); List<Object> items = new ArrayList<Object>() {{ add(new Object()); add(new Object()); }}; writer.setCollection("collection"); writer.write(items); verify(template).remove(items.get(0), "collection"); verify(template).remove(items.get(1), "collection"); }
@Test public void testBasicWrite() throws Exception { MongoItemWriter<String> writer = new MongoItemWriterBuilder<String>().template(this.template).build(); writer.write(this.items); verify(this.template).save(this.items.get(0)); verify(this.template).save(this.items.get(1)); verify(this.template, never()).remove(this.items.get(0)); verify(this.template, never()).remove(this.items.get(1)); }
@Test public void testDelete() throws Exception { MongoItemWriter<String> writer = new MongoItemWriterBuilder<String>().template(this.template) .delete(true) .build(); writer.write(this.items); verify(this.template).remove(this.items.get(0)); verify(this.template).remove(this.items.get(1)); verify(this.template, never()).save(this.items.get(0)); verify(this.template, never()).save(this.items.get(1)); }
@Test public void testWriteToCollection() throws Exception { MongoItemWriter<String> writer = new MongoItemWriterBuilder<String>().collection("collection") .template(this.template) .build(); writer.write(this.items); verify(this.template).save(this.items.get(0), "collection"); verify(this.template).save(this.items.get(1), "collection"); verify(this.template, never()).remove(this.items.get(0), "collection"); verify(this.template, never()).remove(this.items.get(1), "collection"); }
@Override public Object execute(Query query) { String collectionName = method.getEntityInformation().getCollectionName(); Class<?> type = method.getEntityInformation().getJavaType(); if (method.isCollectionQuery()) { return operations.findAllAndRemove(query, type, collectionName); } DeleteResult writeResult = operations.remove(query, type, collectionName); return writeResult != null ? writeResult.getDeletedCount() : 0L; } }
public void remove(MongoOperations mongoOperations, Object target, String collectionName) { if (target instanceof List<?>) { List<?> documents = (List<?>) target; for (Object document : documents) { mongoOperations.remove(document, collectionName); } } }
@Override public void deleteAll() { mongoOperations.remove(new Query(), 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 Object execute(Query query) { String collectionName = method.getEntityInformation().getCollectionName(); Class<?> type = method.getEntityInformation().getJavaType(); if (method.isCollectionQuery()) { return operations.findAllAndRemove(query, type, collectionName); } DeleteResult writeResult = operations.remove(query, type, collectionName); return writeResult != null ? writeResult.getDeletedCount() : 0L; } }
/** * Delete all {@link RestApplication} that matches the provided * <code>projectId</code>. * * @param projectId The id of the project. */ @Override public void deleteWithProjectId(String projectId) { mongoOperations.remove(getProjectIdQuery(projectId), RestApplicationDocument.class); }
@Override @Transactional(readOnly = false) public boolean delete(final RegisteredService svc) { if (this.findServiceById(svc.getId()) != null) { this.mongoTemplate.remove(svc, this.collectionName); log.debug("Removed registered service: {}", svc); return true; } return false; }
@Override public void deleteByPreloaded(boolean preloaded) { logger.debug("deleteByPreloaded preloaded = " + preloaded); Query query = new Query(where("preloaded").is(preloaded)); imageMongoTemplate.remove(query, ImageFull.class); }
@Override public void deleteByAuctionId(Long auctionId) { Query query = new Query(where("auctionId").is(auctionId)); attendanceRecordMongoTemplate.remove(query, AttendanceRecord.class); }
public void destroySession(String identifier) { Query q = new Query(Criteria.where("identifier").is(identifier)); this.source.remove(q, Session.class); }
@Override public void deleteByTags(String... tags) { if (ArrayUtils.isNotEmpty(tags)) { Query query = Query.query(Criteria.where(TAGS).all((Object[]) tags)); mongoOperations.remove(query, OneTimeAccessToken.class); } } }
@Override public void deleteByTags(String... tags) { if (ArrayUtils.isNotEmpty(tags)) { Query query = Query.query(Criteria.where(TAGS).all((Object[]) tags)); mongoOperations.remove(query, OneTimeAccessToken.class); } } }