Search in sources :

Example 1 with UnitaryClause

use of org.apache.manifoldcf.core.interfaces.UnitaryClause in project manifoldcf by apache.

the class DocumentChunkManager method readChunk.

/**
 * Read a chunk of documents.
 */
public DocumentRecord[] readChunk(String host, String path, int maximumNumber) throws ManifoldCFException {
    ArrayList params = new ArrayList();
    String query = buildConjunctionClause(params, new ClauseDescription[] { new UnitaryClause(HOST_FIELD, host), new UnitaryClause(PATH_FIELD, path) });
    IResultSet set = performQuery("SELECT * FROM " + getTableName() + " WHERE " + query + " " + constructOffsetLimitClause(0, maximumNumber), params, null, null);
    DocumentRecord[] rval = new DocumentRecord[set.getRowCount()];
    for (int i = 0; i < set.getRowCount(); i++) {
        IResultRow row = set.getRow(i);
        rval[i] = new DocumentRecord(host, path, (String) row.getValue(UID_FIELD), (String) row.getValue(URI_FIELD), (String) row.getValue(ACTIVITY_FIELD), (Long) row.getValue(LENGTH_FIELD), (BinaryInput) row.getValue(SDF_DATA_FIELD));
    }
    return rval;
}
Also used : BinaryInput(org.apache.manifoldcf.core.interfaces.BinaryInput) IResultSet(org.apache.manifoldcf.core.interfaces.IResultSet) UnitaryClause(org.apache.manifoldcf.core.interfaces.UnitaryClause) ArrayList(java.util.ArrayList) IResultRow(org.apache.manifoldcf.core.interfaces.IResultRow)

Example 2 with UnitaryClause

use of org.apache.manifoldcf.core.interfaces.UnitaryClause in project manifoldcf by apache.

the class DocumentChunkManager method recordDocument.

/**
 * Record document information for later trasmission to Amazon.
 * @param uid documentuid
 * @param sdfData document SDF data.
 * @throws ManifoldCFException
 */
public void recordDocument(String uid, String host, String path, String uri, String activity, Long length, InputStream sdfData) throws ManifoldCFException, IOException {
    TempFileInput tfi = null;
    try {
        // This downloads all the data from upstream!
        try {
            tfi = new TempFileInput(sdfData);
        } catch (ManifoldCFException e) {
            if (e.getErrorCode() == ManifoldCFException.INTERRUPTED)
                throw e;
            throw new IOException("Fetch failed: " + e.getMessage());
        }
        while (true) {
            long sleepAmt = 0L;
            try {
                beginTransaction();
                try {
                    ArrayList params = new ArrayList();
                    String query = buildConjunctionClause(params, new ClauseDescription[] { new UnitaryClause(HOST_FIELD, host), new UnitaryClause(PATH_FIELD, path), new UnitaryClause(UID_FIELD, uid) });
                    IResultSet set = performQuery("SELECT " + UID_FIELD + " FROM " + getTableName() + " WHERE " + query + " FOR UPDATE", params, null, null);
                    Map<String, Object> parameterMap = new HashMap<String, Object>();
                    parameterMap.put(SDF_DATA_FIELD, tfi);
                    parameterMap.put(URI_FIELD, uri);
                    parameterMap.put(ACTIVITY_FIELD, activity);
                    if (length != null)
                        parameterMap.put(LENGTH_FIELD, length);
                    // if record exists on table, update record.
                    if (set.getRowCount() > 0) {
                        performUpdate(parameterMap, " WHERE " + query, params, null);
                    } else {
                        parameterMap.put(UID_FIELD, uid);
                        parameterMap.put(HOST_FIELD, host);
                        parameterMap.put(PATH_FIELD, path);
                        performInsert(parameterMap, null);
                    }
                    break;
                } catch (ManifoldCFException e) {
                    signalRollback();
                    throw e;
                } catch (RuntimeException e) {
                    signalRollback();
                    throw e;
                } catch (Error e) {
                    signalRollback();
                    throw e;
                } finally {
                    endTransaction();
                }
            } catch (ManifoldCFException e) {
                // Look for deadlock and retry if so
                if (e.getErrorCode() == e.DATABASE_TRANSACTION_ABORT) {
                    sleepAmt = getSleepAmt();
                    continue;
                }
                throw e;
            }
        }
    } finally {
        if (tfi != null)
            tfi.discard();
    }
}
Also used : TempFileInput(org.apache.manifoldcf.core.interfaces.TempFileInput) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IResultSet(org.apache.manifoldcf.core.interfaces.IResultSet) UnitaryClause(org.apache.manifoldcf.core.interfaces.UnitaryClause) ManifoldCFException(org.apache.manifoldcf.core.interfaces.ManifoldCFException)

Example 3 with UnitaryClause

use of org.apache.manifoldcf.core.interfaces.UnitaryClause in project manifoldcf by apache.

the class DocumentChunkManager method deleteChunk.

/**
 * Delete the chunk of documents (presumably because we processed them successfully)
 */
public void deleteChunk(DocumentRecord[] records) throws ManifoldCFException {
    // Do the whole thing in a transaction -- if we mess up, we'll have to try everything again
    while (true) {
        long sleepAmt = 0L;
        try {
            beginTransaction();
            try {
                // Theoretically we could aggregate the records, but for now delete one at a time.
                for (DocumentRecord dr : records) {
                    String host = dr.getHost();
                    String path = dr.getPath();
                    String uid = dr.getUid();
                    ArrayList params = new ArrayList();
                    String query = buildConjunctionClause(params, new ClauseDescription[] { new UnitaryClause(HOST_FIELD, host), new UnitaryClause(PATH_FIELD, path), new UnitaryClause(UID_FIELD, uid) });
                    performDelete("WHERE " + query, params, null);
                }
                break;
            } catch (ManifoldCFException e) {
                signalRollback();
                throw e;
            } catch (RuntimeException e) {
                signalRollback();
                throw e;
            } catch (Error e) {
                signalRollback();
                throw e;
            } finally {
                endTransaction();
            }
        } catch (ManifoldCFException e) {
            // Look for deadlock and retry if so
            if (e.getErrorCode() == e.DATABASE_TRANSACTION_ABORT) {
                sleepAmt = getSleepAmt();
                continue;
            }
            throw e;
        }
    }
}
Also used : UnitaryClause(org.apache.manifoldcf.core.interfaces.UnitaryClause) ManifoldCFException(org.apache.manifoldcf.core.interfaces.ManifoldCFException) ArrayList(java.util.ArrayList)

Example 4 with UnitaryClause

use of org.apache.manifoldcf.core.interfaces.UnitaryClause in project manifoldcf by apache.

the class DocumentChunkManager method equalOrMoreThan.

/**
 * Determine if there are N documents or more.
 */
public boolean equalOrMoreThan(String host, String path, int maximumNumber) throws ManifoldCFException {
    ArrayList params = new ArrayList();
    String query = buildConjunctionClause(params, new ClauseDescription[] { new UnitaryClause(HOST_FIELD, host), new UnitaryClause(PATH_FIELD, path) });
    IResultSet set = performQuery("SELECT " + constructCountClause(UID_FIELD) + " AS countval FROM " + getTableName() + " WHERE " + query + " " + constructOffsetLimitClause(0, maximumNumber), params, null, null);
    long count;
    if (set.getRowCount() > 0) {
        IResultRow row = set.getRow(0);
        Long countVal = (Long) row.getValue("countval");
        count = countVal.longValue();
    } else
        count = 0L;
    return count >= maximumNumber;
}
Also used : IResultSet(org.apache.manifoldcf.core.interfaces.IResultSet) UnitaryClause(org.apache.manifoldcf.core.interfaces.UnitaryClause) ArrayList(java.util.ArrayList) IResultRow(org.apache.manifoldcf.core.interfaces.IResultRow)

Aggregations

ArrayList (java.util.ArrayList)4 UnitaryClause (org.apache.manifoldcf.core.interfaces.UnitaryClause)4 IResultSet (org.apache.manifoldcf.core.interfaces.IResultSet)3 IResultRow (org.apache.manifoldcf.core.interfaces.IResultRow)2 ManifoldCFException (org.apache.manifoldcf.core.interfaces.ManifoldCFException)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 BinaryInput (org.apache.manifoldcf.core.interfaces.BinaryInput)1 TempFileInput (org.apache.manifoldcf.core.interfaces.TempFileInput)1