Integrating Docmosis with Mendix

a) Unlocking the Power of Retrieve + Aggregate in Mendix: Best Practices for Efficient Data Handling

When developing applications in Mendix, optimizing data retrieval is crucial for performance. One powerful technique that can significantly enhance the efficiency of your applications is the Retrieve + Aggregate pattern. Whether you’re working with large datasets or managing complex microflows, using this technique can help you minimize unnecessary data retrieval, streamline queries, and reduce server load. Let’s dive into how this optimization works and why you should consider it in your Mendix projects.

How It Works: Retrieve + Aggregate Optimization in Mendix

The Retrieve + Aggregate optimization is a powerful performance enhancement technique that Mendix uses to optimize queries when you only need the count of a list, rather than the entire list of objects. Here’s how it works.

When you have two actions in a microflow, one to retrieve a list of objects and another to count that list, Mendix optimizes this into a single query, but only if those two actions are placed directly next to each other. The retrieve action must come first, followed immediately by the aggregate (count) action, with no other activities in between.

Mendix recognizes that you’re only interested in the count, not the full list, and it will optimize by retrieving just the count from the database, rather than pulling the entire list into memory. This approach reduces server load and improves performance.

However, this optimization will not work if the retrieved list is used later in the microflow. If you pass the list as input to other activities, Mendix will execute the retrieve and count actions separately, keeping both outputs in memory, which can increase resource usage and negate the optimization.

Let’s explore two examples to clarify this.

Example 1: Using the Same List as Input to Other Activities

In this scenario, I have a microflow that retrieves a list of checkpoints and counts them, but later in the microflow, I pass the retrieved list of checkpoints to another activity.

  • Step 1: Retrieve the list of checkpoints.

  • Step 2: Count the checkpoints.

  • Step 3: Pass the retrieved list to another activity, such as a decision or loop.

Since the retrieved list is used in a subsequent activity, Mendix will not apply the Retrieve + Aggregate optimization. Instead, it will execute the retrieve and count actions separately, holding both the count and the full list in memory. This can lead to increased memory usage, reducing the performance benefits.

gif

Example 2: Not Using the Same List in Other Activities

In this optimized scenario, I retrieve the list of checkpoints and count them, but I do not pass the retrieved list to any other activity. Instead, after further logic or decisions, I retrieve the list again and by having one more retrieve activity in the flow and then I pass the retrieved list of checkpoints to another activity.

  • Step 1: Retrieve the list of checkpoints.

  • Step 2: Count the checkpoints.

  • Step 3: After additional logic or decisions, retrieve the list again (with the same condition) and use it for further activities.

By ensuring the retrieve and count actions are placed directly next to each other and avoiding the use of the initial retrieved list in later activities, Mendix applies the Retrieve + Aggregate optimization. The system retrieves only the count from the database, optimizing performance. If the list of objects is needed later in the flow, a separate retrieval action ensures the data is fetched efficiently when required, without keeping the entire list in memory.

gif

Key Takeaway:

For Retrieve + Aggregate optimization to work effectively in Mendix, make sure that the retrieve and count actions are placed next to each other in the microflow, and that you don’t use the retrieved list in any subsequent activities. If the list is required later, use a separate retrieve action. This ensures Mendix can optimize the query and reduce memory usage, fetching only the count when that’s all you need.

b) Managing Objects from Multiple Entities in a Single Data Container

In Mendix, you can configure List Views to display objects from multiple entities. However, this is not a universal feature and is limited to cases where entities share an inheritance relationship. Below, we’ll explore how this works and why it’s possible.

Displaying Objects of Multiple Entities in a Single List View

Mendix allows you to configure a List View with objects from different entities by setting up individual templates for each entity. However, this only works if there is inheritance between the entities.

gif
gif

    Example Scenario:

  • You have a generalized entity and three specialized entities inheriting from it.

  • If you configure a List View for the generalized entity, you can also display objects from the specialized entities by creating separate templates for each one.

image

This is a useful feature when working with a hierarchy of entities, as it allows you to present a unified view of related data.

How Is This Achievable?

The ability to display objects from multiple inherited entities stems from how Mendix handles inheritance in the underlying database. To fully understand this, let’s take a look at how data is structured.

Understanding Inheritance in Database Tables

In a typical scenario, data for each entity is stored in its own table within the database. However, when entities share an inheritance relationship, the data for specialized entities is distributed across two tables:

  • The table of the generalized (parent) entity.

image
  • If you configure a List View for the generalized entity, you can also display objects from the specialized entities by creating separate templates for each one.

image

    Key Points:

  • Both the generalized and specialized entity share the same object ID (GUID).

  • An additional column, “SubMetaObjectName” is added to the generalized entity’s table. This column stores metadata, indicating to which specialized entity an object belongs.

This shared structure allows the generalized table to hold both its own objects and the objects of its specialized entities, making it possible to list them together in a single view.

Why This Matters

By utilizing inheritance, Mendix provides a flexible way to display data from related entities in a single List View. This approach simplifies data management and presentation when working with multiple entities that share common characteristics but also have unique attributes.