1
package org.apache.solr.client.solrj.request;
3
* Licensed to the Apache Software Foundation (ASF) under one or more
4
* contributor license agreements. See the NOTICE file distributed with
5
* this work for additional information regarding copyright ownership.
6
* The ASF licenses this file to You under the Apache License, Version 2.0
7
* (the "License"); you may not use this file except in compliance with
8
* the License. You may obtain a copy of the License at
10
* http://www.apache.org/licenses/LICENSE-2.0
12
* Unless required by applicable law or agreed to in writing, software
13
* distributed under the License is distributed on an "AS IS" BASIS,
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
* See the License for the specific language governing permissions and
16
* limitations under the License.
19
import org.apache.solr.client.solrj.SolrRequest;
20
import org.apache.solr.client.solrj.SolrServer;
21
import org.apache.solr.client.solrj.SolrServerException;
22
import org.apache.solr.client.solrj.response.UpdateResponse;
23
import org.apache.solr.common.params.ModifiableSolrParams;
24
import org.apache.solr.common.params.UpdateParams;
26
import java.io.IOException;
33
public abstract class AbstractUpdateRequest extends SolrRequest {
34
protected ModifiableSolrParams params;
35
protected int commitWithin = -1;
42
public AbstractUpdateRequest(METHOD m, String path) {
46
/** Sets appropriate parameters for the given ACTION */
47
public AbstractUpdateRequest setAction(ACTION action, boolean waitFlush, boolean waitSearcher ) {
48
return setAction(action, waitFlush, waitSearcher, 1);
51
public AbstractUpdateRequest setAction(ACTION action, boolean waitFlush, boolean waitSearcher, int maxSegments ) {
53
params = new ModifiableSolrParams();
55
if( action == ACTION.OPTIMIZE ) {
56
params.set( UpdateParams.OPTIMIZE, "true" );
57
params.set(UpdateParams.MAX_OPTIMIZE_SEGMENTS, maxSegments);
59
else if( action == ACTION.COMMIT ) {
60
params.set( UpdateParams.COMMIT, "true" );
62
params.set( UpdateParams.WAIT_FLUSH, String.valueOf(waitFlush));
63
params.set( UpdateParams.WAIT_SEARCHER, String.valueOf(waitSearcher));
67
public AbstractUpdateRequest setAction(ACTION action, boolean waitFlush, boolean waitSearcher, int maxSegments , boolean expungeDeletes) {
68
setAction(action, waitFlush, waitSearcher,maxSegments) ;
69
params.set(UpdateParams.EXPUNGE_DELETES, String.valueOf(expungeDeletes));
76
public AbstractUpdateRequest rollback() {
78
params = new ModifiableSolrParams();
80
params.set( UpdateParams.ROLLBACK, "true" );
84
public void setParam(String param, String value) {
86
params = new ModifiableSolrParams();
87
params.set(param, value);
90
/** Sets the parameters for this update request, overwriting any previous */
91
public void setParams(ModifiableSolrParams params) {
96
public ModifiableSolrParams getParams() {
101
public UpdateResponse process( SolrServer server ) throws SolrServerException, IOException
103
long startTime = System.currentTimeMillis();
104
UpdateResponse res = new UpdateResponse();
105
res.setResponse( server.request( this ) );
106
res.setElapsedTime( System.currentTimeMillis()-startTime );
110
public boolean isWaitFlush() {
111
return params != null && params.getBool(UpdateParams.WAIT_FLUSH, false);
114
public boolean isWaitSearcher() {
115
return params != null && params.getBool(UpdateParams.WAIT_SEARCHER, false);
118
public ACTION getAction() {
119
if (params==null) return null;
120
if (params.getBool(UpdateParams.COMMIT, false)) return ACTION.COMMIT;
121
if (params.getBool(UpdateParams.OPTIMIZE, false)) return ACTION.OPTIMIZE;
125
public void setWaitFlush(boolean waitFlush) {
126
setParam( UpdateParams.WAIT_FLUSH, waitFlush+"" );
129
public void setWaitSearcher(boolean waitSearcher) {
130
setParam( UpdateParams.WAIT_SEARCHER, waitSearcher+"" );
133
public int getCommitWithin() {
137
public void setCommitWithin(int commitWithin) {
138
this.commitWithin = commitWithin;