public void delete(@Valid Product entity) throws EntityDoesNotExistException { Integer updatedRows = 0; this.dao.begin(); updatedRows += this.dao.deleteAddons(entity); updatedRows += this.dao.deleteProductFromCollections(entity.getId()); updatedRows += this.dao.deleteEntityEntityById(PRODUCT_TABLE_NAME, entity.getId()); updatedRows += this.dao.detachChildren(entity.getId()); updatedRows += this.dao.deleteEntityAndChildrenById(entity.getId()); this.dao.commit(); if (updatedRows <= 0) { throw new EntityDoesNotExistException("No rows was updated when trying to delete product"); } }
Product retrieved = this.productStore.findById(product.getId()); output.println("- indexing " + tenant.getSlug() + ":" + product.getSlug()); output.flush();
} catch (Exception e) { logger.warn("Failed to add back product [{}] from session", product.getId());
public void update(Product product) throws EntityDoesNotExistException, InvalidEntityException { this.dao.begin(); Product originalProduct = this.findBySlug(product.getSlug(), product.getParentId()); if (originalProduct == null) { this.dao.commit(); throw new EntityDoesNotExistException(); } if (!product.getAddons().isLoaded()) { product.setAddons(originalProduct.getAddons().get()); } getObservationManager().notify(new EntityUpdatingEvent(), product); product.setId(originalProduct.getId()); Integer updatedRows = this.dao.updateProduct(product); this.dao.createOrUpdateAddons(product); if (product.getLocalizedVersions() != null && !product.getLocalizedVersions().isEmpty()) { Map<Locale, Map<String, Object>> localizedVersions = product.getLocalizedVersions(); for (Locale locale : localizedVersions.keySet()) { this.dao.createOrUpdateTranslation(product.getId(), locale, localizedVersions.get(locale)); } } this.dao.commit(); if (updatedRows <= 0) { throw new StoreException("No rows was updated when updating product"); } getObservationManager().notify(new EntityUpdatedEvent(), product); }