MDXBaseComponent extends ComponentBase implements IDataComponent, IPreparedComponent { public IPentahoResultSet executePrepared( final Map preparedParams ) { try { if ( connection == null ) { error( Messages.getInstance().getErrorString( "MDXBaseComponent.ERROR_0008_NO_CONNECTION" ) ); return null; } if ( !connection.initialized() ) { error( Messages.getInstance().getErrorString( "MDXBaseComponent.ERROR_0008_NO_CONNECTION" ) ); return null; } if ( preparedQuery == null ) { error( Messages.getInstance().getErrorString( "MDXBaseComponent.ERROR_0001_QUERY_NOT_SPECIFIED", getActionName() ) ); return null; } String query = TemplateUtil.applyTemplate( preparedQuery, getRuntimeContext(), new MapParameterResolver( preparedParams, IPreparedComponent.PREPARE_LATER_PREFIX, getRuntimeContext() ) ); if ( ComponentBase.debug ) { debug( Messages.getInstance().getString( "MDXBaseComponent.DEBUG_RUNNING_QUERY", query ) ); } IPentahoResultSet resultSet = connection.executeQuery( query ); rSet = resultSet; return resultSet; } catch ( Exception e ) { error( Messages.getInstance().getErrorString( "MDXBaseComponent.ERROR_0006_EXECUTE_FAILED", getActionName() ), e ); } return null; }  @Override abstract boolean validateSystemSettings(); @Override abstract Log getLogger(); IPentahoResultSet getResultSet(); @Override void done(); void dispose(); IPentahoConnection shareConnection(); IPentahoResultSet executePrepared( final Map preparedParams ); IPentahoConnection getDatasourceConnection(); @Override boolean init(); static final String FORMATTED_CELL_VALUES; }
@Test public void testExecutePrepared_nullConnection() throws Exception { Map params = new HashMap(); assertNull( mdxBaseComponent.executePrepared( params ) ); }
@Test public void testExecutePrepared() throws Exception { Map params = new HashMap(); when( conn.initialized() ).thenReturn( true ); mdxBaseComponent.setConnection( conn ); mdxBaseComponent.preparedQuery = "select * from table where x = ?"; when( conn.executeQuery( anyString() ) ).thenReturn( resultSet ); doReturn( runtimeContext ).when( mdxBaseComponent ).getRuntimeContext(); Set inputs = new HashSet(); when( runtimeContext.getInputNames() ).thenReturn( inputs ); when( runtimeContext.getParameterManager() ).thenReturn( paramManager ); when( paramManager.getCurrentInputNames() ).thenReturn( inputs ); IPentahoResultSet result = mdxBaseComponent.executePrepared( params ); assertNotNull( result ); assertEquals( resultSet, result ); assertEquals( resultSet, mdxBaseComponent.getResultSet() ); }