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 2018 Viridian Software Limited
*
* 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 com.elefana.document;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import com.elefana.api.document.DocumentShardInfo;
import org.postgresql.copy.CopyIn;
import org.postgresql.copy.CopyManager;
import org.postgresql.jdbc.PgConnection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import com.codahale.metrics.Timer;
import com.elefana.api.document.BulkItemResponse;
import com.elefana.api.document.BulkOpType;
import com.elefana.api.exception.ShardFailedException;
import com.elefana.util.IndexUtils;
import com.jsoniter.JsonIterator;
import com.jsoniter.spi.JsonException;
public class BulkTask implements Callable> {
private static final Logger LOGGER = LoggerFactory.getLogger(BulkTask.class);
private static final String FALLBACK_STAGING_TABLE_PREFIX = "elefana_fallback_stg_";
private static int FALLBACK_STAGING_TABLE_ID = 0;
private static final String DELIMITER = "|";
private static final String NEW_LINE = "\n";
public static final String KEY_INDEX = "_index";
public static final String KEY_TYPE = "_type";
public static final String KEY_ID = "_id";
public static final String KEY_VERSION = "_version";
public static final String KEY_SHARDS = "_shards";
public static final String KEY_RESULT = "result";
public static final String VALUE_RESULT_CREATED = "created";
public static final String KEY_CREATED = "created";
public static final boolean VALUE_CREATED = true;
public static final String KEY_STATUS = "status";
public static final int VALUE_STATUS_CREATED = 201;
private static final long ONE_SECOND_IN_MILLIS = 1000L;
private static final long ONE_MINUTE_IN_MILLIS = ONE_SECOND_IN_MILLIS * 60L;
private static final long ONE_HOUR_IN_MILLIS = ONE_MINUTE_IN_MILLIS * 60L;
private static final long ONE_DAY_IN_MILLIS = ONE_HOUR_IN_MILLIS * 24L;
private static final DocumentShardInfo SHARDS = new DocumentShardInfo();
private final Timer psqlTimer;
private final JdbcTemplate jdbcTemplate;
private final List indexOperations;
private final String tablespace;
private final String index;
private final String queryTarget;
private final int from;
private final int size;
private final String stagingTable;
public BulkTask(Timer psqlTimer, JdbcTemplate jdbcTemplate, List indexOperations,
String tablespace, String index, String queryTarget, int from, int size) {
super();
this.psqlTimer = psqlTimer;
this.jdbcTemplate = jdbcTemplate;
this.indexOperations = indexOperations;
this.tablespace = tablespace;
this.index = index;
this.queryTarget = queryTarget;
this.from = from;
this.size = size;
List