Skip to content

Commit 46f5da6

Browse files
committed
Proofread
1 parent 67633dd commit 46f5da6

2 files changed

Lines changed: 24 additions & 26 deletions

File tree

content/en/docs/howto/extensibility/howto-datastorage-api.md

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Mendix Studio Pro supports two query languages to retrieve data:
1313
* XPath as an easy to use query language to retrieve objects
1414
* OQL is a SQL based language, more focused on powerful reporting facilities
1515

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.
1717

1818
This how to describes how you can build the following microflow actions:
1919

@@ -24,23 +24,21 @@ This how to describes how you can build the following microflow actions:
2424
* Create first Monday of month list - returns a list of dates of the first Monday of every month in a specified range
2525
* Register global entity listeners - run custom Java code for every object change
2626

27-
{{< figure src="/attachments/howto/extensibility/howto-datastorage-api/image001.png" alt="Microflow actions toolbox" class="no-border" >}}
28-
2927
For more information on Java programming for Mendix, see [Java Programming](/refguide/java-programming/).
3028

3129
For more information on calling Java actions from a microflow, see [Java Actions](/refguide/java-actions/).
3230

33-
## Retrieving Advanced XPath
31+
## Retrieving Objects Using Advanced XPath
3432

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.
3634

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.
3836

3937
The Java action needs the following parameters:
4038

4139
* A string where the user can specify the XPath expression to be executed
4240
* 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
4442

4543
{{< figure src="/attachments/howto/extensibility/howto-datastorage-api/image003.png" class="no-border" >}}
4644

@@ -57,24 +55,24 @@ The implementation of this Java action is pretty straightforward; you can use th
5755
The implementation also validates that the list returned contains objects of the entity specified.
5856

5957
```java
60-
@Override
61-
public java.util.List<IMendixObject> executeAction() throws Exception
62-
{
63-
//BEGIN USER CODE
64-
List<IMendixObject> result = null;
65-
result = Core.createXPathQuery(this.XPath).execute(getContext());
66-
if (!result.isEmpty() && !result.get(0).isInstanceOf(this.ResultEntity)) {
67-
throw new MendixRuntimeException(String.format("Unexpected result entity: %s vs %s",
68-
result.get(0).getMetaObject().getName(), this.ResultEntity));
58+
@Override
59+
public java.util.List<IMendixObject> executeAction() throws Exception
60+
{
61+
//BEGIN USER CODE
62+
List<IMendixObject> result = null;
63+
result = Core.createXPathQuery(this.XPath).execute(getContext());
64+
if (!result.isEmpty() && !result.get(0).isInstanceOf(this.ResultEntity)) {
65+
throw new MendixRuntimeException(String.format("Unexpected result entity: %s vs %s",
66+
result.get(0).getMetaObject().getName(), this.ResultEntity));
67+
}
68+
return result;
69+
// END USER CODE
6970
}
70-
return result;
71-
// END USER CODE
72-
}
7371
```
7472

7573
Now you have a new microflow action in the toolbox that you can use in your microflows.
7674

77-
Here’s an example domain model with two entities: Department and Employee.
75+
Here is an example domain model with two entities: Department and Employee.
7876

7977
{{< figure src="/attachments/howto/extensibility/howto-datastorage-api/image011.png" class="no-border" >}}
8078

@@ -86,7 +84,7 @@ You can drag the Java action created above from the toolbox into a microflow. In
8684

8785
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:
8886

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
9088
* OQL is database vendor independent, so you can run the same OQL statement on all databases supported by Mendix
9189

9290
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
111109

112110
* **OqlQuery** – a string containing the OQL query
113111
* **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
115113

116114
As in the XPath example above, a **Type parameter** is defined to specify that the return list uses the type specified in ResultEntity.
117115

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.
119117

120118
{{< figure src="/attachments/howto/extensibility/howto-datastorage-api/image020.png" class="no-border" >}}
121119

122120
The Java action illustrated below does the following:
123121

124122
* 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**
126124

127125
{{% 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 %}}
128126

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
130128
* The Mendix object created is added to the list to be returned
131129

132130
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.
413411

414412
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 *After App Startup Microflow*.
415413

416-
### Example code to Register the Event Listener.
414+
### Example code to Register the Event Listener
417415

418416
This code will log old and new attribute value for all changes to attributes before making changes in the database:
419417

Binary file not shown.

0 commit comments

Comments
 (0)