Package at.molindo.esi4j.mapping

Examples of at.molindo.esi4j.mapping.TypeMapping


    index.execute(new Esi4JOperation<Void>() {

      @Override
      public Void execute(Client client, String indexName, Esi4JOperation.OperationContext context) {

        final TypeMapping mapping = context.findTypeMapping(rebuildSession.getType());

        ModuleIdAndVersionStream moduleStream = new ModuleIdAndVersionStream(rebuildSession,
            DEFAULT_BATCH_SIZE, mapping);

        IdAndVersionFactory factory = new MappedObjectIdAndVersionFactory(mapping);

        ElasticSearchSorter elasticSearchSorter = new ElasticSearchSorter(createSorter(factory));
        IteratorFactory iteratorFactory = new IteratorFactory(factory);
        String workingDirectory = SystemUtils.getJavaIoTmpDir().getAbsolutePath();

        ElasticSearchIdAndVersionStream esStream = new ElasticSearchIdAndVersionStream(
            new ElasticSearchDownloader(client, indexName, "_type:" + mapping.getTypeAlias(), factory),
            elasticSearchSorter, iteratorFactory, workingDirectory);

        long start = System.currentTimeMillis();

        BulkIndexHelper h = new BulkIndexHelper().setMaxRunning(2);
        h.setResponseHandler(new BulkIndexHelper.IResponseHandler() {

          @Override
          public void handle(String id, String type) {
            if ("delete".equals(type)) {
              onDelete(mapping.getTypeClass(), mapping.toId(id));
            } else if ("index".equals(type)) {
              onIndex(mapping.getTypeClass(), mapping.toId(id));
            } else if ("create".equals(type)) {
              onCreate(mapping.getTypeClass(), mapping.toId(id));
            } else {
              log.warn("unexpected operation type {}", type);
            }
          }
        });
View Full Code Here


      add(toIndexRequest(o));
      return this;
    }

    public IndexRequestBuilder toIndexRequest(Object object) {
      TypeMapping mapping = _context.findTypeMapping(object);
      return mapping.indexRequest(_client, _indexName, object);
    }
View Full Code Here

      TypeMapping mapping = _context.findTypeMapping(object);
      return mapping.indexRequest(_client, _indexName, object);
    }

    public Session delete(Object o) {
      TypeMapping mapping = _context.findTypeMapping(o);
      delete(mapping.getTypeClass(), mapping.getId(o), mapping.getVersion(o));
      return this;
    }
View Full Code Here

      add(toDeleteRequest(type, id, version));
      return this;
    }

    private DeleteRequestBuilder toDeleteRequest(Class<?> type, Object id, Long version) {
      TypeMapping mapping = _context.findTypeMapping(type);
      return mapping.deleteRequest(_client, _indexName, mapping.toIdString(id), version);
    }
View Full Code Here

  public Esi4JRebuildSession startRebuildSession(final Class<?> type) {
    return _index.execute(new Esi4JOperation<Esi4JRebuildSession>() {

      @Override
      public Esi4JRebuildSession execute(Client client, String indexName, OperationContext helper) {
        final TypeMapping mapping = helper.findTypeMapping(type);

        return new Esi4JRebuildSession() {

          private final long _scrollTimeoutSeconds = 60;

          private String _scrollId;
          private boolean _endReached = false;

          @Override
          public boolean isOrdered() {
            return true;
          }

          @Override
          public Class<?> getType() {
            return type;
          }

          /**
           * only uses the batchSize from the first invocation and
           * ignores changes
           */
          @Override
          public List<?> getNext(int batchSize) {
            if (_endReached) {
              // TODO improve
              throw new IllegalStateException("reached end");
            }

            ActionFuture<SearchResponse> responseFuture;
            if (_scrollId == null) {
              // first request
              SearchRequestBuilder builder = new SearchRequestBuilder(_client)
                  .setIndices(mapping.getTypeAlias()).setFilter(FilterBuilders.matchAllFilter())
                  .setScroll(TimeValue.timeValueSeconds(_scrollTimeoutSeconds))
                  .addSort("_id", SortOrder.ASC).setSize(batchSize);

              responseFuture = _client.search(builder.request());
            } else {
              responseFuture = _client.searchScroll(new SearchScrollRequestBuilder(_client, _scrollId)
                  .request());
            }

            SearchResponse response = responseFuture.actionGet();

            SearchHit[] hits = response.getHits().getHits();
            ArrayList<Object> list = new ArrayList<Object>(hits.length);

            if (hits.length == 0) {
              _endReached = true;
              _scrollId = null;
            } else {
              _scrollId = response.getScrollId();
              for (int i = 0; i < hits.length; i++) {
                Object o = mapping.read(hits[i]);
                if (o != null) {
                  list.add(o);
                }
              }
            }
View Full Code Here

    index.execute(new Esi4JOperation<Void>() {

      @Override
      public Void execute(Client client, String indexName, Esi4JOperation.OperationContext context) {

        final TypeMapping mapping = context.findTypeMapping(rebuildSession.getType());

        ModuleIdAndVersionStream moduleStream = new ModuleIdAndVersionStream(rebuildSession,
            DEFAULT_BATCH_SIZE, mapping);

        IdAndVersionFactory factory = new MappedObjectIdAndVersionFactory(mapping);

        ElasticSearchSorter elasticSearchSorter = new ElasticSearchSorter(createSorter(factory));
        IteratorFactory iteratorFactory = new IteratorFactory(factory);
        String workingDirectory = SystemUtils.getJavaIoTmpDir().getAbsolutePath();

        ElasticSearchIdAndVersionStream esStream = new ElasticSearchIdAndVersionStream(
            new ElasticSearchDownloader(client, indexName, "_type:" + mapping.getTypeAlias(), factory),
            elasticSearchSorter, iteratorFactory, workingDirectory);

        BulkIndexHelper bulkHelper = new BulkIndexHelper().setMaxRunning(2);
        bulkHelper.setResponseHandler(new BulkIndexHelper.IResponseHandler() {

          @Override
          public void handle(String id, String type) {
            if ("delete".equals(type)) {
              onDelete(mapping.getTypeClass(), mapping.toId(id));
            } else {
              onIndex(mapping.getTypeClass(), mapping.toId(id));
            }
          }

        });
View Full Code Here

  public Esi4JRebuildSession startRebuildSession(final Class<?> type) {
    return _index.execute(new Esi4JOperation<Esi4JRebuildSession>() {

      @Override
      public Esi4JRebuildSession execute(Client client, String indexName, OperationContext helper) {
        final TypeMapping mapping = helper.findTypeMapping(type);

        return new Esi4JRebuildSession() {

          private final long _scrollTimeoutSeconds = 60;

          private String _scrollId;
          private boolean _endReached = false;

          @Override
          public boolean isOrdered() {
            return true;
          }

          @Override
          public Class<?> getType() {
            return type;
          }

          /**
           * only uses the batchSize from the first invocation and
           * ignores changes
           */
          @Override
          public List<?> getNext(int batchSize) {
            if (_endReached) {
              // TODO improve
              throw new IllegalStateException("reached end");
            }

            ActionFuture<SearchResponse> responseFuture;
            if (_scrollId == null) {
              // first request
              SearchRequestBuilder builder = new SearchRequestBuilder(_client)
                  .setIndices(mapping.getTypeAlias()).setFilter(FilterBuilders.matchAllFilter())
                  .setScroll(TimeValue.timeValueSeconds(_scrollTimeoutSeconds))
                  .addSort("_id", SortOrder.ASC).setSize(batchSize);

              responseFuture = _client.search(builder.request());
            } else {
              responseFuture = _client.searchScroll(new SearchScrollRequestBuilder(_client, _scrollId)
                  .request());
            }

            SearchResponse response = responseFuture.actionGet();

            SearchHit[] hits = response.getHits().getHits();
            ArrayList<Object> list = new ArrayList<Object>(hits.length);

            if (hits.length == 0) {
              _endReached = true;
              _scrollId = null;
            } else {
              _scrollId = response.getScrollId();
              for (int i = 0; i < hits.length; i++) {
                Object o = mapping.read(hits[i]);
                if (o != null) {
                  list.add(o);
                }
              }
            }
View Full Code Here

    return ListenableActionFutureWrapper.wrap(execute(indexOperation),
        new Function<IndexResponse, IndexResponseWrapper>() {

          @Override
          public IndexResponseWrapper apply(IndexResponse input) {
            TypeMapping typeMapping = _mappings.getTypeMapping(input.getType());
            Object id = typeMapping.toId(input.getId());
            return new DefaultIndexResponseWrapper(input, id);
          }
        });
  }
View Full Code Here

    return ListenableActionFutureWrapper.wrap(execute(getOperation),
        new Function<GetResponse, GetResponseWrapper>() {

          @Override
          public GetResponseWrapper apply(GetResponse input) {
            TypeMapping typeMapping = _mappings.getTypeMapping(input.getType());
            Object object = typeMapping.read(input);
            return new DefaultGetResponseWrapper(input, object);
          }
        });
  }
View Full Code Here

        });
  }

  @Override
  public ListenableActionFuture<DeleteResponseWrapper> delete(Object object) {
    TypeMapping typeMapping = _mappings.findTypeMapping(object);
    return executeDelete(new Delete(typeMapping.getTypeClass(), typeMapping.getId(object)));
  }
View Full Code Here

TOP

Related Classes of at.molindo.esi4j.mapping.TypeMapping

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.