Package org.pentaho.actionsequence.dom.actions

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


  protected boolean validateAction() {
    boolean result = false;
    IActionDefinition actionDefinition = getActionDefinition();

    if ( actionDefinition instanceof XQueryAction ) {
      XQueryAction xQueryAction = (XQueryAction) actionDefinition;
      if ( ( xQueryAction.getSourceXml() == ActionInputConstant.NULL_INPUT )
        && ( xQueryAction.getXmlDocument() == null ) ) {
        error( Messages.getInstance()
          .getString( "XQueryBaseComponent.ERROR_0008_SOURCE_NOT_DEFINED", getActionName() ) ); //$NON-NLS-1$
      } else if ( xQueryAction.getQuery() == ActionInputConstant.NULL_INPUT ) {
        error( Messages.getInstance().getErrorString(
          "XQueryBaseComponent.ERROR_0001_QUERY_NOT_SPECIFIED", getActionName() ) ); //$NON-NLS-1$
      } else if ( ( xQueryAction.getOutputPreparedStatement() == null ) && ( xQueryAction.getOutputResultSet()
        == null ) ) {
        error( Messages.getInstance().getErrorString(
          "XQueryBaseComponent.ERROR_0003_OUTPUT_NOT_SPECIFIED", getActionName() ) ); //$NON-NLS-1$
      } else {
        result = true;
View Full Code Here


    boolean result = false;
    IActionDefinition actionDefinition = getActionDefinition();
    // int maxRows = -1;
    // int queryTimeout = -1;
    if ( actionDefinition instanceof XQueryAction ) {
      XQueryAction xQueryAction = (XQueryAction) actionDefinition;

      // Not implemented yet
      // IActionInput queryTimeoutInput = xQueryAction.getQueryTimeout();

      IActionInput maxRowsInput = xQueryAction.getMaxRows();
      if ( maxRowsInput != ActionInputConstant.NULL_INPUT ) {
        this.setMaxRows( maxRowsInput.getIntValue() );
      }

      IPreparedComponent sharedConnection = (IPreparedComponent) xQueryAction.getSharedConnection().getValue();
      if ( sharedConnection != null ) {
        connectionOwner = false;
        connection = sharedConnection.shareConnection();
      } else {
        connection = getConnection();
      }
      if ( connection == null ) {
        error( Messages.getInstance().getErrorString(
          "IPreparedComponent.ERROR_0002_CONNECTION_NOT_AVAILABLE", getActionName() ) ); //$NON-NLS-1$
      } else if ( connection.getDatasourceType() != IPentahoConnection.XML_DATASOURCE ) {
        error( Messages.getInstance().getErrorString(
          "IPreparedComponent.ERROR_0001_INVALID_CONNECTION_TYPE", getActionName() ) ); //$NON-NLS-1$
      } else {
        result = runQuery( connection, xQueryAction.getQuery().getStringValue() );
      }
    } else if ( actionDefinition instanceof XQueryConnectionAction ) {
      XQueryConnectionAction xQueryConnectionAction = (XQueryConnectionAction) getActionDefinition();
      connection = getConnection();
      if ( connection == null ) {
View Full Code Here

    }
    return result;
  }

  protected boolean runQuery( final IPentahoConnection localConnection, String rawQuery ) {
    XQueryAction xQueryAction = (XQueryAction) getActionDefinition();
    try {
      if ( localConnection == null ) {
        return false;
      }
      if ( ComponentBase.debug ) {
        debug( Messages.getInstance().getString( "XQueryBaseComponent.DEBUG_RUNNING_QUERY", rawQuery ) ); //$NON-NLS-1$
      }
      String documentPath = null;
      int resourceType = -1;
      String srcXml = xQueryAction.getSourceXml().getStringValue();
      org.pentaho.actionsequence.dom.IActionResource xmlResource = xQueryAction.getXmlDocument();
      InputStream inputStream = null;
      URL url = null;
      if ( srcXml != null ) {
        inputStream = new FileInputStream( new File( createTempXMLFile( srcXml ) ) );
      } else if ( xmlResource != null ) {
        // we have a local document to use as the data source
        IActionSequenceResource resource = getResource( xmlResource.getName() );
        resourceType = resource.getSourceType();
        if ( ( resourceType == IActionSequenceResource.SOLUTION_FILE_RESOURCE )
          || ( resourceType == IActionSequenceResource.FILE_RESOURCE ) ) {
          inputStream = resource.getInputStream( RepositoryFilePermission.READ );
        } else if ( resourceType == IActionSequenceResource.XML ) {
          inputStream = new FileInputStream( new File( createTempXMLFile( resource.getAddress() ) ) );
        } else {
          url = new URL( documentPath );
        }
      }

      // Retrieve the column types
      String[] columnTypes = null;
      if ( retrieveColumnTypes() ) {
        try {
          SAXReader reader = new SAXReader();
          Document document;
          if ( url != null ) {
            document = reader.read( url );
          } else {
            document = reader.read( inputStream );
          }
          Node commentNode = document.selectSingleNode( "/result-set/comment()" ); //$NON-NLS-1$
          if ( commentNode != null ) {
            String commentString = commentNode.getText();
            StringTokenizer st = new StringTokenizer( commentString, "," ); //$NON-NLS-1$
            List columnTypesList = new LinkedList();
            while ( st.hasMoreTokens() ) {
              String token = st.nextToken().trim();
              columnTypesList.add( token );
            }
            columnTypes = (String[]) columnTypesList.toArray( new String[ 0 ] );
          }
        } catch ( Exception e ) {
          getLogger().warn(
            Messages.getInstance().getString( "XQueryBaseComponent.ERROR_0009_ERROR_BUILDING_COLUMN_TYPES" ),
            e ); //$NON-NLS-1$
        }
      }

      if ( rawQuery != null ) {
        if ( rawQuery.indexOf( "{" + XQueryBaseComponent.XML_DOCUMENT_TAG + "}" ) >= 0 ) { //$NON-NLS-1$//$NON-NLS-2$
          rawQuery = TemplateUtil.applyTemplate( rawQuery, XQueryBaseComponent.XML_DOCUMENT_TAG, documentPath );
        } else {
          Calendar now = Calendar.getInstance();
          File temp = File.createTempFile( "tempXQuery" + now.getTimeInMillis(), ".xml" );
          temp.deleteOnExit();

          OutputStream out = new FileOutputStream( temp );
          IActionSequenceResource resource = getResource( xmlResource.getName() );
          inputStream = resource.getInputStream( RepositoryFilePermission.READ );
          byte[] buf = new byte[ 1024 ];
          int len;
          while ( ( len = inputStream.read( buf ) ) > 0 ) {
            out.write( buf, 0, len );
          }
          out.close();
          inputStream.close();
          documentPath = temp.getAbsolutePath();
          documentPath = FilenameUtils.separatorsToUnix( documentPath );

          rawQuery = "doc(\"" + documentPath + "\")" + rawQuery; //$NON-NLS-1$ //$NON-NLS-2$
        }
      }

      if ( xQueryAction.getOutputPreparedStatement() != null ) {
        return prepareFinalQuery( rawQuery, columnTypes );
      } else {
        return runFinalQuery( localConnection, rawQuery, columnTypes );
      }
    } catch ( Exception e ) {
View Full Code Here

    return true;
  }

  protected boolean runFinalQuery( final IPentahoConnection localConnection, final String rawQuery,
                                   final String[] columnTypes ) {
    XQueryAction xQueryAction = (XQueryAction) getActionDefinition();
    boolean success = false;
    String finalQuery = applyInputsToFormat( rawQuery );
    // execute the query, read the results and cache them
    try {
      IPentahoResultSet resultSet = ( (XQConnection) localConnection ).executeQuery( finalQuery, columnTypes );
      if ( resultSet != null ) {
        if ( !xQueryAction.getLive().getBooleanValue( true ) ) {
          resultSet = resultSet.memoryCopy();
        }
        try {
          IActionOutput resultSetOutput = xQueryAction.getOutputResultSet();
          if ( resultSetOutput != null ) {
            resultSetOutput.setValue( resultSet );
          }
          success = true;
        } finally {
View Full Code Here

TOP

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

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.