/**
  * This method retrieves a connection based on the components inputs.
  *
  * @param defaultConnection a default connection to use if no other is available
  * @return new connection object
  */
 protected IPentahoConnection getConnection(final IPentahoConnection defaultConnection) {
   IPentahoConnection localConnection = null;
   try {
     String jndiName = null;
     String driver = null;
     String userId = null;
     String password = null;
     String connectionInfo = null;
     if (getActionDefinition() instanceof SqlConnectionAction) {
       SqlConnectionAction sqlConnectionAction = (SqlConnectionAction) getActionDefinition();
       jndiName = sqlConnectionAction.getJndi().getStringValue();
       driver = sqlConnectionAction.getDriver().getStringValue();
       userId = sqlConnectionAction.getUserId().getStringValue();
       password = sqlConnectionAction.getPassword().getStringValue();
       connectionInfo = sqlConnectionAction.getDbUrl().getStringValue();
     } else if (getActionDefinition() instanceof AbstractRelationalDbAction) {
       AbstractRelationalDbAction relationalDbAction =
           (AbstractRelationalDbAction) getActionDefinition();
       jndiName = relationalDbAction.getJndi().getStringValue();
       driver = relationalDbAction.getDriver().getStringValue();
       userId = relationalDbAction.getUserId().getStringValue();
       password = relationalDbAction.getPassword().getStringValue();
       connectionInfo = relationalDbAction.getDbUrl().getStringValue();
     }
     if (jndiName != null) {
       localConnection =
           PentahoConnectionFactory.getConnection(
               IPentahoConnection.SQL_DATASOURCE, jndiName, getSession(), this);
     }
     if (localConnection == null) {
       localConnection =
           PentahoConnectionFactory.getConnection(
               IPentahoConnection.SQL_DATASOURCE,
               driver,
               connectionInfo,
               userId,
               password,
               getSession(),
               this);
     }
     if (localConnection == null) {
       if (defaultConnection == null) {
         error(
             Messages.getInstance()
                 .getErrorString("SQLBaseComponent.ERROR_0005_INVALID_CONNECTION")); // $NON-NLS-1$
         return null;
       } else {
         localConnection = defaultConnection;
       }
     }
     return localConnection;
   } catch (Exception e) {
     error(
         Messages.getInstance()
             .getErrorString("SQLBaseComponent.ERROR_0006_EXECUTE_FAILED", getActionName()),
         e); //$NON-NLS-1$
   }
   return null;
 }
  /**
   * validates the action. checks to verify inputs are available to execute
   *
   * <p>- verify query is available - verify connection is available, via jndi, connection string,
   * or prepared component - verify output is specified
   */
  @Override
  public boolean validateAction() {
    boolean result = true;

    IActionDefinition actionDefinition = getActionDefinition();
    String actionName = getActionName();

    if (actionDefinition instanceof AbstractRelationalDbAction) {
      AbstractRelationalDbAction relationalDbAction = (AbstractRelationalDbAction) actionDefinition;
      IActionInput query = relationalDbAction.getQuery();
      IActionInput dbUrl = relationalDbAction.getDbUrl();
      IActionInput jndi = relationalDbAction.getJndi();

      IActionInput sharedConnection = relationalDbAction.getSharedConnection();
      if (query == ActionInputConstant.NULL_INPUT) {

        error(
            Messages.getInstance()
                .getErrorString(
                    "SQLBaseComponent.ERROR_0001_QUERY_NOT_SPECIFIED", actionName)); // $NON-NLS-1$
        result = false;
      }

      if ((jndi == ActionInputConstant.NULL_INPUT)
          && (dbUrl == ActionInputConstant.NULL_INPUT)
          && (sharedConnection == ActionInputConstant.NULL_INPUT)) {
        error(
            Messages.getInstance()
                .getErrorString(
                    "SQLBaseComponent.ERROR_0002_CONNECTION_NOT_SPECIFIED",
                    actionName)); //$NON-NLS-1$
        result = false;
      }
    } else if (actionDefinition instanceof SqlConnectionAction) {
      SqlConnectionAction sqlConnectionAction = (SqlConnectionAction) actionDefinition;
      IActionInput dbUrl = sqlConnectionAction.getDbUrl();
      IActionInput jndi = sqlConnectionAction.getJndi();
      if ((jndi == ActionInputConstant.NULL_INPUT) && (dbUrl == ActionInputConstant.NULL_INPUT)) {
        error(
            Messages.getInstance()
                .getErrorString(
                    "SQLBaseComponent.ERROR_0002_CONNECTION_NOT_SPECIFIED",
                    actionName)); //$NON-NLS-1$
        result = false;
      }
    } else {
      error(
          Messages.getInstance()
              .getErrorString(
                  "ComponentBase.ERROR_0001_UNKNOWN_ACTION_TYPE",
                  actionDefinition.getElement().asXML())); // $NON-NLS-1$
      result = false;
    }
    return result;
  }