Package org.pentaho.actionsequence.dom.actions

Examples of org.pentaho.actionsequence.dom.actions.SqlExecuteAction


    SQLConnection conn = (SQLConnection) connection;
    return runSqlQuery( conn, rawQuery, live );
  }

  protected boolean runSqlQuery( final SQLConnection conn, String rawQuery, final boolean live ) {
    SqlExecuteAction sqlExecuteAction = (SqlExecuteAction) getActionDefinition();
    boolean executed = false;
    boolean continueOnException = sqlExecuteAction.getContinueOnException().getBooleanValue( false );
    String[] columnHeaders =
        new String[] { Messages.getInstance().getString( "SQLExecute.USER_AFFECTED_ROWS_COLUMN_NAME" ), //$NON-NLS-1$
          Messages.getInstance().getString( "SQLExecute.USER_AFFECTED_ROW_STATUS" ) //$NON-NLS-1$
        };
    MemoryMetaData metaData = new MemoryMetaData( new String[][] { columnHeaders }, null );
    metaData.setColumnTypes( new String[] { "int", "string" } ); //$NON-NLS-1$ //$NON-NLS-2$
    MemoryResultSet affectedRowsResultSet = new MemoryResultSet( metaData );
    String successMsg = Messages.getInstance().getString( "SQLExecute.USER_SUCCESS" ); //$NON-NLS-1$
    String failMsg = Messages.getInstance().getString( "SQLExecute.USER_FAILED" ); //$NON-NLS-1$
    try {
      if ( conn == null ) {
        error( Messages.getInstance().getErrorString( "SQLBaseComponent.ERROR_0007_NO_CONNECTION" ) ); //$NON-NLS-1$
        return false;
      }
      if ( !conn.initialized() ) {
        error( Messages.getInstance().getErrorString( "SQLBaseComponent.ERROR_0007_NO_CONNECTION" ) ); //$NON-NLS-1$
        return false;
      }

      if ( sqlExecuteAction.getForceSingleStatement().getBooleanValue( false ) ) {
        // Forces original execution path.
        //
        // This execution path should be used if the query
        // has a semi-colon in the text of the SQL statement.
        //
        // This is a legitimate condition if there is (for example)
        // a statement with a where-clause that has a semi-colon.
        //
        // e.g.: UPDATE sometable SET somecolumn='val1;val2' WHERE somecolumn='val3;val4'
        //
        // In this case, using StringTokenizer on semi-colon will result in multiple un-executable
        // statements - the whole thing will fail.
        //
        // This is (arguably) unlikely, but it is possible. That's why I've chosen to make sure
        // that there is a mechanism for instating the old behavior.
        //
        String query = applyInputsToFormat( rawQuery );
        if ( ComponentBase.debug ) {
          debug( Messages.getInstance().getString( "SQLBaseComponent.DEBUG_RUNNING_QUERY", query ) ); //$NON-NLS-1$
        }
        int affectedRows = conn.execute( query );
        executed = true;
        affectedRowsResultSet.addRow( new Object[] { new Integer( affectedRows ), successMsg } );
      } else {
        //
        // Multiple statement execute support provided by contribution from Melanie Crouch
        //
        rawQuery = SQLExecute.removeLineTerminators( rawQuery.trim() ).toString();

        // tokenize the rawQuery passed into method to find if there are multiple updates to be executed.
        StringTokenizer st =
            new StringTokenizer( rawQuery, sqlExecuteAction.getMultiStatementSeparator().getStringValue( ";" ) ); //$NON-NLS-1$

        while ( st.hasMoreTokens() ) {
          // set rawQuery equal to the nextToken.
          rawQuery = st.nextToken();
          String query = applyInputsToFormat( rawQuery.trim() );
View Full Code Here

TOP

Related Classes of org.pentaho.actionsequence.dom.actions.SqlExecuteAction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.