File: CopyOutImpl.java

package info (click to toggle)
libpgjava 8.4-701-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 3,532 kB
  • ctags: 4,162
  • sloc: java: 33,948; xml: 3,158; makefile: 14; sh: 10
file content (54 lines) | stat: -rw-r--r-- 1,935 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*-------------------------------------------------------------------------
*
* Copyright (c) 2009, PostgreSQL Global Development Group
*
* IDENTIFICATION
*   $PostgreSQL: pgjdbc/org/postgresql/core/v3/CopyOutImpl.java,v 1.1 2009/07/01 05:00:40 jurka Exp $
*
*-------------------------------------------------------------------------
*/
package org.postgresql.core.v3;

import java.sql.SQLException;

import org.postgresql.copy.CopyOut;

/**
 * Anticipated flow of a COPY TO STDOUT operation:
 * 
 * CopyManager.copyOut()
 *   ->QueryExecutor.startCopy()
 *       - sends given query to server
 *       ->processCopyResults():
 *           - receives CopyOutResponse from Server
 *           - creates new CopyOutImpl
 *           ->initCopy():
 *              - receives copy metadata from server
 *              ->CopyOutImpl.init()
 *              ->lock() connection for this operation
 *   - if query fails an exception is thrown
 *   - if query returns wrong CopyOperation, copyOut() cancels it before throwing exception
 * <-returned: new CopyOutImpl holding lock on connection
 * repeat CopyOut.readFromCopy() until null
 *   ->CopyOutImpl.readFromCopy()
 *       ->QueryExecutorImpl.readFromCopy()
 *           ->processCopyResults()
 *               - on copydata row from server
 *                   ->CopyOutImpl.handleCopydata() stores reference to byte array
 *               -  on CopyDone, CommandComplete, ReadyForQuery
 *                   ->unlock() connection for use by other operations
 * <-returned: byte array of data received from server or null at end.
 */
public class CopyOutImpl extends CopyOperationImpl implements CopyOut {
    private byte[] currentDataRow;

    public byte[] readFromCopy() throws SQLException {
        currentDataRow = null;
        queryExecutor.readFromCopy(this);
        return currentDataRow;
    }

    void handleCopydata(byte[] data) {
        currentDataRow = data;
    }
}