Package org.pentaho.commons.connection

Examples of org.pentaho.commons.connection.IPentahoResultSet


    Matcher parameterMatcher = parameterPattern.matcher( template );
    ArrayList<String> partsList = new ArrayList<String>();
    ArrayList<Integer> columnsList = new ArrayList<Integer>();
    int idx = 0;
    int lastEnd = 0;
    IPentahoResultSet data = null;
    while ( parameterMatcher.find() ) {
      int start = parameterMatcher.start();
      String parameter = parameterMatcher.group( 1 );
      // pull out the repeating part
      int pos1 = parameter.indexOf( ":col:" ); //$NON-NLS-1$
      if ( pos1 > -1 ) {
        String part = template.substring( lastEnd, start );
        if ( PentahoSystem.debug ) {
          TemplateUtil.logger.debug( "parameter=" + parameter ); //$NON-NLS-1$
          TemplateUtil.logger.debug( "part=" + part ); //$NON-NLS-1$
        }
        String inputName = parameter.substring( 0, pos1 );
        String columnNoStr = parameter.substring( pos1 + 5 );
        int columnNo = Integer.parseInt( columnNoStr );
        if ( PentahoSystem.debug ) {
          TemplateUtil.logger.debug( "inputName=" + inputName ); //$NON-NLS-1$
          TemplateUtil.logger.debug( "columnNoStr=" + columnNoStr ); //$NON-NLS-1$
          TemplateUtil.logger.debug( "columnNo=" + columnNo ); //$NON-NLS-1$
        }
        Object obj = null;
        if ( inputs instanceof InputProperties ) {
          obj = ( (InputProperties) inputs ).getInput( inputName );
        }
        if ( obj == null ) {
          if ( TemplateUtil.logger.isDebugEnabled() ) {
            TemplateUtil.logger.debug( Messages.getInstance().getString( "TemplateUtil.NOT_FOUND", inputName ) ); //$NON-NLS-1$
          }
        } else {
          if ( obj instanceof IPentahoResultSet ) {
            data = (IPentahoResultSet) obj;
            if ( columnNo < data.getColumnCount() ) {
              columnsList.add( new Integer( columnNo ) );
            } else {
              TemplateUtil.logger.warn( Messages.getInstance().getString(
                  "TemplateUtil.INVALID_COLUMN", String.valueOf( columnNo ) ) ); //$NON-NLS-1$
            }
          }
        }
        partsList.add( part );
        lastEnd = parameterMatcher.end();
      }
    }
    if ( PentahoSystem.debug ) {
      TemplateUtil.logger.debug( "partsList.size()=" + partsList.size() ); //$NON-NLS-1$
    }
    if ( PentahoSystem.debug ) {
      TemplateUtil.logger.debug( "columnsList.size()=" + columnsList.size() ); //$NON-NLS-1$
    }
    if ( PentahoSystem.debug ) {
      TemplateUtil.logger.debug( "data=" + data ); //$NON-NLS-1$
    }
    if ( partsList.size() > 0 ) {
      partsList.add( template.substring( lastEnd ) );
    } else {
      TemplateUtil.logger.warn( Messages.getInstance().getString( "TemplateUtil.NO_TOKEN" ) ); //$NON-NLS-1$
    }

    if ( ( data != null ) && ( partsList.size() == columnsList.size() + 1 ) ) {
      // here we go
      String[] parts = new String[partsList.size()];
      partsList.toArray( parts );
      Integer[] cols = new Integer[columnsList.size()];
      columnsList.toArray( cols );
      int rowNo = 0;
      Object[] row = data.getDataRow( rowNo );
      while ( row != null ) {
        for ( idx = 0; idx < cols.length; idx++ ) {
          results.append( parts[idx] );
          results.append( row[cols[idx].intValue()] );
        }
        results.append( parts[parts.length - 1] );
        rowNo++;
        row = data.getDataRow( rowNo );
      }
    }
    if ( PentahoSystem.debug ) {
      TemplateUtil.logger.debug( "results=" + results.toString() ); //$NON-NLS-1$
    }
View Full Code Here


        // leave the text alone
        return "{" + parameter + ":" + keyColumn + ":" + keyValue + ":" + valueColumn + ":" + defaultValue + "}"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
      }
      Object valueObj = context.getInputParameterValue( parameter );
      if ( valueObj instanceof IPentahoResultSet ) {
        IPentahoResultSet data = (IPentahoResultSet) valueObj;
        // this is slow
        // TODO implement mapping or sorting here to improve performance
        int keyColumnNo = data.getMetaData().getColumnIndex( keyColumn );
        if ( keyValue.indexOf( '_' ) > 0 ) {
          keyValue = keyValue.replace( '_', ' ' );
        }
        int valueColumnNo = data.getMetaData().getColumnIndex( valueColumn );
        if ( ( keyColumnNo != -1 ) && ( valueColumnNo != -1 ) ) {
          for ( int row = 0; row < data.getRowCount(); row++ ) {
            Object thisKey = data.getValueAt( row, keyColumnNo );
            if ( thisKey != null ) {
              if ( keyValue.equals( thisKey.toString() ) ) {
                // we found the value
                // TODO support typing here
                return data.getValueAt( row, valueColumnNo ).toString();
              }
            }
          }
        }
      }
View Full Code Here

            }
          }
          String valueStr = valuesBuffer.toString();
          value = valueStr.substring( 1, valueStr.length() - 1 );
        } else if ( valueObj instanceof IPentahoResultSet ) {
          IPentahoResultSet rs = (IPentahoResultSet) valueObj;
          // See if we can find a column in the metadata with the same
          // name as the input
          IPentahoMetaData md = rs.getMetaData();
          int columnIdx = -1;
          if ( md.getColumnCount() == 1 ) {
            columnIdx = 0;
          } else {
            columnIdx = md.getColumnIndex( new String[] { name } );
          }
          if ( columnIdx < 0 ) {
            InputProperties.inputPropertiesLogger.error( Messages.getInstance().getErrorString(
                "Template.ERROR_0005_COULD_NOT_DETERMINE_COLUMN" ) ); //$NON-NLS-1$
            return null;
          }
          int rowCount = rs.getRowCount();
          Object valueCell = null;
          StringBuffer valuesBuffer = new StringBuffer();
          // TODO support non-string columns
          for ( int i = 0; i < rowCount; i++ ) {
            valueCell = rs.getValueAt( i, columnIdx );
            if ( i == 0 ) {
              valuesBuffer.append( "'" ).append( valueCell.toString() ).append( "'" ); //$NON-NLS-1$ //$NON-NLS-2$
            } else {
              valuesBuffer.append( ",'" ).append( valueCell.toString() ).append( "'" ); //$NON-NLS-1$ //$NON-NLS-2$
            }
View Full Code Here

    IActionParameter rtn1 = context.getOutputParameter( "prepared_component" ); //$NON-NLS-1$
    assertNotNull( rtn1 );
    IPreparedComponent preparedComponent1 = (IPreparedComponent) rtn1.getValue();
    assertNotNull( preparedComponent1 );
    IPentahoResultSet resultset1 = preparedComponent1.executePrepared( null );
    assertTrue( resultset1.getRowCount() >= 1 );
    Object val1 = resultset1.getValueAt( 0, 0 );

    IActionParameter rtn2 = context.getOutputParameter( "second_prepared_component" ); //$NON-NLS-1$
    assertNotNull( rtn2 );
    IPreparedComponent preparedComponent2 = (IPreparedComponent) rtn2.getValue();
    assertNotNull( preparedComponent2 );
    HashMap map = new HashMap();
    map.put( "POSITIONTITLE", "Engineer" ); //$NON-NLS-1$ //$NON-NLS-2$
    IPentahoResultSet resultset2 = preparedComponent2.executePrepared( map );
    assertTrue( resultset2.getRowCount() >= 1 );
    assertEquals( resultset1.getRowCount(), resultset2.getRowCount() );

    Object val2 = resultset2.getValueAt( 0, 0 );

    assertEquals( "Values from the first and second query should be equal", val1, val2 ); //$NON-NLS-1$

    finishTest();
  }
View Full Code Here

    IActionParameter rtn1 = context.getOutputParameter( "prepared_component" ); //$NON-NLS-1$
    assertNotNull( rtn1 );
    IPreparedComponent preparedComponent1 = (IPreparedComponent) rtn1.getValue();
    assertNotNull( preparedComponent1 );
    IPentahoResultSet resultset1 = preparedComponent1.executePrepared( null );
    assertTrue( resultset1.getRowCount() >= 1 );
    Object val1 = resultset1.getValueAt( 0, 0 );
    assertNotNull( val1 );

    finishTest();
  }
View Full Code Here

  @Override
  protected boolean executeAction() {
    Object resultSetObject = getInputValue( "result-set" ); //$NON-NLS-1$
    if ( resultSetObject instanceof IPentahoResultSet ) {
      IPentahoResultSet resultset = (IPentahoResultSet) resultSetObject;
      if ( getResultOutputName() != null ) {
        setOutputValue( getResultOutputName(), DataUtilities.getXMLString( resultset ) );
      }
      return true;
    } else {
View Full Code Here

        } else if ( StandardSettings.DATE_FORMAT_TYPE.equalsIgnoreCase( sortFormatType ) ) {
          sortFormat = new SimpleDateFormat( sortFormatString );
        }
      }

      IPentahoResultSet rSet = null;

      if ( isDefinedInput( ResultSetCrosstabComponent.OLD_STYLE_CROSSTAB ) ) {
        warn( Messages.getInstance().getString( "ResultSetCrosstabComponent.WARN_DEPRECATED" ) ); //$NON-NLS-1$
        rSet =
            PentahoDataTransmuter.crossTab( (IPentahoResultSet) resultSetObject, columnToPivot - 1, measuresColumn - 1,
View Full Code Here

    MetadataQueryComponent component = new MetadataQueryComponent();
    component.setQuery( mql );
    component.execute();

    IPentahoResultSet rs = component.getResultSet();
    try {
      Assert.assertNotNull( rs );
      Assert.assertEquals( 16, rs.getRowCount() );
      Object[] obj;
      while ( ( obj = rs.next() ) != null ) {
        System.out.println( obj[0] );
      }

    } finally {
      if ( rs != null ) {
        rs.close();
        rs.closeConnection();
      }
    }

    component = new MetadataQueryComponent();
    Map<String, Object> inputs = new HashMap<String, Object>();
    inputs.put( "param1", "B%" );
    component.setInputs( inputs );
    component.setQuery( mql );
    component.execute();

    rs = component.getResultSet();
    try {
      Assert.assertNotNull( rs );
      Assert.assertEquals( 5, rs.getRowCount() );
      Object[] obj;
      while ( ( obj = rs.next() ) != null ) {
        System.out.println( obj[0] );
      }

    } finally {
      if ( rs != null ) {
        rs.close();
        rs.closeConnection();
      }
    }

  }
View Full Code Here

    MetadataQueryComponent component = new MetadataQueryComponent();
    component.setQuery( mql );
    component.execute();

    IPentahoResultSet rs = component.getResultSet();
    try {
      Assert.assertNotNull( rs );
      Assert.assertEquals( 2, rs.getRowCount() );
      Object[] obj;
      while ( ( obj = rs.next() ) != null ) {
        System.out.println( obj[0] );
      }

    } finally {
      rs.close();
      rs.closeConnection();
    }

    component = new MetadataQueryComponent();
    Map<String, Object> inputs = new HashMap<String, Object>();
    inputs.put( "param1", new String[] { "BG&E Collectables", "Baane Mini Imports",
      "Bavarian Collectables Imports, Co.", "Boards & Toys Co." } );
    component.setInputs( inputs );
    component.setQuery( mql );
    component.execute();

    rs = component.getResultSet();
    try {
      Assert.assertNotNull( rs );
      Assert.assertEquals( 4, rs.getRowCount() );
      Object[] obj;
      while ( ( obj = rs.next() ) != null ) {
        System.out.println( obj[0] );
      }

    } finally {
      rs.close();
      rs.closeConnection();
    }

    mql =
        "<mql><domain_id>DOMAIN</domain_id><model_id>MODEL</model_id>"
            + "<parameters><parameter name=\"param1\" type=\"NUMERIC\" defaultValue=\"1504|1337\"/></parameters>"
            + "<selections><selection>"
            + "<view>CATEGORY</view>"
            + "<column>LC_CUSTOMERNAME</column>"
            + "</selection><selection>"
            + "<view>CATEGORY</view>"
            + "<column>LC_SALESREP</column>"
            + "</selection>"
            + "</selections>"
            + "<constraints>"
            + "<constraint><operator>AND</operator><condition>EQUALS([CATEGORY.LC_SALESREP];"
            + "[param:param1])</condition></constraint>"
            + "</constraints>" + "</mql>";

    component = new MetadataQueryComponent();
    component.setQuery( mql );
    component.execute();

    rs = component.getResultSet();
    try {
      Assert.assertNotNull( rs );
      Assert.assertEquals( 15, rs.getRowCount() );
      Object[] obj;
      while ( ( obj = rs.next() ) != null ) {
        System.out.println( obj[0] + " [" + obj[1] + "]" );
      }

    } finally {
      rs.close();
      rs.closeConnection();
    }

  }
View Full Code Here

    component.execute();

    // Preprocessor test code will add condition narrowing
    // resultset to 6 rows, all customers starting with 'Au'

    IPentahoResultSet rs = component.getResultSet();
    try {
      Assert.assertNotNull( rs );
      Assert.assertEquals( 6, rs.getRowCount() );
      Object[] obj;
      while ( ( obj = rs.next() ) != null ) {
        System.out.println( obj[0] );
      }

    } finally {
      rs.close();
      rs.closeConnection();
    }
  }
View Full Code Here

TOP

Related Classes of org.pentaho.commons.connection.IPentahoResultSet

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.