/** dispose of the resultset, and if the owner, dispose of the connection. */ public void dispose() { rSet = null; // close connection if owner if (connectionOwner) { if (connection != null) { connection.close(); } connection = null; } }
/** * executes the specified query template. The query template is first formatted and then executed. * If live, the original result set is made available as an output. If not live, the result set is * converted into memory and the connection and live result set are closed. * * @param rawQuery query template * @param live returns original result set if true, memory result set if false * @return true if successful */ protected boolean runQuery(final String rawQuery, boolean live) { try { if ((connection == null) || !connection.initialized()) { error( Messages.getInstance() .getErrorString("SQLBaseComponent.ERROR_0007_NO_CONNECTION")); // $NON-NLS-1$ return false; } String query = applyInputsToFormat(rawQuery); SQLConnection sqlConnection = null; if ((connection instanceof SQLConnection)) { sqlConnection = (SQLConnection) connection; } // Some of the following Added by Arijit Chatterjee passing the timeout value to SQLConnection // class if (sqlConnection != null) { if (this.getQueryTimeout() >= 0) { sqlConnection.setQueryTimeout(this.getQueryTimeout()); } if (this.getMaxRows() >= 0) { sqlConnection.setMaxRows(this.getMaxRows()); } if (this.getReadOnly()) { sqlConnection.setReadOnly(true); } } AbstractRelationalDbAction relationalDbAction = (AbstractRelationalDbAction) getActionDefinition(); IPentahoResultSet resultSet = null; boolean isForwardOnly = relationalDbAction.getUseForwardOnlyResultSet().getBooleanValue(false); resultSet = doQuery(sqlConnection, query, isForwardOnly); if (sqlConnection.isForcedForwardOnly()) { isForwardOnly = true; live = false; warn( Messages.getInstance() .getString("SQLBaseComponent.WARN_FALL_BACK_TO_NONSCROLLABLE")); // $NON-NLS-1$ } if (live) { // set the result set as the output rSet = resultSet; // After preparation and execution, we need to clear out the // prepared parameters. preparedParameters.clear(); if (resultSet != null) { getMetadata(resultSet, true); IActionOutput actionOutput = relationalDbAction.getOutputResultSet(); if (actionOutput != null) { actionOutput.setValue(resultSet); } return true; } else { // close the connection if owner error( Messages.getInstance() .getErrorString( "SQLBaseComponent.ERROR_0006_EXECUTE_FAILED", getActionName())); //$NON-NLS-1$ if (connectionOwner) { connection.close(); } return false; } } else { // execute the query, read the results and cache them try { // After preparation and execution, we need to clear out the // prepared parameters. preparedParameters.clear(); IPentahoResultSet cachedResultSet = resultSet.memoryCopy(); rSet = cachedResultSet; IActionOutput actionOutput = relationalDbAction.getOutputResultSet(); if (actionOutput != null) { actionOutput.setValue(cachedResultSet); } } finally { // close the connection if owner if (connectionOwner) { connection.close(); connection = null; } } } return true; } catch (Exception e) { error( Messages.getInstance() .getErrorString("SQLBaseComponent.ERROR_0006_EXECUTE_FAILED", getActionName()), e); //$NON-NLS-1$ } return false; }