// This file was generated by Mendix Modeler.
//
// 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 databaseconnector.actions;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.mendix.core.Core;
import com.mendix.logging.ILogNode;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.systemwideinterfaces.core.IMendixObject;
import com.mendix.systemwideinterfaces.core.meta.IMetaObject;
import com.mendix.webui.CustomJavaAction;
import databaseconnector.impl.JdbcConnector;

/**
 * <p>
 * This Java action provides a consistent environment for Mendix projects to perform an arbitrary SELECT SQL query on relational external databases.
 * JDBC (Java Database Connectivity) API, a standard Java API, is used when this Java action attempts
 * to connect with a Relational Database for which a JDBC driver exists.
 * The JDBC drivers for the databases you want to connect to, must be placed inside the userlib directory of a project.
 * </p>
 * 
 * Do not use this Java action for INSERT, UPDATE, DELETE or DDL queries.
 * This action returns a list of Mendix objects based on the JDBC result set.
 * The jdbcUrl argument must specify a database URL address that points to your relational database and is dependent
 * upon the particular database and JDBC driver. It will always begin with "jdbc:" protocol, but the rest is up to particular vendor.
 * For example 'jdbc:mysql://hostname/databaseName' jdbcUrl format can be used for MySQL databases.
 * Note: Proper security must be applied as this action can allow SQL Injection in your Mendix application.
 * 
 * @see    JdbcConnector
 * @since  Mendix World 2016
 * @param <String> jdbcUrl
 *    A database URL address that points to your database.
 * 
 * @param <String> userName 
 *    The user name for logging into the database, relative to the jdbcUrl argument.
 * 
 * @param <String> password 
 *    The password for logging into the database, relative to the jdbcUrl argument.
 * 
 * @param <String> sql
 *    The SELECT query to be performed, relative to the database type.
 * 
 * @param <IMendixObject> resultObject
 *    An instance of the resulting object. This instance is used only for defining the type of object to be returned.
 * 
 * @return <List<IMendixObject>>
 *    SELECT Query result as a list of objects.
 */
public class ExecuteQuery extends CustomJavaAction<java.util.List<IMendixObject>>
{
	private java.lang.String jdbcUrl;
	private java.lang.String userName;
	private java.lang.String password;
	private java.lang.String sql;
	private IMendixObject resultObject;

	public ExecuteQuery(IContext context, java.lang.String jdbcUrl, java.lang.String userName, java.lang.String password, java.lang.String sql, IMendixObject resultObject)
	{
		super(context);
		this.jdbcUrl = jdbcUrl;
		this.userName = userName;
		this.password = password;
		this.sql = sql;
		this.resultObject = resultObject;
	}

	@java.lang.Override
	public java.util.List<IMendixObject> executeAction() throws Exception
	{
		// BEGIN USER CODE
		IMetaObject metaObject = resultObject.getMetaObject();
		Stream<IMendixObject> resultStream = connector.executeQuery(
		    this.jdbcUrl, this.userName, this.password, metaObject, this.sql, this.getContext());
		List<IMendixObject> resultList = resultStream.collect(Collectors.toList());
		logNode.trace(String.format("Result list count: %d", resultList.size()));

		return resultList;
		// END USER CODE
	}

	/**
	 * Returns a string representation of this action
	 */
	@java.lang.Override
	public java.lang.String toString()
	{
		return "ExecuteQuery";
	}

	// BEGIN EXTRA CODE
	private final ILogNode logNode = Core.getLogger(this.getClass().getName());

	private final JdbcConnector connector = new JdbcConnector(logNode);
	// END EXTRA CODE
}

@@ -2960,29 +2960,32 @@
 private 
-IMendixObject
+java.lang.String
  resultO
@@ -2989,16 +2989,20 @@
 ltObject
+Type
 ;%0D%0A%0D%0A%09pu
@@ -3139,29 +3139,32 @@
 ng sql, 
-IMendixObject
+java.lang.String
  resultO
@@ -3168,16 +3168,20 @@
 ltObject
+Type
 )%0D%0A%09%7B%0D%0A%09
@@ -3317,24 +3317,28 @@
 resultObject
+Type
  = resultObj
@@ -3340,16 +3340,20 @@
 ltObject
+Type
 ;%0D%0A%09%7D%0D%0A%0D
@@ -3504,35 +3504,48 @@
 t = 
-resultObject.getMeta
+Core.getMetaObject(this.result
 Object
-(
+Type
 );%0D%0A

Replace instance object by generic type argument