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
+110-4Lines changed: 110 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -182,7 +182,37 @@ The microflow to execute the Java action is similar to the previous example, but
182
182
183
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.
((8 - extract(dow from fdom.firstday))::integer % 7)
314
+
as first_monday_date
315
+
from first_day_of_month as fdom
316
+
)
317
+
select fm.first_monday_date
318
+
from firstmonday as fm
319
+
where fm.first_monday_date >= '2017-01-2400:00'::timestamp
320
+
and fm.first_monday_date <= '2017-11-0512:00'::timestamp
321
+
;
322
+
```
274
323
275
324
### Creating the Java Action
276
325
@@ -282,15 +331,72 @@ You create a Java action with parameters for the start date and the end date. Yo
282
331
283
332
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.
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" +
350
+
" as first_monday_date \n" +
351
+
" from first_day_of_month as fdom \n" +
352
+
") \n" +
353
+
"select fm.first_monday_date \n" +
354
+
"from firstmonday as fm \n" +
355
+
"where fm.first_monday_date >= ?::timestamp \n" +
356
+
"and fm.first_monday_date <= ?::timestamp \n" +
357
+
";"
358
+
;
359
+
logger.info("executeAction: " + sql);
360
+
```
286
361
287
362
2. Next, use the Mendix API 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