Search in sources :

Example 6 with MarkLogicErrorCode

use of org.talend.components.marklogic.exceptions.MarkLogicErrorCode in project components by Talend.

the class MarkLogicRowProcessor method write.

@Override
public void write(Object indexedRecordDatum) throws IOException {
    if (indexedRecordDatum == null) {
        return;
    }
    cleanWrites();
    IndexedRecord indexedRecord = (IndexedRecord) indexedRecordDatum;
    Schema indexedRecordSchema = indexedRecord.getSchema();
    int docIdFieldIndex = indexedRecordSchema.getFields().indexOf(indexedRecordSchema.getField(inputProperties.docIdColumn.getStringValue()));
    if (docIdFieldIndex == -1) {
        throw new MarkLogicException(new MarkLogicErrorCode("Can't find docId column " + inputProperties.docIdColumn.getStringValue() + " in input row"));
    }
    String docId = (String) indexedRecord.get(docIdFieldIndex);
    GenericData.Record matchedDocument = docContentReader.readDocument(docId);
    totalCounter++;
    documents.add(matchedDocument);
}
Also used : MarkLogicException(org.talend.components.marklogic.exceptions.MarkLogicException) IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) MarkLogicErrorCode(org.talend.components.marklogic.exceptions.MarkLogicErrorCode) GenericData(org.apache.avro.generic.GenericData)

Example 7 with MarkLogicErrorCode

use of org.talend.components.marklogic.exceptions.MarkLogicErrorCode in project components by Talend.

the class MarkLogicCriteriaReader method getCurrent.

@Override
public IndexedRecord getCurrent() throws NoSuchElementException {
    ++documentCounter;
    MatchDocumentSummary currentSummary = currentPage[pageCounter];
    current = new GenericData.Record(settings.outputSchema);
    try {
        String docId = currentSummary.getUri();
        current = docContentReader.readDocument(docId);
        result.totalCountLong++;
        result.successCountLong++;
        pageCounter++;
        return current;
    } catch (Exception e) {
        throw new MarkLogicException(new MarkLogicErrorCode("Can't read document from MarkLogic database"), e);
    }
}
Also used : MarkLogicException(org.talend.components.marklogic.exceptions.MarkLogicException) MatchDocumentSummary(com.marklogic.client.query.MatchDocumentSummary) MarkLogicErrorCode(org.talend.components.marklogic.exceptions.MarkLogicErrorCode) GenericData(org.apache.avro.generic.GenericData) NoSuchElementException(java.util.NoSuchElementException) MarkLogicException(org.talend.components.marklogic.exceptions.MarkLogicException) IOException(java.io.IOException)

Aggregations

MarkLogicErrorCode (org.talend.components.marklogic.exceptions.MarkLogicErrorCode)7 MarkLogicException (org.talend.components.marklogic.exceptions.MarkLogicException)7 IOException (java.io.IOException)3 Schema (org.apache.avro.Schema)2 GenericData (org.apache.avro.generic.GenericData)2 DatabaseClient (com.marklogic.client.DatabaseClient)1 DatabaseClientFactory (com.marklogic.client.DatabaseClientFactory)1 SecurityContext (com.marklogic.client.DatabaseClientFactory.SecurityContext)1 StringHandle (com.marklogic.client.io.StringHandle)1 MatchDocumentSummary (com.marklogic.client.query.MatchDocumentSummary)1 InputStream (java.io.InputStream)1 NoSuchElementException (java.util.NoSuchElementException)1 IndexedRecord (org.apache.avro.generic.IndexedRecord)1 MarkLogicConnectionProperties (org.talend.components.marklogic.tmarklogicconnection.MarkLogicConnectionProperties)1