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
@@ -129,37 +129,37 @@ The Java action illustrated below does the following:
129
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
130
130
* The Mendix object created is added to the list to be returned
131
131
132
-
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.
132
+
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).
Below is the Java code to get the Dataset OQL, execute the OQL, and retrieve the Objects. You use the [Core.createOQLTextGetRequestFromDataSet](https://apidocs.rnd.mendix.com/10/runtime/com/mendix/core/Core.html#createOQLTextGetRequestFromDataSet(java.lang.String)) method to get the OQL query of the Dataset specified.
183
+
Below is the Java code to get the Dataset OQL, execute the OQL, and retrieve the Objects. You use the [Core.createOQLTextGetRequestFromDataSet](https://apidocs.rnd.mendix.com/10/runtime/com/mendix/core/Core.html#createOQLTextGetRequestFromDataSet(java.lang.String)) method to get the OQL query of the Dataset specified. (See [RetrieveDatasetOql.java](https://github.com/ako/QueryApiBlogPost/blob/master/javasource/hr/actions/RetrieveDatasetOql.java) in the *QueryApiBlogPost* GitHub repo for the full source code).
logger.info(String.format("Target entity %s does not have attribute named %s", this.ResultEntity, colName));
208
-
}
209
-
resultList.add(obj);
210
-
}
211
-
});
212
-
return resultList;
213
-
//END USER CODE
214
-
}
215
215
```
216
216
217
217
## Retrieving Objects Using SQL
@@ -227,46 +227,45 @@ The Java implementation below implements the following steps:
227
227
* Use *Core.dataStorage().executeWithConnection()* to execute some Java statements that receive a JDBC connection from the internal connection pool. This API is constructed to enable the Mendix Platform to guarantee that connections are returned to the pool after usage.
You can find the complete Java source code on GitHub: [RetrieveAdvancedSQL](https://github.com/ako/QueryApiBlogPost/blob/master/javasource/hr/actions/RetrieveAdvancedSql.java).
You can find the complete Java source code in the *QueryApiBlogPost*GitHub repo on GitHub: [RetrieveAdvancedSQL](https://github.com/ako/QueryApiBlogPost/blob/master/javasource/hr/actions/RetrieveAdvancedSql.java).
270
269
271
270
You now have a generic SQL action that can be used in microflows to retrieve data from your application database. The query in this example returns the same data as the OQL earlier, so you can reuse the non-persistable entity DepartmentSummary as defined previously.
272
271
@@ -329,76 +328,79 @@ You create a Java action with parameters for the start date and the end date. Yo
329
328
330
329
### Creating the JavaCode
331
330
331
+
{{% alert color="info"%}}
332
+
All the code is also available in [CreateDateRangeList.java](https://github.com/ako/QueryApiBlogPost/blob/master/javasource/hr/actions/CreateDateRangeList.java) in the *QueryApiBlogPost* GitHub repo.
333
+
{{%/alert %}}
334
+
332
335
1.Specify the required SQL statement in the Java method. JDBC queries expect the parameters to be specified by question marks (?) in the SQL statement.
333
336
334
337
```java
335
-
@Override
336
-
public java.util.List<IMendixObject> executeAction() throws Exception
337
-
{
338
-
// BEGIN USER CODE
339
-
String sql=
340
-
"with first_day_of_month as (\n" +
341
-
" SELECT * \n" +
342
-
" FROM generate_series\n" +
343
-
" ( date_trunc('month', ?::timestamp)\n" +
344
-
" , ?, '1 months'\n" +
345
-
" ) as firstday\n" +
346
-
"),\n" +
347
-
"firstmonday as (\n" +
348
-
" select fdom.firstday::date + \n" +
349
-
" ((8 - extract(dow from fdom.firstday))::integer % 7) \n" +
" ((8 - extract(dow from fdom.firstday))::integer % 7) \n"+
353
+
" as first_monday_date\n"+
354
+
"from first_day_of_month as fdom\n"+
355
+
")\n"+
356
+
"select fm.first_monday_date\n"+
357
+
"from firstmonday as fm\n"+
358
+
"where fm.first_monday_date >= ?::timestamp\n"+
359
+
"and fm.first_monday_date <= ?::timestamp\n"+
360
+
";"
361
+
;
362
+
logger.info("executeAction: "+ sql);
360
363
```
361
364
362
365
2.Next, use the MendixAPI to execute some statements using the JDBC connection. Here you create a prepared statement, define the JDBC parameter values, and execute the SQL query.
When you use this in a microflow, you just need to specify the start and end dates, and the name of the resulting list. This example iterates through all the data objects in the list and prints the date of that object.
0 commit comments