At Mendix we are always working towards making your life better. In this month’s product release, we delivered new features like a database connector to seamlessly integrate with external data, enhanced synchronization control in the offline-first app, better accessibility options, and powerful microflow expressions to name a few. We are sure these updates will make the developer’s life easy and the end-users happy.

Studio Pro

Database Connector: bring back-end data to your front-end users

JDBC is a de-facto standard connecting all types of databases out in the wild. With this release, you can now use the Database Connector to easily extend apps with data stored in almost any type of database.

The Database Connector allows you to use traditional SQL queries for data retrievals:

SQL query with syntax highlighting
SQL query with syntax highlighting

Results can easily map back to your app:

The result object type can now be selected from your entities

Queries clauses can be parameterized for additional flexibility:

Parameters in statements are filled by their type and Studio Pro checks if you are passing correct values

You can find two new activities in the microflow toolbox: Execute parameterized query and Execute parameterized statement. These can be found next to the existing two activities. Don’t worry about migrating to the new activities immediately, you can do so at your own pace.

New parameterized activities

These improvements are available from Studio Pro 8.6 onward. Grab the Database Connector v3.x from the App Store to take advantage of this new feature! To learn more about the source model, visit our GitHub repository.

Parameterized string templates

Building queries at scale using direct string concatenation can quickly get cumbersome and sometimes even unsafe. Parameterized queries can solve these problems. In this release, we introduced string template parameters and added type information so module developers can create parameterized queries.

Without string template parameters, creating a query-based module is hard, and usually, the burden of building queries properly will be placed on the consumer of a module. In the following example, the old Database Connector is used to execute a statement against an external database. The developer has to pass the query in a complete JDBC URL and has to build up the full query before calling the Execute Statement action:

Execute Statement requires the developer to provide a full query in a single string

This is convenient for simple queries. But advanced queries quickly become hard to maintain since it cannot be easily formatted, nor are there any editor services like syntax highlighting. The burden of ensuring that the queries are secure partially falls to the developer. In fact, in some cases, expressions based on unchecked user input need to be sanitized manually.

With string template parameters, this is now a thing of the past. Developers can write completely safe parameterized SQL statements. In Mendix Studio Pro, if you add a String Template parameter to a Java action, callers of this action will get a template input instead of a regular string input. Here is an example from the Database Connector where this new functionality is used to execute a parameterized update statement against an external database:

Templated query with SQL syntax highlighting

The Database Connector executes this query with JDBC’s PreparedStatement, which means that any expression passed in are type-checked and escaped.

So how is this implemented in the Database Connector? In Studio Pro, the template contains Mendix-style indexed template parameters, ie. {1} and {2}. In the Java implementation, this needs to be mapped to a JDBC PreparedStatement. The placeholders, e.g. {1}, need to be replaced with JDBC’s ?. With the following line, are placeholders can be replaced with one of the IStringTemplate methods:

String updatedTemplate = template.replacePlaceholders((parameter, index) -> "?");

From this updated template, the prepared statement can be created:

PreparedStatement pstmt = con.prepareStatement(updatedTemplate);

The list of template parameters with their types and values is also provided by IStringTemplate. The type information and values of each of the template parameters can be used to add parameters at the correct index to the PreparedStatement:

List templateParameters = stringTemplate.getParameters();
for (int i = 0; i < templateParameters.size(); i++) {
ITemplateParameter parameter = templateParameters.get(i);
switch (parameter.getParameterType()) {
pstmt.setLong(i + 1, (long) parameter.getValue());
case STRING:
pstmt.setString(i + 1, (String)parameter.getValue());
pstmt.setBoolean(i + 1, (Boolean)parameter.getValue());
pstmt.setBigDecimal(i + 1, (BigDecimal)parameter.getValue());
pstmt.setDate(i + 1, convertDate(parameter.getValue()));

You can build a user-friendly interface to the Database Connector or similar modules using string templates. Create easy-to-use activities that use a query or query-like constructs for any kind of module, including the modules you create yourself. For inspiration, take a look at the source model of the Database Connector on GitHub.


Sync-to-device: synchronize only selected objects

Whenever an offline-first app synchronizes, the offline database is cleared and repopulated from scratch to guarantee data integrity. However, this can cause unnecessary overhead, for example, a large set of data that does not change often, and so, doesn’t need to synchronize frequently.

In this release, we added a microflow activity called sync-to-device. The activity enables developers to synchronize only the required objects to the device by passing them through a microflow. These objects are added to a local database and no other data is synchronized, making this a very performant option. If you want to synchronize objects of multiple entities, you can call this activity multiple times.

Sync-to-device used for synchronizing today’s news items

Another good example is when there is a large set of static data (e.g. 10k+ objects) that seldom changes, like a list of products. In this case, you can show a progress screen on the device while downloading all the objects in a batch. Once the data on the server is changed, you can then synchronize just the changed objects – making the sync to the device very flexible and efficient.

See the release notes for more information.


Improved accessibility with new web nanoflow activities

Building accessible apps are necessary to make your apps more user-friendly. In this release, we made several updates to improve accessibility. You can learn more about the updates in the release notes or check out the evaluation guide for more information about accessibility support.

We also published four new nanoflow activities for the web. These activities improve the user experience by offering more control over the focus elements.

Set focus: set the focus directly to a certain element
Focus next: set the focus to the next possible element
Focus previous: set the focus to the previous possible element
Scroll to: an element on the page

New web actions module

You can download these activities in the new web actions module in the app store here.


Simplified stories overview page

The stories overview page in the developer portal went through a huge transformation earlier this year. While everyone was able to switch to the new look since February, it has now become the default. A big thanks to all of you who submitted valuable feedback via the Mendix Community Slack.

In this update, we further simplified this page to make it more user-friendly. You can now find the right story by simply using the search box on top of the page. It’ll look-up for stories in descriptions, labels, and statuses at once.

Simplified search

Save time by clicking the ‘Create Another Story’ button on the New Story page or use the keyboard shortcut Shift+Enter.

Create another story

In addition to these changes, we’ve also made performance improvements across editing stories, loading stories on the overview page, stories API when getting to an active sprint, and more.


Associations in microflow expressions

While you could always use associations in microflow expressions, the use cases were limited. You could check if associations were empty, compare it with another object, or use it in assignments. However, when you needed to go beyond that, for example, to check the value of an attribute, you always had to Retrieve the associated object first. Well, not anymore!

With this release, we are making it easier to use associations. You can now follow the association directly inside all your microflows expressions, for example, in decisions and when setting values. Just write $variable/Module.Association/Module.TargetEntity/Attribute to get a referenced object’s attribute.

But you do not have to stop there – you can also follow two or more associations and check the type of entity of an association when specialization is used.

Following multiple associations and checking the type

Visual indicator for consistency errors and warnings

To ensure that your application models are consistent, Mendix provides an advanced error checking mechanism. Whenever you create a model that is not entirely correct, it provides syntactical and semantic errors and warnings. These errors and warnings are shown in the error pane of Studio Pro as a list.

To provide even faster feedback while you are building models, Studio Pro now visualizes the number of consistency errors and warnings on top of the relevant element. Errors get a red indicator and warnings get an orange one:

Visual indicators of errors and warnings

This feature is based on an idea submitted in the Mendix Idea Forum by Axel Brink. Thank you, Axel, for making development with Mendix easier!

Keep making life better

To read more about the new capabilities and features, check out the release notes. And, as always, download the latest version of Mendix Studio Pro to make life better.