/** * Adds the beans supplied by the given iterator. * * @param beanIterator * the iterator which returns Beans * * @return an {@link org.apache.solr.client.solrj.response.UpdateResponse} from the server * * @throws IOException if there is a communication error with the server * @throws SolrServerException if there is an error on the server */ public UpdateResponse addBeans(final Iterator<?> beanIterator) throws SolrServerException, IOException { return addBeans(null, beanIterator); }
/** * Adds the beans supplied by the given iterator. * * @param beanIterator * the iterator which returns Beans * * @return an {@link org.apache.solr.client.solrj.response.UpdateResponse} from the server * * @throws IOException if there is a communication error with the server * @throws SolrServerException if there is an error on the server */ public UpdateResponse addBeans(final Iterator<?> beanIterator) throws SolrServerException, IOException { return addBeans(null, beanIterator); }
/** * Adds a collection of beans * * The beans are converted to {@link SolrInputDocument}s by the client's * {@link org.apache.solr.client.solrj.beans.DocumentObjectBinder} * * @param beans the collection of beans * * @return an {@link org.apache.solr.client.solrj.response.UpdateResponse} from the server * * @throws IOException if there is a communication error with the server * @throws SolrServerException if there is an error on the server */ public UpdateResponse addBeans(Collection<?> beans) throws SolrServerException, IOException { return addBeans(null, beans, -1); }
/** * Adds a collection of beans * * The beans are converted to {@link SolrInputDocument}s by the client's * {@link org.apache.solr.client.solrj.beans.DocumentObjectBinder} * * @param collection the Solr collection to add documents to * @param beans the collection of beans * * @return an {@link org.apache.solr.client.solrj.response.UpdateResponse} from the server * * @throws IOException if there is a communication error with the server * @throws SolrServerException if there is an error on the server */ public UpdateResponse addBeans(String collection, Collection<?> beans) throws SolrServerException, IOException { return addBeans(collection, beans, -1); }
/** * Adds a collection of beans * * The beans are converted to {@link SolrInputDocument}s by the client's * {@link org.apache.solr.client.solrj.beans.DocumentObjectBinder} * * @param beans the collection of beans * * @return an {@link org.apache.solr.client.solrj.response.UpdateResponse} from the server * * @throws IOException if there is a communication error with the server * @throws SolrServerException if there is an error on the server */ public UpdateResponse addBeans(Collection<?> beans) throws SolrServerException, IOException { return addBeans(null, beans, -1); }
/** * Adds a collection of beans * * The beans are converted to {@link SolrInputDocument}s by the client's * {@link org.apache.solr.client.solrj.beans.DocumentObjectBinder} * * @param collection the Solr collection to add documents to * @param beans the collection of beans * * @return an {@link org.apache.solr.client.solrj.response.UpdateResponse} from the server * * @throws IOException if there is a communication error with the server * @throws SolrServerException if there is an error on the server */ public UpdateResponse addBeans(String collection, Collection<?> beans) throws SolrServerException, IOException { return addBeans(collection, beans, -1); }
/** * Adds a collection of beans specifying max time before they become committed * * The beans are converted to {@link SolrInputDocument}s by the client's * {@link org.apache.solr.client.solrj.beans.DocumentObjectBinder} * * @param beans the collection of beans * @param commitWithinMs max time (in ms) before a commit will happen * * @return an {@link org.apache.solr.client.solrj.response.UpdateResponse} from the server * * @throws IOException if there is a communication error with the server * @throws SolrServerException if there is an error on the server * * @see SolrClient#getBinder() * * @since solr 3.5 */ public UpdateResponse addBeans(Collection<?> beans, int commitWithinMs) throws SolrServerException, IOException { return addBeans(null, beans, commitWithinMs); }
/** * Adds a collection of beans specifying max time before they become committed * * The beans are converted to {@link SolrInputDocument}s by the client's * {@link org.apache.solr.client.solrj.beans.DocumentObjectBinder} * * @param beans the collection of beans * @param commitWithinMs max time (in ms) before a commit will happen * * @return an {@link org.apache.solr.client.solrj.response.UpdateResponse} from the server * * @throws IOException if there is a communication error with the server * @throws SolrServerException if there is an error on the server * * @see SolrClient#getBinder() * * @since solr 3.5 */ public UpdateResponse addBeans(Collection<?> beans, int commitWithinMs) throws SolrServerException, IOException { return addBeans(null, beans, commitWithinMs); }
@Override public void process(Exchange exchange) throws Exception { String operation = (String) exchange.getIn().getHeader(SolrConstants.OPERATION); if (operation == null) { throw new IllegalArgumentException(SolrConstants.OPERATION + " header is missing"); } SolrClient serverToUse = getBestSolrServer(operation); if (operation.equalsIgnoreCase(SolrConstants.OPERATION_INSERT)) { insert(exchange, serverToUse); } else if (operation.equalsIgnoreCase(SolrConstants.OPERATION_INSERT_STREAMING)) { insert(exchange, serverToUse); } else if (operation.equalsIgnoreCase(SolrConstants.OPERATION_DELETE_BY_ID)) { serverToUse.deleteById(exchange.getIn().getBody(String.class)); } else if (operation.equalsIgnoreCase(SolrConstants.OPERATION_DELETE_BY_QUERY)) { serverToUse.deleteByQuery(exchange.getIn().getBody(String.class)); } else if (operation.equalsIgnoreCase(SolrConstants.OPERATION_ADD_BEAN)) { serverToUse.addBean(exchange.getIn().getBody()); } else if (operation.equalsIgnoreCase(SolrConstants.OPERATION_ADD_BEANS)) { serverToUse.addBeans(exchange.getIn().getBody(Collection.class)); } else if (operation.equalsIgnoreCase(SolrConstants.OPERATION_COMMIT)) { serverToUse.commit(); } else if (operation.equalsIgnoreCase(SolrConstants.OPERATION_ROLLBACK)) { serverToUse.rollback(); } else if (operation.equalsIgnoreCase(SolrConstants.OPERATION_OPTIMIZE)) { serverToUse.optimize(); } else { throw new IllegalArgumentException( SolrConstants.OPERATION + " header value '" + operation + "' is not supported"); } }
@Override public void storeOntologyEntries(List<OntologyEntryBean> entries) throws StorageEngineException { if (entries.isEmpty()) { LOGGER.debug("storeOntologyEntries called with empty list - ignoring"); } else { try { UpdateResponse response = server.addBeans(entries, config.getCommitWithinMs()); if (response.getStatus() != STATUS_OK) { LOGGER.error("Unexpected response: {}", response.getResponse()); throw new StorageEngineException("Could not store entries: " + response.getResponse()); } } catch (IOException e) { LOGGER.error("IO exception when calling server: {}", e.getMessage()); throw new StorageEngineException(e); } catch (SolrServerException e) { LOGGER.error("Server exception when storing entries: {}", e.getMessage()); throw new StorageEngineException(e); } } }
public <T, M> void insertCatalogCollection(List<T> records, ComplexTypeConverter converter, String collectionName) throws IOException, CatalogException { List<M> solrModels = new ArrayList<>(); for (T record : records) { solrModels.add((M) converter.convertToStorageType(record)); } UpdateResponse updateResponse; try { updateResponse = solrManager.getSolrClient().addBeans(DATABASE_PREFIX + collectionName, solrModels); if (updateResponse.getStatus() == 0) { solrManager.getSolrClient().commit(DATABASE_PREFIX + collectionName); } } catch (SolrServerException e) { throw new CatalogException(e.getMessage(), e); } }
/** * Insert a list of variants into the given Solr collection. * * @param collection Solr collection where to insert * @param variants List of variants to insert * @throws IOException IOException * @throws SolrServerException SolrServerException */ public void insert(String collection, List<Variant> variants) throws IOException, SolrServerException { if (variants != null && CollectionUtils.isNotEmpty(variants)) { List<VariantSearchModel> variantSearchModels = variantSearchToVariantConverter.convertListToStorageType(variants); if (!variantSearchModels.isEmpty()) { UpdateResponse updateResponse; updateResponse = solrManager.getSolrClient().addBeans(collection, variantSearchModels); if (updateResponse.getStatus() == 0) { solrManager.getSolrClient().commit(collection); } } } }