You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/docs/howto/extensibility/howto-datastorage-api.md
+24-26Lines changed: 24 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ Mendix Studio Pro supports two query languages to retrieve data:
13
13
* XPath as an easy to use query language to retrieve objects
14
14
* OQL is a SQL based language, more focused on powerful reporting facilities
15
15
16
-
You can use these query languages in Mendix Studio Pro, but both languages are also available through the [Mendix Runtime Java API](/apidocs-mxsdk/apidocs/runtime-api/). You can use these APIs to implement powerful reusable microflow actions. In addition to XPath and OQL, the Mendix APIs also enable you to use standard SQL on your Mendix database.
16
+
You can use these query languages in Mendix Studio Pro, but both languages are also available through the [Mendix Runtime Java API](/apidocs-mxsdk/apidocs/runtime-api/). You can use this API to implement powerful reusable microflow actions. In addition to XPath and OQL, the Mendix API also enables you to use standard SQL on your Mendix database.
17
17
18
18
This how to describes how you can build the following microflow actions:
19
19
@@ -24,23 +24,21 @@ This how to describes how you can build the following microflow actions:
24
24
* Create first Monday of month list - returns a list of dates of the first Monday of every month in a specified range
25
25
* Register global entity listeners - run custom Java code for every object change
For more information on Java programming for Mendix, see [Java Programming](/refguide/java-programming/).
30
28
31
29
For more information on calling Java actions from a microflow, see [Java Actions](/refguide/java-actions/).
32
30
33
-
## Retrieving Advanced XPath
31
+
## Retrieving Objects Using Advanced XPath
34
32
35
-
The goal is to create a microflow action where a user can specify an XPath expression and which result entities are expected. The action will execute the XPath statement and return the resulting list of objects.
33
+
In this section you will create a microflow action where a user can specify an XPath expression and the result entities which are expected. The action will execute the XPath statement and return the resulting list of objects.
36
34
37
-
In practice, this is not a very useful microflow action as you can already do this with the standard retrieve action in Mendix Studio Pro. The goal, however, is to illustrate how you can use the XPath Java API.
35
+
In practice, this is not a very useful microflow action as you can already do this with the standard retrieve action in Mendix Studio Pro. It is used to illustrate how you can use the XPath Java API.
38
36
39
37
The Java action needs the following parameters:
40
38
41
39
* A string where the user can specify the XPath expression to be executed
42
40
* A result entity where the user specifies which entity is to be returned
43
-
* A return type which specifies that the action returns a list of the entities specified in the previous parameter.
41
+
* A return type which specifies that the action returns a list of the entities specified in the previous parameter
@@ -86,7 +84,7 @@ You can drag the Java action created above from the toolbox into a microflow. In
86
84
87
85
The following example illustrates how you can use the OQL APIs for reporting purposes. OQL is the general-purpose Mendix query language, very much resembling SQL. The biggest differences between OQL and SQL are:
88
86
89
-
* OQL is expressed in entity and attribute names instead of table names and column names. This makes it easier to use, as you do not have to know the technical data model as stored in the database
87
+
* OQL is expressed in entity and attribute names instead of table names and column names. This makes it easier to use, as you do not have to know the technical details of the data model as stored in the database
90
88
* OQL is database vendor independent, so you can run the same OQL statement on all databases supported by Mendix
91
89
92
90
The following non-persistable entity shows what data you are interested in for your report:
@@ -111,22 +109,22 @@ You can create a generic microflow action to execute OQL queries and return a li
111
109
112
110
***OqlQuery** – a string containing the OQL query
113
111
***ResultEntity** – which entity will hold the retrieved data
114
-
* A list of the **ResultEntity** specified as a return type.
112
+
* A list of the **ResultEntity** specified as the return type
115
113
116
114
As in the XPath example above, a **Type parameter** is defined to specify that the return list uses the type specified in ResultEntity.
117
115
118
-
Additionally, you need to expose the Java action as a microflow action, provide a caption and an icon.
116
+
Additionally, you need to expose the Java action as a microflow action, so provide a caption and an icon.
The Java action illustrated below does the following:
123
121
124
122
* Retrieves all data using the Mendix API `Core.retrieveOQLDataTable()`
125
-
* Loops through all the rows, creates a new object of the type specified by ResultEntity.
123
+
* Loops through all the rows, creates a new object of the type specified by **ResultEntity**
126
124
127
125
{{% alert color="info" %}}Setting a Java action parameter of type **Entity of type parameter...** (*ResultEntity* in the example above) creates a Java string in the action which contains the name of the entity type. This string can be passed to Core.instantiate to create a new object.{{% /alert %}}
128
126
129
-
* Loops through all columns of a record and copies the column value to an attribute with the same name. If an attribute with a column name does not exist, a message is printed, and the loop continues
127
+
* Loops through all columns of a record and copies the column value to an attribute with the same name. If an attribute with the specified column name does not exist, a message is printed and the loop continues
130
128
* The Mendix object created is added to the list to be returned
131
129
132
130
Note that in this case, as show in the domain model screenshot and the OQL screenshot above, the names of the attributes and columns match exactly. (See [RetrieveAdvancedOql.java](https://github.com/ako/QueryApiBlogPost/blob/master/javasource/hr/actions/RetrieveAdvancedOql.java) in the *QueryApiBlogPost* GitHub repo for the full source code).
@@ -413,7 +411,7 @@ You will see the list of dates in the console.
413
411
414
412
Global entity event listeners enable you to define generic event handlers on all entities. This enables you to build generic validations or create a real-time data export to a central datastore. You can use a Java action to register any desired event handler, most likely in the *AfterAppStartupMicroflow*.
415
413
416
-
### Example code to Register the EventListener.
414
+
### Example code to Register the EventListener
417
415
418
416
This code will log old and new attribute value for all changes to attributes before making changes in the database:
0 commit comments