Data Querying & Management
Mendix offers a number of ways to specify the data you want to retrieve:
- Both Mendix Studio Pro and Mendix Studio offer visual ways to specify your query needs via an expression editor
- To retrieve specific objects or a set of related objects, you can use XPath expressions (see XPath below)
- For reporting needs where the aggregation and joining of multiple entities into a single result set is important, Mendix offers OQL queries (see OQL below)
- A Java API is available if you want to use SQL queries on the application database (see SQL below)
- For data sharing with other applications or data analytics tools, Mendix offers out-of-the-box support for OData on entities in your domain model (see OData below)
The Mendix Platform provides a lot of optimization out of the box. For example, when retrieving data for your pages through XPath, Mendix will automatically retrieve all the related information used on the page in one go. A concept called schemas is used for this. A schema tells the data retrieval component to not only retrieve a specific set of objects from the database, but to include specific associated entities in the result as well.
Besides optimized queries, Mendix also optimizes to avoid the need to query. This is done, for example, in the web client where objects are cached and reused through multiple pages. Another optimization made in the Mendix Runtime uses knowledge of the page structure to determine if objects need to be sent from the Runtime to the client at all.
In addition to these out-of-the-box optimizations, there are a number of steps you can take to optimize your queries:
- Retrieve only what you need, and make sure you do not include attributes or objects in your query that you do not need
- Ensure that you have indexes on the following:
- Columns that are regularly searched or filtered on
- Columns that are used for sorting
In some cases—especially when you have a large number of objects—it can be helpful to use database-specific indexes. You can create these through the JDBC API, as described above in SQL.
You can use the Database Connector to run SQL actions on any database you are using. To learn more about using an existing SQL database in Mendix, see the section How Does Mendix Support Direct Access to an External SQL Database? in External Data.
The Mendix Runtime provides Java APIs that enable extending the data storage behavior. Mendix ensures that anybody on your team can use these extensions by enabling you to provide them through normal microflow activities. For more info on this extensibility feature of Mendix, see the section What Kind of APIs Does Mendix Expose? in Openness (API & SDK).
Regarding data storage extensibility, the main Java APIs provide the following functionality:
- XPath – APIs to retrieve from the database using Xpath queries
- OQL – APIs to retrieve data from the database using OQL queries
- SQL – APIs to directly use the underlying Java JDBC connection to run any SQL required on your application database
- Entity event handlers – APIs to register entity event listeners for all your entities, which can be used to extract auditing information or do a real-time export of all data changes to an external system