public List<EventBean> poll(Object[] lookupValues) { List<EventBean> rowResult = null; try { Object invocationResult = method.invoke(null, lookupValues); if (invocationResult != null) { if (isArray) { int length = Array.getLength(invocationResult); if (length > 0) { rowResult = new ArrayList<EventBean>(); for (int i = 0; i < length; i++) { Object value = Array.get(invocationResult, i); if (value == null) { log.warn( "Expected non-null return result from method '" + method.getName() + "', but received null value"); continue; } EventBean theEvent; if (useMapType) { if (!(value instanceof Map)) { log.warn( "Expected Map-type return result from method '" + method.getName() + "', but received type '" + value.getClass() + "'"); continue; } Map mapValues = (Map) value; theEvent = eventAdapterService.adapterForTypedMap(mapValues, eventType); } else { theEvent = eventAdapterService.adapterForBean(value); } rowResult.add(theEvent); } } } else { rowResult = new LinkedList<EventBean>(); EventBean theEvent; if (useMapType) { if (!(invocationResult instanceof Map)) { log.warn( "Expected Map-type return result from method '" + method.getName() + "', but received type '" + invocationResult.getClass() + "'"); } else { Map mapValues = (Map) invocationResult; theEvent = eventAdapterService.adapterForTypedMap(mapValues, eventType); rowResult.add(theEvent); } } else { theEvent = eventAdapterService.adapterForBean(invocationResult); rowResult.add(theEvent); } } } } catch (InvocationTargetException ex) { throw new EPException( "Method '" + method.getName() + "' of class '" + method.getJavaMethod().getDeclaringClass().getName() + "' reported an exception: " + ex.getTargetException(), ex.getTargetException()); } return rowResult; }
private List<EventBean> execute( PreparedStatement preparedStatement, Object[] lookupValuePerStream) { if (ExecutionPathDebugLog.isDebugEnabled && log.isInfoEnabled()) { log.info(".execute Executing prepared statement '" + preparedStatementText + "'"); } // set parameters SQLInputParameterContext inputParameterContext = null; if (columnTypeConversionHook != null) { inputParameterContext = new SQLInputParameterContext(); } int count = 1; for (int i = 0; i < lookupValuePerStream.length; i++) { try { Object parameter = lookupValuePerStream[i]; if (ExecutionPathDebugLog.isDebugEnabled && log.isInfoEnabled()) { log.info( ".execute Setting parameter " + count + " to " + parameter + " typed " + ((parameter == null) ? "null" : parameter.getClass())); } if (columnTypeConversionHook != null) { inputParameterContext.setParameterNumber(i + 1); inputParameterContext.setParameterValue(parameter); parameter = columnTypeConversionHook.getParameterValue(inputParameterContext); } setObject(preparedStatement, count, parameter); } catch (SQLException ex) { throw new EPException("Error setting parameter " + count, ex); } count++; } // execute ResultSet resultSet; if (enableJDBCLogging && jdbcPerfLog.isInfoEnabled()) { long startTimeNS = System.nanoTime(); long startTimeMS = System.currentTimeMillis(); try { resultSet = preparedStatement.executeQuery(); } catch (SQLException ex) { throw new EPException("Error executing statement '" + preparedStatementText + '\'', ex); } long endTimeNS = System.nanoTime(); long endTimeMS = System.currentTimeMillis(); jdbcPerfLog.info( "Statement '" + preparedStatementText + "' delta nanosec " + (endTimeNS - startTimeNS) + " delta msec " + (endTimeMS - startTimeMS)); } else { try { resultSet = preparedStatement.executeQuery(); } catch (SQLException ex) { throw new EPException("Error executing statement '" + preparedStatementText + '\'', ex); } } // generate events for result set List<EventBean> rows = new LinkedList<EventBean>(); try { SQLColumnValueContext valueContext = null; if (columnTypeConversionHook != null) { valueContext = new SQLColumnValueContext(); } SQLOutputRowValueContext rowContext = null; if (outputRowConversionHook != null) { rowContext = new SQLOutputRowValueContext(); } int rowNum = 0; while (resultSet.next()) { int colNum = 1; Map<String, Object> row = new HashMap<String, Object>(); for (Map.Entry<String, DBOutputTypeDesc> entry : outputTypes.entrySet()) { String columnName = entry.getKey(); Object value; DatabaseTypeBinding binding = entry.getValue().getOptionalBinding(); if (binding != null) { value = binding.getValue(resultSet, columnName); } else { value = resultSet.getObject(columnName); } if (columnTypeConversionHook != null) { valueContext.setColumnName(columnName); valueContext.setColumnNumber(colNum); valueContext.setColumnValue(value); valueContext.setResultSet(resultSet); value = columnTypeConversionHook.getColumnValue(valueContext); } row.put(columnName, value); colNum++; } EventBean eventBeanRow = null; if (this.outputRowConversionHook == null) { eventBeanRow = eventAdapterService.adapterForTypedMap(row, eventType); } else { rowContext.setValues(row); rowContext.setRowNum(rowNum); rowContext.setResultSet(resultSet); Object rowData = outputRowConversionHook.getOutputRow(rowContext); if (rowData != null) { eventBeanRow = eventAdapterService.adapterForTypedBean(rowData, (BeanEventType) eventType); } } if (eventBeanRow != null) { rows.add(eventBeanRow); rowNum++; } } } catch (SQLException ex) { throw new EPException( "Error reading results for statement '" + preparedStatementText + '\'', ex); } if (enableJDBCLogging && jdbcPerfLog.isInfoEnabled()) { jdbcPerfLog.info("Statement '" + preparedStatementText + "' " + rows.size() + " rows"); } try { resultSet.close(); } catch (SQLException ex) { throw new EPException("Error closing statement '" + preparedStatementText + '\'', ex); } return rows; }