private <T extends IEntity> List<T> find(final Query query, final int firstResult, final int maxResults, final EMergeMode mergeMode, final Class<? extends T> clazz) { return getTransactionTemplate().execute(new TransactionCallback<List<T>>() { @SuppressWarnings("unchecked") @Override public List<T> doInTransaction(TransactionStatus status) { if (firstResult >= 0) { query.skip(firstResult); } if (maxResults > 0) { query.limit(maxResults); } List<? extends T> entities = getMongoTemplate().find(query, clazz); if (mergeMode != null) { entities = merge(entities, mergeMode); } return (List<T>) entities; } }); }
/** * Persists or update an entity. * * @param entity * the entity to persist or update. */ protected void saveOrUpdate(final IEntity entity) { final MongoBackendController mongoBackendController = getBackendController(); mongoBackendController.getTransactionTemplate().execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { getMongoTemplate().save(mongoBackendController.cloneInUnitOfWork(entity)); } }); }
private void clearPresiousData() { final MongoBackendController mongoBackendController = getBackendController(); mongoBackendController.getTransactionTemplate().execute(new TransactionCallbackWithoutResult() { @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); } } } }); }
} else { res = getTransactionTemplate().execute(new TransactionCallback<T>() {
getTransactionTemplate().execute(new TransactionCallbackWithoutResult() {