Search in sources :

Example 6 with TransAdapter

use of org.pentaho.di.trans.TransAdapter in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceExecutor method executeQuery.

public DataServiceExecutor executeQuery(final DataOutputStream dos) throws IOException {
    writeMetadata(dos, getServiceName(), calculateTransname(getSql(), true), getServiceTrans().getContainerObjectId(), calculateTransname(getSql(), false), getGenTrans().getContainerObjectId());
    final AtomicBoolean rowMetaWritten = new AtomicBoolean(false);
    // When done, check if no row metadata was written.  The client is still going to expect it...
    // Since we know it, we'll pass it.
    // 
    getGenTrans().addTransListener(new TransAdapter() {

        @Override
        public void transFinished(Trans trans) throws KettleException {
            if (rowMetaWritten.compareAndSet(false, true)) {
                RowMetaInterface stepFields = trans.getTransMeta().getStepFields(getResultStepName());
                stepFields.writeMeta(dos);
            }
        }
    });
    // Now execute the query transformation(s) and pass the data to the output stream...
    return executeQuery(new RowAdapter() {

        @Override
        public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
            // 
            try {
                if (rowMetaWritten.compareAndSet(false, true)) {
                    rowMeta.writeMeta(dos);
                }
                rowMeta.writeData(dos, row);
            } catch (Exception e) {
                if (!getServiceTrans().isStopped()) {
                    throw new KettleStepException(e);
                }
            }
        }
    });
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowAdapter(org.pentaho.di.trans.step.RowAdapter) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Trans(org.pentaho.di.trans.Trans) TransAdapter(org.pentaho.di.trans.TransAdapter) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) KettleStepException(org.pentaho.di.core.exception.KettleStepException)

Aggregations

KettleException (org.pentaho.di.core.exception.KettleException)6 Trans (org.pentaho.di.trans.Trans)6 TransAdapter (org.pentaho.di.trans.TransAdapter)6 TransMeta (org.pentaho.di.trans.TransMeta)5 SimpleLoggingObject (org.pentaho.di.core.logging.SimpleLoggingObject)4 Repository (org.pentaho.di.repository.Repository)4 TransExecutionConfiguration (org.pentaho.di.trans.TransExecutionConfiguration)4 IOException (java.io.IOException)3 TransConfiguration (org.pentaho.di.trans.TransConfiguration)3 PrintWriter (java.io.PrintWriter)2 ServletException (javax.servlet.ServletException)2 KettleStepException (org.pentaho.di.core.exception.KettleStepException)2 LogChannelFileWriter (org.pentaho.di.core.logging.LogChannelFileWriter)2 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)2 RowAdapter (org.pentaho.di.trans.step.RowAdapter)2 BufferedReader (java.io.BufferedReader)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1