Unable to pass a class(object) while passing as payload(Connection context)
anilnair Sep 1, 2015 11:06 PMHi All,
I have a custom translator which accepts a class in different package . Payloadf class resides in the same package as class which extends.JDBCQueryExecution
jboss with teiid starts fine without any errors but when i try to txecute query by passing payload from the client I get ClassNotFound execption for the payload class.
Please note when I try to pass int or string directly instead of class it all works fine , assuming something to do with the serialization of custom class(though my custom class is serializable I still get ClassNotFound exception)
Here is the code that I am using
I have set added dependency in the module.xml file as mentioned in the documentation
<?xml version="1.0" encoding="UTF-8"?> <module xmlns="urn:jboss:module:1.0" name="MyApp.teiid.translator"> <resources> <resource-root path="MyApp-teiid-translator-5.jar" /> <!-- This jar file that has the translator--> path="MyApp-teiid-translator-5.jar" /> <!--This jar has the dependencies where the payload and class which implements JDBCExecutionFactory) </resources> <dependencies> <module name="javax.api" /> <module name="javax.resource.api" /> <module name="org.jboss.teiid.common-core" /> <module name="org.jboss.teiid.api" /> <module name="org.jboss.teiid.translator.jdbc" /> </dependencies> </module>
Class which extends JDBCQueryExecution
public class MultiEmployeeQueryExecutor extends org.teiid.translator.jdbc.JDBCQueryExecution { private Connection sqlconnection; private TeiidSqlServerPayload payload; private static final Logger LOGGER = LoggerFactory .getLogger(MultiTenantQueryExecutor.class); public MultiEmployeeQueryExecutor(Command command, Connection connection, ExecutionContext context, JDBCExecutionFactory env, TeiidSqlServerPayload teiidsqlserverpayload) { super(command, connection, context, env); this.sqlconnection = connection; this.payload = teiidsqlserverpayload; } @Override public void close() { super.close(); try { afterExecution(); } catch (SQLException e) { LOGGER.error("Translator afterExecution error: {}", e); } } @Override public void execute() throws TranslatorException { try { beforeExecution(); } catch (SQLException e) { LOGGER.error("Translator execute error {}", e); throw new TranslatorException(e); } super.execute(); } private void beforeExecution() throws SQLException { try (CallableStatement cstmt = sqlconnection .prepareCall("{call spSetEmployeeInfo (?, ?)}")) { cstmt.setInt(1, payload.getEmpId()); cstmt.setInt(2, payload.getDeptId()); cstmt.execute(); } } private void afterExecution() throws SQLException { try (CallableStatement cstmt = sqlconnection .prepareCall("{call spResetEmployeeInfo}")) { cstmt.execute(); } } }
The Payload class
public class TeiidSqlServerPayload implements Serializable { private static final long serialVersionUID = 4736614740664143158L; private int empId; private int deptId; public int getEmpId() { return EmpId; } public void setEmpId(int empId) { this.empId = empId; } public int getDeptId() { return deptId; } public void setDeptId(int deptId) { this.deptId = deptId; } }
The Translator class calling the class that extends JDBCQueryExecution
@Translator(name = "MyApp-translator", description = "") public class MyAppExecutionFactory extends JDBCExecutionFactory { @Override public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Connection conn) throws TranslatorException { TeiidSqlServerPayload payload = (TeiidSqlServerPayload) executionContext .getCommandPayload(); MultiEmployeeQueryExecutor exec = new MultiEmployeeQueryExecutor(command, conn, executionContext, this, payload); return exec; } }
Thanks
Anil