File: CopyOperationImpl.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 (66 lines) | stat: -rw-r--r-- 1,843 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
55
56
57
58
59
60
61
62
63
64
65
66
/*-------------------------------------------------------------------------
*
* Copyright (c) 2009, PostgreSQL Global Development Group
*
* IDENTIFICATION
*   $PostgreSQL: pgjdbc/org/postgresql/core/v3/CopyOperationImpl.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.CopyOperation;
import org.postgresql.util.GT;
import org.postgresql.util.PSQLException;
import org.postgresql.util.PSQLState;

public class CopyOperationImpl implements CopyOperation {
    String sql;
    QueryExecutorImpl queryExecutor;
    int rowFormat;
    int[] fieldFormats;
    long handledRowCount = -1;
    
    void init(QueryExecutorImpl q, int fmt, int[] fmts) {
        queryExecutor = q;
        rowFormat = fmt;
        fieldFormats = fmts;
    }

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

    public int getFieldCount() {
        return fieldFormats.length;
    }

    public int getFieldFormat(int field) {
        return fieldFormats[field];
    }

    public int getFormat() {
        return rowFormat;
    }

    public boolean isActive() {
        synchronized(queryExecutor) {
            return queryExecutor.hasLock(this);
        }
    }
    
    public void handleCommandStatus(String status) throws PSQLException {
        if(status.startsWith("COPY")) {
            int i = status.lastIndexOf(' ');
            handledRowCount = i > 3 ? Long.parseLong(status.substring( i + 1 )) : -1;
        } else {
            throw new PSQLException(GT.tr("CommandComplete expected COPY but got: " + status), PSQLState.COMMUNICATION_ERROR);
        }
    }

    public long getHandledRowCount() {
        return handledRowCount;
    }
}