Uploaded image for project: 'Isis'
  1. Isis
  2. ISIS-1392

Extend RepositoryService with persistAndFlush(...) and removeAndFlush(...) methods

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.12.1
    • Fix Version/s: 1.13.0
    • Component/s: Core
    • Labels:
      None

      Description

      It will ease life for newcomers, as the “flush()” invokation is needed for DataNucleus to update “mappedBy” collections, for example, when a new element has been added.

      For Queries, we’re currently invoking always flush(…) before executing it on the persistence layer, but that’s not the default behavior when setting a property, for example.

      So when DN reloads entities collections would not be updated.

      Let's see an example (notice the "this.persistAndFlush(...)" helper method invocation):

      public abstract class Warehouse extends SalesVIPEntity<Marketplace> {

      // {{ ExcludedProducts (Collection)
      @Persistent(mappedBy = "marketplace", dependentElement = "true")
      private SortedSet<MarketplaceExcludedProduct> excludedProducts = new TreeSet<MarketplaceExcludedProduct>();

      @MemberOrder(sequence = "1")
      public SortedSet<MarketplaceExcludedProduct> getExcludedProducts()

      { return this.excludedProducts; }

      public void setExcludedProducts(
      final SortedSet<MarketplaceExcludedProduct> excludedProducts)

      { this.excludedProducts = excludedProducts; }

      // }}

      // {{ addExcludedProduct (action)
      @Action(semantics = SemanticsOf.IDEMPOTENT)
      @MemberOrder(sequence = "1")
      public MarketplaceExcludedProduct addExcludedProduct(final Product product) {
      MarketplaceExcludedProduct marketplaceExcludedProduct = this
      .findExcludedProduct(product);
      if (marketplaceExcludedProduct == null)

      { marketplaceExcludedProduct = this.factoryService .instantiate(MarketplaceExcludedProduct.class); }

      this.wrap(marketplaceExcludedProduct).setMarketplace(this);
      this.wrap(marketplaceExcludedProduct).setProduct(product);

      this.persistAndFlush(marketplaceExcludedProduct); <—————————————

      return marketplaceExcludedProduct;
      }

      // }}

      // {{ deleteFromExcludedProducts (action)
      @Action(semantics = SemanticsOf.IDEMPOTENT)
      @MemberOrder(sequence = "1")
      public void deleteFromExcludedProducts(final Product product) {
      final MarketplaceExcludedProduct marketplaceExcludedProduct = this
      .findExcludedProduct(product);
      if (marketplaceExcludedProduct != null)

      { this.repositoryService.remove(marketplaceExcludedProduct); this.flushTransaction(); }

      }

      // }}

      // {{ findExcludedProduct (action)
      @Action(semantics = SemanticsOf.SAFE)
      @MemberOrder(sequence = "1")
      public MarketplaceExcludedProduct findExcludedProduct(final Product product)

      { return this.repositoryService.firstMatch(QueryDefault.create( MarketplaceExcludedProduct.class, "findByMarketplaceAndProduct", "marketplace", this, "product", product)); }

      // }}

      // {{ findAllProductsExcluded (action)
      @Action(semantics = SemanticsOf.SAFE, hidden = Where.EVERYWHERE)
      public Set<Product> findAllProductsExcluded()

      { return this.getExcludedProducts().stream().map(mep -> mep.getProduct()) .collect(Collectors.toSet()); }

      // }}

      }

      On the “addExcludedProduct()” action, if the user don’t flush(), in addition to persist(), this test would fail, not containing the given product:

      @Test
      public void addExcludedProduct()

      { // given final AmazonMarketplace amazonMarketplace = this.wrapSkipRules( this.marketplaceRepository).findOrCreateAmazonMarketplace( AmazonMarketplaceLocation.FRANCE); final Product product = this.wrap(this.productRepository) .createProduct(UUID.randomUUID().toString(), UUID.randomUUID().toString()); // when this.wrap(amazonMarketplace).addExcludedProduct(product); // then Assertions.assertThat(this.wrapSkipRules(amazonMarketplace).findAllProductsExcluded()).contains(product); }

        Activity

        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit f6e3835c035ebeb8d007d6a6134f64086d93a375 in isis's branch refs/heads/master from Oscar Bou
        [ https://git-wip-us.apache.org/repos/asf?p=isis.git;h=f6e3835 ]

        ISIS-1392: Extend RepositoryService with persistAndFlush(...) and removeAndFlush(...) methods

        Show
        jira-bot ASF subversion and git services added a comment - Commit f6e3835c035ebeb8d007d6a6134f64086d93a375 in isis's branch refs/heads/master from Oscar Bou [ https://git-wip-us.apache.org/repos/asf?p=isis.git;h=f6e3835 ] ISIS-1392 : Extend RepositoryService with persistAndFlush(...) and removeAndFlush(...) methods
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 5722c0bc44401efde2da80301604df5a9ea0c9f1 in isis's branch refs/heads/master from Oscar Bou
        [ https://git-wip-us.apache.org/repos/asf?p=isis.git;h=5722c0b ]

        ISIS-1392: updating documentation detailing the use case for managed relationships

        Show
        jira-bot ASF subversion and git services added a comment - Commit 5722c0bc44401efde2da80301604df5a9ea0c9f1 in isis's branch refs/heads/master from Oscar Bou [ https://git-wip-us.apache.org/repos/asf?p=isis.git;h=5722c0b ] ISIS-1392 : updating documentation detailing the use case for managed relationships
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 219e63addc70ab675e71baaf92a15c64883a3eb2 in isis's branch refs/heads/master from Dan Haywood
        [ https://git-wip-us.apache.org/repos/asf?p=isis.git;h=219e63a ]

        Merge branch 'ISIS-1392' of https://github.com/oscarbou/isis into ISIS-1392_pr-43

        Show
        jira-bot ASF subversion and git services added a comment - Commit 219e63addc70ab675e71baaf92a15c64883a3eb2 in isis's branch refs/heads/master from Dan Haywood [ https://git-wip-us.apache.org/repos/asf?p=isis.git;h=219e63a ] Merge branch ' ISIS-1392 ' of https://github.com/oscarbou/isis into ISIS-1392 _pr-43
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 219e63addc70ab675e71baaf92a15c64883a3eb2 in isis's branch refs/heads/master from Dan Haywood
        [ https://git-wip-us.apache.org/repos/asf?p=isis.git;h=219e63a ]

        Merge branch 'ISIS-1392' of https://github.com/oscarbou/isis into ISIS-1392_pr-43

        Show
        jira-bot ASF subversion and git services added a comment - Commit 219e63addc70ab675e71baaf92a15c64883a3eb2 in isis's branch refs/heads/master from Dan Haywood [ https://git-wip-us.apache.org/repos/asf?p=isis.git;h=219e63a ] Merge branch ' ISIS-1392 ' of https://github.com/oscarbou/isis into ISIS-1392 _pr-43
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 78b70ade82bf5e398783343a1a710e7dba6bb1cf in isis's branch refs/heads/master from Dan Haywood
        [ https://git-wip-us.apache.org/repos/asf?p=isis.git;h=78b70ad ]

        ISIS-1392: minor edits to updated docs

        Show
        jira-bot ASF subversion and git services added a comment - Commit 78b70ade82bf5e398783343a1a710e7dba6bb1cf in isis's branch refs/heads/master from Dan Haywood [ https://git-wip-us.apache.org/repos/asf?p=isis.git;h=78b70ad ] ISIS-1392 : minor edits to updated docs
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit bcca867a2ee755fa1e61eabb927ab3d0d41ab48b in isis's branch refs/heads/master from Dan Haywood
        [ https://git-wip-us.apache.org/repos/asf?p=isis.git;h=bcca867 ]

        Merge branch 'ISIS-1392_pr-43'

        Show
        jira-bot ASF subversion and git services added a comment - Commit bcca867a2ee755fa1e61eabb927ab3d0d41ab48b in isis's branch refs/heads/master from Dan Haywood [ https://git-wip-us.apache.org/repos/asf?p=isis.git;h=bcca867 ] Merge branch ' ISIS-1392 _pr-43'

          People

          • Assignee:
            oscarbou Oscar Bou
            Reporter:
            oscarbou Oscar Bou
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development