SOLR-436: To make future changes easier, SolrServer changed from an interface to an abstract super class.

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@614633 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ryan McKinley 2008-01-23 19:31:31 +00:00
parent e71870c4f6
commit 17c461e26d
5 changed files with 83 additions and 133 deletions

View File

@ -36,6 +36,9 @@ Changes in runtime behavior
creating a new HttpClient on each request. If your existing code overrides
getHttpConnection(), you will now need to override createHttpClient()
(Sean Timm via ryan)
4. SOLR-436: To make future changes easier, SolrServer changed from an
interface to an abstract super class. (ryan)
Bug Fixes

View File

@ -20,6 +20,9 @@ package org.apache.solr.client.solrj;
import java.io.IOException;
import java.util.Collection;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.request.SolrPing;
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.response.SolrPingResponse;
import org.apache.solr.client.solrj.response.UpdateResponse;
@ -28,29 +31,83 @@ import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
/**
*
* @version $Id$
* @since solr 1.3
*/
public interface SolrServer
public abstract class SolrServer
{
// A general method to allow various methods
NamedList<Object> request( final SolrRequest request ) throws SolrServerException, IOException;
protected String defaultCore = null;
void setDefaultCore( String core );
String getDefaultCore();
public UpdateResponse add(Collection<SolrInputDocument> docs, boolean overwrite ) throws SolrServerException, IOException {
UpdateRequest req = new UpdateRequest();
req.add(docs);
req.setOverwrite(overwrite);
return req.process(this);
}
public UpdateResponse add(SolrInputDocument doc, boolean overwrite ) throws SolrServerException, IOException {
UpdateRequest req = new UpdateRequest();
req.add(doc);
req.setOverwrite(overwrite);
return req.process(this);
}
public UpdateResponse add(SolrInputDocument doc) throws SolrServerException, IOException {
return add(doc, true);
}
public UpdateResponse add(Collection<SolrInputDocument> docs) throws SolrServerException, IOException {
return add(docs, true);
}
/** waitFlush=true and waitSearcher=true to be inline with the defaults for plain HTTP access
* @throws IOException
*/
public UpdateResponse commit( ) throws SolrServerException, IOException {
return commit(true, true);
}
/** waitFlush=true and waitSearcher=true to be inline with the defaults for plain HTTP access
* @throws IOException
*/
public UpdateResponse optimize( ) throws SolrServerException, IOException {
return optimize(true, true);
}
// Standard methods
UpdateResponse add( SolrInputDocument doc ) throws SolrServerException, IOException;
UpdateResponse add( Collection<SolrInputDocument> docs ) throws SolrServerException, IOException;
UpdateResponse add( SolrInputDocument doc, boolean overwrite ) throws SolrServerException, IOException;
UpdateResponse add( Collection<SolrInputDocument> docs, boolean overwrite ) throws SolrServerException, IOException;
UpdateResponse deleteById( String id ) throws SolrServerException, IOException;
UpdateResponse deleteByQuery( String query ) throws SolrServerException, IOException;
UpdateResponse commit( boolean waitFlush, boolean waitSearcher ) throws SolrServerException, IOException;
UpdateResponse optimize( boolean waitFlush, boolean waitSearcher ) throws SolrServerException, IOException;
UpdateResponse commit( ) throws SolrServerException, IOException;
UpdateResponse optimize( ) throws SolrServerException, IOException;
QueryResponse query( SolrParams params ) throws SolrServerException, IOException;
SolrPingResponse ping() throws SolrServerException, IOException;
public UpdateResponse commit( boolean waitFlush, boolean waitSearcher ) throws SolrServerException, IOException {
return new UpdateRequest().setAction( UpdateRequest.ACTION.COMMIT, waitFlush, waitSearcher ).process( this );
}
public UpdateResponse optimize( boolean waitFlush, boolean waitSearcher ) throws SolrServerException, IOException {
return new UpdateRequest().setAction( UpdateRequest.ACTION.OPTIMIZE, waitFlush, waitSearcher ).process( this );
}
public UpdateResponse deleteById(String id) throws SolrServerException, IOException {
return new UpdateRequest().deleteById( id ).process( this );
}
public UpdateResponse deleteByQuery(String query) throws SolrServerException, IOException {
return new UpdateRequest().deleteByQuery( query ).process( this );
}
public SolrPingResponse ping() throws SolrServerException, IOException {
return new SolrPing().process( this );
}
public QueryResponse query(SolrParams params) throws SolrServerException {
return new QueryRequest( params ).process( this );
}
public String getDefaultCore() {
return defaultCore;
}
public void setDefaultCore(String defaultCore) {
this.defaultCore = defaultCore;
}
/**
* SolrServer implementations need to implement a how a request is actually processed
*/
public abstract NamedList<Object> request( final SolrRequest request ) throws SolrServerException, IOException;
}

View File

@ -23,8 +23,8 @@ import java.io.StringWriter;
import org.apache.solr.client.solrj.ResponseParser;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.BaseSolrServer;
import org.apache.solr.client.solrj.impl.XMLResponseParser;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CommonParams;
@ -49,7 +49,7 @@ import org.apache.solr.servlet.SolrRequestParsers;
* @version $Id$
* @since solr 1.3
*/
public class EmbeddedSolrServer extends BaseSolrServer
public class EmbeddedSolrServer extends SolrServer
{
protected ModifiableSolrParams _invariantParams;
protected ResponseParser _processor;

View File

@ -1,111 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.client.solrj.impl;
import java.io.IOException;
import java.util.Collection;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.request.SolrPing;
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.response.SolrPingResponse;
import org.apache.solr.client.solrj.response.UpdateResponse;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.SolrParams;
/**
* Base class that converts the server request into the more verbose general request framework.
*
* @version $Id$
* @since solr 1.3
*/
public abstract class BaseSolrServer implements SolrServer
{
protected String defaultCore = null;
public UpdateResponse add(Collection<SolrInputDocument> docs, boolean overwrite ) throws SolrServerException, IOException {
UpdateRequest req = new UpdateRequest();
req.add(docs);
req.setOverwrite(overwrite);
return req.process(this);
}
public UpdateResponse add(SolrInputDocument doc, boolean overwrite ) throws SolrServerException, IOException {
UpdateRequest req = new UpdateRequest();
req.add(doc);
req.setOverwrite(overwrite);
return req.process(this);
}
public UpdateResponse add(SolrInputDocument doc) throws SolrServerException, IOException {
return add(doc, true);
}
public UpdateResponse add(Collection<SolrInputDocument> docs) throws SolrServerException, IOException {
return add(docs, true);
}
/** waitFlush=true and waitSearcher=true to be inline with the defaults for plain HTTP access
* @throws IOException
*/
public UpdateResponse commit( ) throws SolrServerException, IOException {
return commit(true, true);
}
/** waitFlush=true and waitSearcher=true to be inline with the defaults for plain HTTP access
* @throws IOException
*/
public UpdateResponse optimize( ) throws SolrServerException, IOException {
return optimize(true, true);
}
public UpdateResponse commit( boolean waitFlush, boolean waitSearcher ) throws SolrServerException, IOException {
return new UpdateRequest().setAction( UpdateRequest.ACTION.COMMIT, waitFlush, waitSearcher ).process( this );
}
public UpdateResponse optimize( boolean waitFlush, boolean waitSearcher ) throws SolrServerException, IOException {
return new UpdateRequest().setAction( UpdateRequest.ACTION.OPTIMIZE, waitFlush, waitSearcher ).process( this );
}
public UpdateResponse deleteById(String id) throws SolrServerException, IOException {
return new UpdateRequest().deleteById( id ).process( this );
}
public UpdateResponse deleteByQuery(String query) throws SolrServerException, IOException {
return new UpdateRequest().deleteByQuery( query ).process( this );
}
public SolrPingResponse ping() throws SolrServerException, IOException {
return new SolrPing().process( this );
}
public QueryResponse query(SolrParams params) throws SolrServerException {
return new QueryRequest( params ).process( this );
}
public String getDefaultCore() {
return defaultCore;
}
public void setDefaultCore(String defaultCore) {
this.defaultCore = defaultCore;
}
}

View File

@ -46,6 +46,7 @@ import org.apache.commons.httpclient.methods.multipart.PartBase;
import org.apache.commons.io.IOUtils;
import org.apache.solr.client.solrj.ResponseParser;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.util.ClientUtils;
import org.apache.solr.common.SolrException;
@ -61,7 +62,7 @@ import org.apache.solr.common.util.NamedList;
* @version $Id$
* @since solr 1.3
*/
public class CommonsHttpSolrServer extends BaseSolrServer
public class CommonsHttpSolrServer extends SolrServer
{
public static final String AGENT = "Solr["+CommonsHttpSolrServer.class.getName()+"] 1.0";