/** * Search Mongo using query. The result is then merged into session unless the method is called into a * pre-existing transaction, in which case, the merge mode is ignored and the merge is not performed. * * @param <T> * the entity type to return * @param query * the Mongo query. * @param mergeMode * the merge mode to use when merging back retrieved entities or null * if no merge is requested. * @param clazz * the type of the entity. * @return the first found entity or null */ public <T extends IEntity> List<T> findByQuery(final Query query, EMergeMode mergeMode, Class<? extends T> clazz) { return findByQuery(query, -1, -1, mergeMode, clazz); }
/** * Search Mongo using query. The result is then merged into session unless the method is called into a * pre-existing transaction, in which case, the merge mode is ignored and the merge is not performed. * * @param <T> * the entity type to return * @param query * the Mongo query. * @param mergeMode * the merge mode to use when merging back retrieved entities or null * if no merge is requested. * @param clazz * the type of the entity. * @return the first found entity or null */ public <T extends IEntity> T findFirstByQuery(Query query, EMergeMode mergeMode, Class<? extends T> clazz) { List<T> ret = findByQuery(query, 0, 1, mergeMode, clazz); if (ret != null && !ret.isEmpty()) { return ret.get(0); } return null; }
@Override protected void doInTransactionWithoutResult(TransactionStatus status) { List<Company> companies = mongoBackendController.findByQuery(new Query(), null, Company.class); for (Company company : companies) { try { mongoBackendController.cleanRelationshipsOnDeletion(company, false); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { e.printStackTrace(System.err); } } List<City> cities = mongoBackendController.findByQuery(new Query(), null, City.class); for (City city : cities) { try { mongoBackendController.cleanRelationshipsOnDeletion(city, false); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { e.printStackTrace(System.err); } } } });