Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2019 Immutables Authors and Contributors
*
* Licensed 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.immutables.criteria.elasticsearch;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.base.Preconditions;
import io.reactivex.Flowable;
import org.elasticsearch.client.RestClient;
import org.immutables.criteria.backend.Backend;
import org.immutables.criteria.backend.DefaultResult;
import org.immutables.criteria.backend.KeyExtractor;
import org.immutables.criteria.backend.PathNaming;
import org.immutables.criteria.backend.ProjectedTuple;
import org.immutables.criteria.backend.StandardOperations;
import org.immutables.criteria.backend.WriteResult;
import org.immutables.criteria.expression.Path;
import org.immutables.criteria.expression.Query;
import org.reactivestreams.Publisher;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
* Queries ElasticSearch data-store.
*/
public class ElasticsearchBackend implements Backend {
final RestClient restClient;
final ObjectMapper objectMapper;
private final IndexResolver resolver;
private final KeyExtractor.Factory keyExtractorFactory;
private final int scrollSize;
private final PathNaming pathNaming;
public ElasticsearchBackend(ElasticsearchSetup setup) {
Objects.requireNonNull(setup, "setup");
this.restClient = setup.restClient();
this.objectMapper = setup.objectMapper();
this.resolver = setup.indexResolver();
this.scrollSize = setup.scrollSize();
this.keyExtractorFactory = setup.keyExtractorFactory();
this.pathNaming = PathNaming.defaultNaming();
}
@Override
public Backend.Session open(Class> entityType) {
final String index = resolver.resolve(entityType);
return new Session(entityType, keyExtractorFactory.create(entityType), new ElasticsearchOps(restClient, index, objectMapper, scrollSize), pathNaming);
}
static class Session implements Backend.Session {
final Class> entityType;
final ObjectMapper objectMapper;
final ElasticsearchOps ops;
final KeyExtractor keyExtractor;
final JsonConverter