コード例 #1
0
  public void update(Collection collection)
      throws EntityDoesNotExistException, InvalidEntityException {
    this.dao.begin();

    Collection originalCollection = this.dao.findBySlug(collection.getSlug(), getTenant());
    if (originalCollection == null) {
      this.dao.commit();
      throw new EntityDoesNotExistException();
    }
    collection.setId(originalCollection.getId());
    Integer updatedRows = this.dao.update(collection);

    if (collection.getLocalizedVersions() != null && !collection.getLocalizedVersions().isEmpty()) {
      Map<Locale, Map<String, Object>> localizedVersions = collection.getLocalizedVersions();
      for (Locale locale : localizedVersions.keySet()) {
        this.dao.createOrUpdateTranslation(
            collection.getId(), locale, localizedVersions.get(locale));
      }
    }

    this.dao.commit();

    if (updatedRows <= 0) {
      throw new StoreException("No rows was updated when updating collection");
    }

    getObservationManager().notify(new EntityUpdatedEvent(), collection);
  }
コード例 #2
0
  public Collection create(Collection collection)
      throws EntityAlreadyExistsException, InvalidEntityException {
    if (this.dao.findBySlug(collection.getSlug(), getTenant()) != null) {
      throw new EntityAlreadyExistsException();
    }

    getObservationManager().notify(new EntityCreatingEvent(), collection);

    this.dao.begin();

    UUID entityId = UUID.randomUUID();
    collection.setId(entityId);

    this.dao.createEntity(collection, COLLECTION_TABLE_NAME, getTenant());
    Integer lastIndex = this.dao.lastPosition(getTenant());
    this.dao.create(lastIndex == null ? 0 : ++lastIndex, collection);
    // this.dao.insertTranslations(entityId, collection.getTranslations());

    this.dao.commit();

    getObservationManager().notify(new EntityCreatedEvent(), collection);

    return collection;
  }