Search in sources :

Example 1 with RollbackUpdateCommand

use of org.apache.solr.update.RollbackUpdateCommand in project lucene-solr by apache.

the class RequestHandlerUtils method handleRollback.

/**
   * @since Solr 1.4
   */
public static boolean handleRollback(SolrQueryRequest req, UpdateRequestProcessor processor, SolrParams params, boolean force) throws IOException {
    if (params == null) {
        params = new MapSolrParams(new HashMap<String, String>());
    }
    boolean rollback = params.getBool(UpdateParams.ROLLBACK, false);
    if (rollback || force) {
        RollbackUpdateCommand cmd = new RollbackUpdateCommand(req);
        processor.processRollback(cmd);
        return true;
    }
    return false;
}
Also used : MapSolrParams(org.apache.solr.common.params.MapSolrParams) RollbackUpdateCommand(org.apache.solr.update.RollbackUpdateCommand)

Example 2 with RollbackUpdateCommand

use of org.apache.solr.update.RollbackUpdateCommand in project lucene-solr by apache.

the class SolrWriter method rollback.

@Override
public void rollback() {
    try {
        RollbackUpdateCommand rollback = new RollbackUpdateCommand(req);
        processor.processRollback(rollback);
    } catch (Exception e) {
        log.error("Exception during rollback command.", e);
    }
}
Also used : RollbackUpdateCommand(org.apache.solr.update.RollbackUpdateCommand) SolrException(org.apache.solr.common.SolrException)

Example 3 with RollbackUpdateCommand

use of org.apache.solr.update.RollbackUpdateCommand in project lucene-solr by apache.

the class XMLLoader method processUpdate.

/**
   * @since solr 1.2
   */
void processUpdate(SolrQueryRequest req, UpdateRequestProcessor processor, XMLStreamReader parser) throws XMLStreamException, IOException, FactoryConfigurationError {
    AddUpdateCommand addCmd = null;
    SolrParams params = req.getParams();
    while (true) {
        int event = parser.next();
        switch(event) {
            case XMLStreamConstants.END_DOCUMENT:
                parser.close();
                return;
            case XMLStreamConstants.START_ELEMENT:
                String currTag = parser.getLocalName();
                if (currTag.equals(UpdateRequestHandler.ADD)) {
                    log.trace("SolrCore.update(add)");
                    addCmd = new AddUpdateCommand(req);
                    // First look for commitWithin parameter on the request, will be overwritten for individual <add>'s
                    addCmd.commitWithin = params.getInt(UpdateParams.COMMIT_WITHIN, -1);
                    addCmd.overwrite = params.getBool(UpdateParams.OVERWRITE, true);
                    for (int i = 0; i < parser.getAttributeCount(); i++) {
                        String attrName = parser.getAttributeLocalName(i);
                        String attrVal = parser.getAttributeValue(i);
                        if (UpdateRequestHandler.OVERWRITE.equals(attrName)) {
                            addCmd.overwrite = StrUtils.parseBoolean(attrVal);
                        } else if (UpdateRequestHandler.COMMIT_WITHIN.equals(attrName)) {
                            addCmd.commitWithin = Integer.parseInt(attrVal);
                        } else {
                            log.warn("XML element <add> has invalid XML attr: " + attrName);
                        }
                    }
                } else if ("doc".equals(currTag)) {
                    if (addCmd != null) {
                        log.trace("adding doc...");
                        addCmd.clear();
                        addCmd.solrDoc = readDoc(parser);
                        processor.processAdd(addCmd);
                    } else {
                        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unexpected <doc> tag without an <add> tag surrounding it.");
                    }
                } else if (UpdateRequestHandler.COMMIT.equals(currTag) || UpdateRequestHandler.OPTIMIZE.equals(currTag)) {
                    log.trace("parsing " + currTag);
                    CommitUpdateCommand cmd = new CommitUpdateCommand(req, UpdateRequestHandler.OPTIMIZE.equals(currTag));
                    ModifiableSolrParams mp = new ModifiableSolrParams();
                    for (int i = 0; i < parser.getAttributeCount(); i++) {
                        String attrName = parser.getAttributeLocalName(i);
                        String attrVal = parser.getAttributeValue(i);
                        mp.set(attrName, attrVal);
                    }
                    RequestHandlerUtils.validateCommitParams(mp);
                    // default to the normal request params for commit options
                    SolrParams p = SolrParams.wrapDefaults(mp, req.getParams());
                    RequestHandlerUtils.updateCommit(cmd, p);
                    processor.processCommit(cmd);
                } else // end commit
                if (UpdateRequestHandler.ROLLBACK.equals(currTag)) {
                    log.trace("parsing rollback");
                    RollbackUpdateCommand cmd = new RollbackUpdateCommand(req);
                    processor.processRollback(cmd);
                } else // end rollback
                if (UpdateRequestHandler.DELETE.equals(currTag)) {
                    log.trace("parsing delete");
                    processDelete(req, processor, parser);
                }
                // end delete
                break;
        }
    }
}
Also used : RollbackUpdateCommand(org.apache.solr.update.RollbackUpdateCommand) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) CommitUpdateCommand(org.apache.solr.update.CommitUpdateCommand) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) SolrException(org.apache.solr.common.SolrException) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Aggregations

RollbackUpdateCommand (org.apache.solr.update.RollbackUpdateCommand)3 SolrException (org.apache.solr.common.SolrException)2 MapSolrParams (org.apache.solr.common.params.MapSolrParams)1 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)1 SolrParams (org.apache.solr.common.params.SolrParams)1 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)1 CommitUpdateCommand (org.apache.solr.update.CommitUpdateCommand)1