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;
019import java.util.Optional;
020
021import org.apache.solr.client.solrj.SolrClient;
022import org.apache.solr.client.solrj.SolrServerException;
023import org.apache.solr.client.solrj.response.UpdateResponse;
024import org.slf4j.Logger;
025
026/**
027 * Default update {@link SolrClient} which uses the Solr default Update Request Processor chain
028 */
029public class DefaultUpdateClient extends AbstractAmetysConcurrentUpdateClient
030{
031    /**
032     * Constructor
033     * @param solrServerUrl The Solr server URL
034     * @param solrSocketTimeout The Solr socket timeout (in millis)
035     * @param collectionName The name of the collection, on which operations will be allowed. Operations on other collections will be forbidden.
036     * @param queueSize The buffer size before the documents are sent to the server
037     * @param threadCount The number of background threads used to empty the queue
038     * @param logger internal logger
039     */
040    public DefaultUpdateClient(String solrServerUrl, Optional<Integer> solrSocketTimeout, String collectionName, int queueSize, int threadCount, Logger logger)
041    {
042        super(solrServerUrl, solrSocketTimeout, collectionName, queueSize, threadCount, logger);
043    }
044    
045    @Override
046    public UpdateResponse commit() throws SolrServerException, IOException
047    {
048        throw new CommitNotAllowedException();
049    }
050    
051    @Override
052    public UpdateResponse commit(boolean waitFlush, boolean waitSearcher) throws SolrServerException, IOException
053    {
054        throw new CommitNotAllowedException();
055    }
056    
057    @Override
058    public UpdateResponse commit(boolean waitFlush, boolean waitSearcher, boolean softCommit) throws SolrServerException, IOException
059    {
060        throw new CommitNotAllowedException();
061    }
062    
063    @Override
064    public UpdateResponse commit(String collection) throws SolrServerException, IOException
065    {
066        throw new CommitNotAllowedException();
067    }
068    
069    @Override
070    public UpdateResponse commit(String collection, boolean waitFlush, boolean waitSearcher) throws SolrServerException, IOException
071    {
072        throw new CommitNotAllowedException();
073    }
074    
075    @Override
076    public UpdateResponse commit(String collection, boolean waitFlush, boolean waitSearcher, boolean softCommit) throws SolrServerException, IOException
077    {
078        throw new CommitNotAllowedException();
079    }
080    
081    static class CommitNotAllowedException extends RuntimeException
082    {
083        CommitNotAllowedException()
084        {
085            super("Commit is not allowed with the default update client.");
086        }
087    }
088}