Package org.pentaho.commons.connection

Examples of org.pentaho.commons.connection.IPentahoConnection


    return reportSpec;
  }

  public IPentahoResultSet getResultSet( final ReportSpec reportSpec ) throws Exception {
    String jndiName = reportSpec.getReportSpecChoice().getJndiSource();
    IPentahoConnection connection = null;
    if ( reportSpec.getIsMDX() ) {
      // did this ever work??
      String connectStr = ""; //$NON-NLS-1$
      IDBDatasourceService datasourceService = PentahoSystem.getObjectFactory().get( IDBDatasourceService.class, null );
      String dsName = datasourceService.getDSBoundName( jndiName );
      if ( dsName != null ) {
        connectStr = "dataSource=" + dsName + "; Catalog=mondrian"; //$NON-NLS-1$ //$NON-NLS-2$
      } else {
        error( Messages.getInstance().getErrorString( "MDXBaseComponent.ERROR_0005_INVALID_CONNECTION" ) ); //$NON-NLS-1$
        return null;
      }
      Properties props = new Properties();
      props.setProperty( IPentahoConnection.CONNECTION, connectStr );
      props.setProperty( IPentahoConnection.PROVIDER, reportSpec.getMondrianCubeDefinitionPath() );

      connection =
          PentahoConnectionFactory.getConnection( IPentahoConnection.MDX_DATASOURCE, props, getSession(), this );
    } else {
      connection =
          PentahoConnectionFactory.getConnection( IPentahoConnection.SQL_DATASOURCE, jndiName, getSession(), this );
    }
    String query = ReportParameterUtility.setupParametersForActionSequence( reportSpec.getQuery() );
    query = setupQueryParameters( query );
    IPentahoResultSet res = connection.executeQuery( query );
    return res;
  }
View Full Code Here


          String connectionName = parameterProvider.getStringParameter( "connection", null ); //$NON-NLS-1$
          String query = parameterProvider.getStringParameter( "query", null ); //$NON-NLS-1$
          String dataAction = parameterProvider.getStringParameter( "data-process", null ); //$NON-NLS-1$

          IPentahoConnection connection = null;
          try {
            chartComponent.setParamName( innerParam );
            chartComponent.setParameterProvider( IParameterProvider.SCOPE_REQUEST, parameterProvider );
            if ( ( connectionName != null ) && ( query != null ) ) {
              // connection = new SQLConnection(connectionName, logger)
              // TODO support non-SQL data sources. Much easier now using the factory
              connection =
                  PentahoConnectionFactory.getConnection( IPentahoConnection.SQL_DATASOURCE, connectionName,
                      userSession, logger );

              try {
                query =
                    TemplateUtil.applyTemplate( query, TemplateUtil.parametersToProperties( parameterProvider ), null );
                IPentahoResultSet results = connection.executeQuery( query );
                chartComponent.setValues( results );
              } finally {
                boolean ignored = true;
              }

              chartComponent.setUrlTemplate( urlDrillTemplate );
              if ( outerParams != null ) {
                StringTokenizer tokenizer = new StringTokenizer( outerParams, ";" ); //$NON-NLS-1$
                while ( tokenizer.hasMoreTokens() ) {
                  chartComponent.addOuterParamName( tokenizer.nextToken() );
                }
              }
            } else if ( dataAction != null ) {
              chartComponent.setDataAction( dataAction );
            }
            // ***************** END QUESTIONABLE CODE ********************************************************

            content = chartComponent.getContent( "text/html" ); //$NON-NLS-1$

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

        } catch ( Throwable e ) {
          logger.error( Messages.getInstance().getErrorString( "Widget.ERROR_0001_COULD_NOT_CREATE_WIDGET" ), e ); //$NON-NLS-1$
View Full Code Here

      mdxProperties.load( new FileInputStream( "mdxConnection.properties" ) ); //$NON-NLS-1$
    } catch ( Exception e ) {
      e.printStackTrace();
    }

    IPentahoConnection connection =
        PentahoConnectionFactory.getConnection( IPentahoConnection.MDX_DATASOURCE, mdxProperties, session, this );
    // @TODO Need to know how to use this getConnection method. Where does this property name comes from

    try {
      IPentahoResultSet results = connection.executeQuery( "select * from DEPARTMENT_MANAGERS" ); //$NON-NLS-1$
      Object[][] columnHeaders = results.getMetaData().getColumnHeaders();
      for ( int row = 0; row < columnHeaders.length; row++ ) {
        for ( int col = 0; col < columnHeaders[0].length; col++ ) {
          outputStream.write( columnHeaders[row][col].toString().getBytes() );
          outputStream.write( ",".getBytes() ); //$NON-NLS-1$
        }
        outputStream.write( "\n".getBytes() ); //$NON-NLS-1$
      }
      Object[] row = results.next();
      while ( row != null ) {
        for ( int i = 0; i < row.length; i++ ) {
          outputStream.write( row[i].toString().getBytes() );
          outputStream.write( ",".getBytes() ); //$NON-NLS-1$
        }
        outputStream.write( "\n".getBytes() ); //$NON-NLS-1$
        row = results.next();
      }

    } catch ( Exception e ) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    connection.close();
    finishTest();
  }
View Full Code Here

    startTest();
    IPentahoSession session = new StandaloneSession( "Admin" );
    OutputStream outputStream = this.getOutputStream( "ConnectionTest.testConnectionWithPropertyName", ".csv" ); //$NON-NLS-1$ //$NON-NLS-2$
    File file =
        new File( PentahoSystem.getApplicationContext().getSolutionPath( "test/datasources/SampleData.mondrian.xml" ) ); //$NON-NLS-1$
    IPentahoConnection connection =
        PentahoConnectionFactory
            .getConnection(
              IPentahoConnection.MDX_DATASOURCE,
              "jdbc:hsqldb:hsql://localhost:9001/sampledata; Catalog=" + file.toURI().toString(), "mondrian", "sa", "",
              session, this ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$

    try {
      IPentahoResultSet results = connection.executeQuery( "select * from DEPARTMENT_MANAGERS" ); //$NON-NLS-1$
      Object[][] columnHeaders = results.getMetaData().getColumnHeaders();
      for ( int row = 0; row < columnHeaders.length; row++ ) {
        for ( int col = 0; col < columnHeaders[0].length; col++ ) {
          outputStream.write( columnHeaders[row][col].toString().getBytes() );
          outputStream.write( ",".getBytes() ); //$NON-NLS-1$
        }
        outputStream.write( "\n".getBytes() ); //$NON-NLS-1$
      }
      Object[] row = results.next();
      while ( row != null ) {
        for ( int i = 0; i < row.length; i++ ) {
          outputStream.write( row[i].toString().getBytes() );
          outputStream.write( ",".getBytes() ); //$NON-NLS-1$
        }
        outputStream.write( "\n".getBytes() ); //$NON-NLS-1$
        row = results.next();
      }

    } catch ( Exception e ) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    connection.close();
    finishTest();
  }
View Full Code Here

    startTest();
    IPentahoSession session = new StandaloneSession( "Admin" );
    OutputStream outputStream = this.getOutputStream( "ConnectionTest.testSQLConnection", ".csv" ); //$NON-NLS-1$ //$NON-NLS-2$
    File file =
        new File( PentahoSystem.getApplicationContext().getSolutionPath( "test/datasources/SampleData.mondrian.xml" ) ); //$NON-NLS-1$
    IPentahoConnection connection =
        PentahoConnectionFactory
            .getConnection(
              IPentahoConnection.MDX_DATASOURCE,
              "jdbc:hsqldb:hsql://localhost:9001/sampledata; Catalog=" + file.toURI().toString(), "mondrian", "sa", "",
              session, null ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    String query =
        "select {[Measures].[Actual], [Measures].[Budget]} on rows, {[Region].[All Regions]} ON columns from [Quadrant Analysis] WHERE ([Positions].[All Positions])"; //$NON-NLS-1$

    try {
      IPentahoResultSet results = connection.executeQuery( query );
      Object[][] columnHeaders = results.getMetaData().getColumnHeaders();
      for ( int row = columnHeaders.length - 1; row >= 0; row-- ) {
        for ( int col = 0; col < columnHeaders[row].length; col++ ) {
          outputStream.write( ( columnHeaders[row][col] + "\t" ).getBytes() ); //$NON-NLS-1$
        }
        outputStream.write( '\n' );
      }

      Object[][] rowHeaders = results.getMetaData().getRowHeaders();
      int rowIdx = 0;

      Object[] row = results.next();
      while ( row != null ) {
        for ( int colIdx = rowHeaders[rowIdx].length - 1; colIdx >= 0; colIdx-- ) {
          outputStream.write( ( rowHeaders[rowIdx][colIdx].toString() + "\t" ).getBytes() ); //$NON-NLS-1$
        }
        for ( int colIdx = 0; colIdx < row.length; colIdx++ ) {
          outputStream.write( ( row[colIdx] + "\t" ).getBytes() ); //$NON-NLS-1$
        }
        outputStream.write( '\n' );
        row = results.next();
        rowIdx++;
      }
      results.close();

    } catch ( Exception e ) {
      e.printStackTrace();
    }
    connection.close();
    finishTest();
  }
View Full Code Here

    OutputStream outputStream = this.getOutputStream( "ConnectionTest.testSQLConnection", ".csv" ); //$NON-NLS-1$ //$NON-NLS-2$
    File file =
        new File( PentahoSystem.getApplicationContext().getSolutionPath( "test/datasources/SampleDataSchema.zip" ) ); //$NON-NLS-1$
    String catalog = "zip:" + file.toURI().toString() + "!/SampleData.mondrian.xml"; //$NON-NLS-1$ //$NON-NLS-2$
    catalog = "solution:/test/datasources/SampleData.mondrian.xml;vfs=true"; //$NON-NLS-1$
    IPentahoConnection connection =
        PentahoConnectionFactory.getConnection( IPentahoConnection.MDX_DATASOURCE,
            "jdbc:hsqldb:hsql://localhost:9001/sampledata; Catalog=" + catalog, "mondrian", "sa", "", session, null ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    String query =
        "select {[Measures].[Actual], [Measures].[Budget]} on rows, {[Region].[All Regions]} ON columns from [Quadrant Analysis] WHERE ([Positions].[All Positions])"; //$NON-NLS-1$

    try {
      IPentahoResultSet results = connection.executeQuery( query );
      Object[][] columnHeaders = results.getMetaData().getColumnHeaders();
      for ( int row = columnHeaders.length - 1; row >= 0; row-- ) {
        for ( int col = 0; col < columnHeaders[row].length; col++ ) {
          outputStream.write( ( columnHeaders[row][col] + "\t" ).getBytes() ); //$NON-NLS-1$
        }
        outputStream.write( '\n' );
      }

      Object[][] rowHeaders = results.getMetaData().getRowHeaders();
      int rowIdx = 0;

      Object[] row = results.next();
      while ( row != null ) {
        for ( int colIdx = rowHeaders[rowIdx].length - 1; colIdx >= 0; colIdx-- ) {
          outputStream.write( ( rowHeaders[rowIdx][colIdx].toString() + "\t" ).getBytes() ); //$NON-NLS-1$
        }
        for ( int colIdx = 0; colIdx < row.length; colIdx++ ) {
          outputStream.write( ( row[colIdx] + "\t" ).getBytes() ); //$NON-NLS-1$
        }
        outputStream.write( '\n' );
        row = results.next();
        rowIdx++;
      }
      results.close();

    } catch ( Exception e ) {
      e.printStackTrace();
    }
    connection.close();
    finishTest();
  }
View Full Code Here

  public void testXQueryConnection() {
    startTest();
    IPentahoSession session = new StandaloneSession( "Admin" );
    OutputStream outputStream = this.getOutputStream( "ConnectionTest.testSQLConnection", ".csv" ); //$NON-NLS-1$ //$NON-NLS-2$
    try {
      IPentahoConnection connection =
          PentahoConnectionFactory.getConnection( IPentahoConnection.XML_DATASOURCE, session, this );
      String query =
          "doc(\"" + PentahoSystem.getApplicationContext().getSolutionPath( "samples/datasources/books.xml" ) + "\")/bookstore/book"; //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
      query = query.replace( '\\', '/' );
      IPentahoResultSet results = connection.executeQuery( query );
      assertNotNull( results );
      Object[][] columnHeaders = results.getMetaData().getColumnHeaders();
      for ( int row = 0; row < columnHeaders.length; row++ ) {
        for ( int col = 0; col < columnHeaders[0].length; col++ ) {
          outputStream.write( columnHeaders[row][col].toString().getBytes() );
View Full Code Here

    documentPath = documentPath.replaceAll( "\\\\", "/" ); //$NON-NLS-1$ //$NON-NLS-2$
    return documentPath;
  }

  protected IPentahoConnection getConnection() {
    IPentahoConnection conn = null;
    try {
      conn = PentahoConnectionFactory.getConnection( IPentahoConnection.XML_DATASOURCE, getSession(), this );
      if ( conn == null ) {
        error(
          Messages.getInstance().getErrorString( "XQueryBaseComponent.ERROR_0005_INVALID_CONNECTION" ) ); //$NON-NLS-1$
        return null;
      }
      if ( this.getMaxRows() >= 0 ) {
        conn.setMaxRows( this.getMaxRows() );
      }
      return conn;
    } catch ( Exception e ) {
      error(
        Messages.getInstance().getErrorString( "XQueryBaseComponent.ERROR_0006_EXECUTE_FAILED", getActionName() ),
View Full Code Here

    ArrayList messages = new ArrayList();
    CategoryDatasetChartComponent barChart =
        new CategoryDatasetChartComponent( chartType, chartDefinitionPath, 600, 400, urlFactory, messages );

    String content = null;
    IPentahoConnection connection =
        PentahoConnectionFactory.getConnection( IPentahoConnection.SQL_DATASOURCE, "SampleData", userSession, this ); //$NON-NLS-1$
    try {
      String query = "select department, actual, budget, variance from QUADRANT_ACTUALS"; //$NON-NLS-1$

      IPentahoResultSet results = connection.executeQuery( query );
      try {

        barChart.setValues( results );
        barChart.validate( userSession, null );

        barChart.setParameterProvider( IParameterProvider.SCOPE_REQUEST, requestParameters );
        barChart.setParameterProvider( IParameterProvider.SCOPE_SESSION, sessionParameters );

        content = barChart.getContent( "text/html" ); //$NON-NLS-1$
      } finally {
        results.close();
      }
    } finally {
      connection.close();
    }
    return content;
  }
View Full Code Here

TOP

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

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.