Class CopyInImpl
- java.lang.Object
-
- org.postgresql.core.v3.CopyOperationImpl
-
- org.postgresql.core.v3.CopyInImpl
-
- All Implemented Interfaces:
CopyIn
,CopyOperation
public class CopyInImpl extends CopyOperationImpl implements CopyIn
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()
-
-
Constructor Summary
Constructors Constructor Description CopyInImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
endCopy()
Finishes copy operation successfully.void
flushCopy()
Force any buffered output to be sent over the network to the backend.protected void
handleCopydata(byte[] data)
Consume received copy data.void
writeToCopy(byte[] data, int off, int siz)
Writes specified part of given byte array to an open and writable copy operation.void
writeToCopy(ByteStreamWriter from)
Writes a ByteStreamWriter to an open and writable copy operation.-
Methods inherited from class org.postgresql.core.v3.CopyOperationImpl
cancelCopy, getFieldCount, getFieldFormat, getFormat, getHandledRowCount, getQueryExecutor, handleCommandStatus, isActive
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.postgresql.copy.CopyOperation
cancelCopy, getFieldCount, getFieldFormat, getFormat, getHandledRowCount, isActive
-
-
-
-
Method Detail
-
writeToCopy
public void writeToCopy(byte[] data, int off, int siz) throws java.sql.SQLException
Description copied from interface:CopyIn
Writes specified part of given byte array to an open and writable copy operation.- Specified by:
writeToCopy
in interfaceCopyIn
- Parameters:
data
- array of bytes to writeoff
- offset of first byte to write (normally zero)siz
- number of bytes to write (normally buf.length)- Throws:
java.sql.SQLException
- if the operation fails
-
writeToCopy
public void writeToCopy(ByteStreamWriter from) throws java.sql.SQLException
Description copied from interface:CopyIn
Writes a ByteStreamWriter to an open and writable copy operation.- Specified by:
writeToCopy
in interfaceCopyIn
- Parameters:
from
- the source of bytes, e.g. a ByteBufferByteStreamWriter- Throws:
java.sql.SQLException
- if the operation fails
-
flushCopy
public void flushCopy() throws java.sql.SQLException
Description copied from interface:CopyIn
Force any buffered output to be sent over the network to the backend. In general this is a useless operation as it will get pushed over in due time or when endCopy is called. Some specific modified server versions (Truviso) want this data sooner. If you are unsure if you need to use this method, don't.
-
endCopy
public long endCopy() throws java.sql.SQLException
Description copied from interface:CopyIn
Finishes copy operation successfully.
-
handleCopydata
protected void handleCopydata(byte[] data) throws PSQLException
Description copied from class:CopyOperationImpl
Consume received copy data.- Specified by:
handleCopydata
in classCopyOperationImpl
- Parameters:
data
- data that was receive by copy protocol- Throws:
PSQLException
- if some internal problem occurs
-
-