timyates / mod-jdbc-persistor

BusMod Persistor for JDBC support in vert.x
Other
36 stars 14 forks source link

JDBC Result set from HANA procedure part 2 #34

Open tbealby opened 8 years ago

tbealby commented 8 years ago

This is a continuation of 'JDBC Result set from HANA procedure #33'

I have now (at last!) managed to get the result set back from my HANA procedure with the following code using a regular JDBC connection

String sql = "CALL "XX_SCHEMANAME\".mySprocName(?,?,?,?)"; CallableStatement callableStatement = connection.prepareCall(sql); callableStatement.setString(1, "val1"); callableStatement.setString(2, "val2"); callableStatement.setString(3, "val3"); callableStatement.setInt(4, 123); boolean b = callableStatement.execute(); resultSet = callableStatement.getResultSet();


Please will you let me know whether vertx is using callable statements any where? I can't see that it does.

The following dirty hack of JdbcProcessor.doSelect gets me back the result set from the HANA procedure

private void doSelect( final Message message, Connection connection, TransactionalHandler transaction ) throws SQLException { new BatchHandler( connection, message, transaction ) { public JsonObject process() throws SQLException { JsonObject reply = new JsonObject() ; ArrayList<Map<String,Object>> result = new ArrayList<Map<String,Object>>() ; // processing while( ( resultSet != null || valueIterator.hasNext() ) && ( batchSize == -1 || result.size() < batchSize ) ) { LimitedMapListHandler handler = new LimitedMapListHandler( batchSize == -1 ? -1 : batchSize - result.size() ) ; if( resultSet == null ) { List params = valueIterator.next() ; boolean callable = params.size() > 1;// <-----------Flag value is hacked here - needs passing from client properly. if (callable) { String sql = message.body().getString( "stmt" ) ; statement = connection.prepareCall(sql); int i = 1; for (Object param: params) { statement.setObject(i++, param); } boolean isResultSet = statement.execute(); if (isResultSet) { resultSet = statement.getResultSet(); } } else { statementFiller.fill( statement, params ) ; resultSet = statement.executeQuery() ; } } store( result, handler ) ; } reply.putArray( "result", JsonUtils.listOfMapsToJsonArray( result ) ) ; return reply ; } }.handle( message ) ; }