All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.amazon.redshift.core.v3.CopyDualImpl Maven / Gradle / Ivy

There is a newer version: 2.1.0.30
Show newest version
/*
 * Copyright (c) 2016, PostgreSQL Global Development Group
 * See the LICENSE file in the project root for more information.
 */

package com.amazon.redshift.core.v3;

import com.amazon.redshift.copy.CopyDual;
import com.amazon.redshift.util.ByteStreamWriter;
import com.amazon.redshift.util.RedshiftException;

import java.sql.SQLException;
import java.util.LinkedList;
import java.util.Queue;

public class CopyDualImpl extends CopyOperationImpl implements CopyDual {
  private Queue received = new LinkedList();

  public void writeToCopy(byte[] data, int off, int siz) throws SQLException {
    queryExecutor.writeToCopy(this, data, off, siz);
  }

  public void writeToCopy(ByteStreamWriter from) throws SQLException {
    queryExecutor.writeToCopy(this, from);
  }

  public void flushCopy() throws SQLException {
    queryExecutor.flushCopy(this);
  }

  public long endCopy() throws SQLException {
    return queryExecutor.endCopy(this);
  }

  public byte[] readFromCopy() throws SQLException {
    return readFromCopy(true);
  }

  @Override
  public byte[] readFromCopy(boolean block) throws SQLException {
    if (received.isEmpty()) {
      queryExecutor.readFromCopy(this, block);
    }

    return received.poll();
  }

  @Override
  public void handleCommandStatus(String status) throws RedshiftException {
  }

  protected void handleCopydata(byte[] data) {
    received.add(data);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy