Examples of XQueryAction


Examples of org.exist.xmldb.concurrent.action.XQueryAction

          super.setUp();         
          Collection c1 = DBUtils.addCollection(getTestCollection(), "C1-C2");
          assertNotNull(c1);
          addAction(new MultiResourcesAction("samples/mods", URI + "/C1/C1-C2"), 200, 0, 300);
          addAction(new MultiResourcesAction("samples/mods", URI + "/C1/C1-C2"), 200, 0, 300);
          addAction(new XQueryAction(URI + "/C1/C1-C2", "R1.xml", QUERY0), 200, 200, 500);
          addAction(new XQueryAction(URI + "/C1/C1-C2", "R1.xml", QUERY1), 200, 300, 500);
      //addAction(new XQueryAction(URI + "/C1/C1-C2", "R1.xml", QUERY0), 200, 400, 500);
      //addAction(new XQueryAction(URI + "/C1/C1-C2", "R1.xml", QUERY1), 200, 500, 500);
      } catch (Exception e) {           
            fail(e.getMessage());
        }           
View Full Code Here

Examples of org.exist.xmldb.concurrent.action.XQueryAction

   
    protected void setUp() {
        try {
            super.setUp();
           
            addAction(new XQueryAction(URI + "/C1", "test.xml", QUERY), 200, 0, 200);
            addAction(new XQueryAction(URI + "/C2", "test.xml", QUERY), 200, 0, 200);
            addAction(new CreateCollectionAction(URI + "/C1", "testappend.xml"), 200, 0, 0);
        } catch (Exception e) {
            fail(e.getMessage());
        }
    }
View Full Code Here

Examples of org.exist.xmldb.concurrent.action.XQueryAction

      try {
        super.setUp();       
          Collection c1 = DBUtils.addCollection(getTestCollection(), "C1-C2");
          assertNotNull(c1);
          addAction(new MultiResourcesAction(FILES_DIR, URI + "/C1/C1-C2"), 1, 0, 0);
          addAction(new XQueryAction(URI + "/C1/C1-C2", "R1.xml", QUERY0), 1500, 200, 250);
      } catch (Exception e) {           
            fail(e.getMessage());
        }           
    }
View Full Code Here

Examples of org.exist.xmldb.concurrent.action.XQueryAction

     
      String query0 = "/ROOT-ELEMENT/ELEMENT/ELEMENT-1/ELEMENT-2[@attribute-3]";
      String query1 = "distinct-values(//ELEMENT/@attribute-2)";
      String query2 = "/ROOT-ELEMENT//ELEMENT-1[@attribute-3]";
     
      action0 = new XQueryAction(URI + "/C1", "R1.xml", query0);
      action1 = new XQueryAction(URI + "/C1", "R1.xml", query1);
      action2 = new XQueryAction(URI + "/C1", "R1.xml", query2);
  //    action3 = new XQueryAction(URI + "/C1", "R1.xml", query0);
  //    action4 = new XQueryAction(URI + "/C1", "R1.xml", query0);
  //    action5 = new XQueryAction(URI + "/C1", "R1.xml", query0);
     
      addAction(action0, 50, 500, 0);
View Full Code Here

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

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

    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

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

    }
    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

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

    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
Copyright © 2018 www.massapi.com. 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.