001/*
002 *  Copyright 2018 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.cms.search.solr;
017
018import java.io.IOException;
019
020import org.apache.solr.client.solrj.SolrClient;
021import org.apache.solr.client.solrj.SolrServerException;
022import org.apache.solr.client.solrj.response.UpdateResponse;
023import org.slf4j.Logger;
024
025/**
026 * Default update {@link SolrClient} which uses the Solr default Update Request Processor chain
027 */
028public class DefaultUpdateClient extends AbstractAmetysConcurrentUpdateClient
029{
030    /**
031     * Constructor
032     * @param solrServerUrl The Solr server URL
033     * @param collectionName The name of the collection, on which operations will be allowed. Operations on other collections will be forbidden.
034     * @param queueSize The buffer size before the documents are sent to the server
035     * @param threadCount The number of background threads used to empty the queue
036     * @param logger internal logger
037     */
038    public DefaultUpdateClient(String solrServerUrl, String collectionName, int queueSize, int threadCount, Logger logger)
039    {
040        super(solrServerUrl, collectionName, queueSize, threadCount, logger);
041    }
042    
043    @Override
044    public UpdateResponse commit() throws SolrServerException, IOException
045    {
046        throw new CommitNotAllowedException();
047    }
048    
049    @Override
050    public UpdateResponse commit(boolean waitFlush, boolean waitSearcher) throws SolrServerException, IOException
051    {
052        throw new CommitNotAllowedException();
053    }
054    
055    @Override
056    public UpdateResponse commit(boolean waitFlush, boolean waitSearcher, boolean softCommit) throws SolrServerException, IOException
057    {
058        throw new CommitNotAllowedException();
059    }
060    
061    @Override
062    public UpdateResponse commit(String collection) throws SolrServerException, IOException
063    {
064        throw new CommitNotAllowedException();
065    }
066    
067    @Override
068    public UpdateResponse commit(String collection, boolean waitFlush, boolean waitSearcher) throws SolrServerException, IOException
069    {
070        throw new CommitNotAllowedException();
071    }
072    
073    @Override
074    public UpdateResponse commit(String collection, boolean waitFlush, boolean waitSearcher, boolean softCommit) throws SolrServerException, IOException
075    {
076        throw new CommitNotAllowedException();
077    }
078    
079    static class CommitNotAllowedException extends RuntimeException
080    {
081        CommitNotAllowedException()
082        {
083            super("Commit is not allowed with the default update client.");
084        }
085    }
086}