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);
}
}
}
});
}
Aggregations