Skip to content

Instantly share code, notes, and snippets.

Last active November 8, 2022 12:57
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Retrieves the objects of the type of ReturnEntity based on the identifiers retrieved in the SQL query
// This file was generated by Mendix Studio Pro.
// WARNING: Only the following code will be retained when actions are regenerated:
// - the import list
// - the code between BEGIN USER CODE and END USER CODE
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
// Other code you write will be lost the next time you deploy the project.
// Special characters, e.g., é, ö, à, etc. are supported in comments.
package myfirstmodule.actions;
import com.mendix.core.Core;
import com.mendix.core.CoreException;
import com.mendix.logging.ILogNode;
import com.mendix.systemwideinterfaces.MendixRuntimeException;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.systemwideinterfaces.core.IMendixIdentifier;
import com.mendix.systemwideinterfaces.core.IMendixObject;
import com.mendix.systemwideinterfaces.core.meta.IMetaObject;
import com.mendix.systemwideinterfaces.core.meta.IMetaPrimitive;
import com.mendix.webui.CustomJavaAction;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
* Executes the SQL query
* Retrieves the objects of the type of ReturnEntity based on the identifiers retrieved in the SQL query.
* The query should only return the identifier (id column) of the entity you wish to retrieve. For example the planning$ and the JavaAction will retrieveById these objects and return all Day objects matching the SQL query
public class RetrieveObjectsByIdAdvancedSql extends CustomJavaAction<java.util.List<IMendixObject>>
private java.lang.String Sql;
private java.lang.String ReturnEntity;
public RetrieveObjectsByIdAdvancedSql(IContext context, java.lang.String Sql, java.lang.String ReturnEntity)
this.Sql = Sql;
this.ReturnEntity = ReturnEntity;
public java.util.List<IMendixObject> executeAction() throws Exception
logger.debug("executeAction: " + this.Sql);
List<IMendixObject> resultList = null;
resultList = Core.dataStorage().executeWithConnection(connection ->
List<IMendixObject> objects = new ArrayList<IMendixObject>();
List<IMendixIdentifier> resultIDs = new ArrayList<IMendixIdentifier>();
try {
PreparedStatement stmt = connection.prepareStatement(this.Sql);
ResultSet rset = stmt.executeQuery();
while( {
catch (SQLException e) {
logger.error("Failed to execute sql statement: " + e.getMessage());
throw new MendixRuntimeException(e);
try {
objects = Core.retrieveIdList(getContext(), resultIDs);
catch (CoreException e) {
logger.error("Failed to retrieve objects by id: " + e.getMessage());
return objects;
return resultList;
* Returns a string representation of this action
public java.lang.String toString()
return "RetrieveObjectsByIdAdvancedSql";
private final ILogNode logger = Core.getLogger(this.getClass().getName());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment