com.amazon.redshift.core.v3.CopyInImpl Maven / Gradle / Ivy
Show all versions of redshift-jdbc42 Show documentation
/*
* Copyright (c) 2009, 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.CopyIn;
import com.amazon.redshift.util.ByteStreamWriter;
import com.amazon.redshift.util.GT;
import com.amazon.redshift.util.RedshiftException;
import com.amazon.redshift.util.RedshiftState;
import java.sql.SQLException;
/**
* COPY FROM STDIN operation.
*
* Anticipated flow:
*
* CopyManager.copyIn() ->QueryExecutor.startCopy() - sends given query to server
* ->processCopyResults(): - receives CopyInResponse from Server - creates new CopyInImpl
* ->initCopy(): - receives copy metadata from server ->CopyInImpl.init() ->lock()
* connection for this operation - if query fails an exception is thrown - if query returns wrong
* CopyOperation, copyIn() cancels it before throwing exception <-return: new CopyInImpl holding
* lock on connection repeat CopyIn.writeToCopy() for all data ->CopyInImpl.writeToCopy()
* ->QueryExecutorImpl.writeToCopy() - sends given data ->processCopyResults() - parameterized
* not to block, just peek for new messages from server - on ErrorResponse, waits until protocol is
* restored and unlocks connection CopyIn.endCopy() ->CopyInImpl.endCopy()
* ->QueryExecutorImpl.endCopy() - sends CopyDone - processCopyResults() - on CommandComplete
* ->CopyOperationImpl.handleCommandComplete() - sets updatedRowCount when applicable - on
* ReadyForQuery unlock() connection for use by other operations <-return:
* CopyInImpl.getUpdatedRowCount()
*/
public class CopyInImpl extends CopyOperationImpl implements CopyIn {
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);
}
protected void handleCopydata(byte[] data) throws RedshiftException {
throw new RedshiftException(GT.tr("CopyIn copy direction can't receive data"),
RedshiftState.PROTOCOL_VIOLATION);
}
}