~ubuntu-branches/ubuntu/maverick/libpgjava/maverick

« back to all changes in this revision

Viewing changes to org/postgresql/fastpath/FastpathArg.java

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Vandyck
  • Date: 2006-04-25 00:07:07 UTC
  • mfrom: (1.3.1 upstream) (3.1.1 dapper)
  • Revision ID: james.westby@ubuntu.com-20060425000707-6lr2s0awuz4z48hm
* Drop support for the old jdbc2 driver (can be reverted if wanted)
  (closes: #358345).
* New upstream (thanks to Wolfgang Baer).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
*
 
3
* Copyright (c) 2003-2005, PostgreSQL Global Development Group
 
4
*
 
5
* IDENTIFICATION
 
6
*   $PostgreSQL: pgjdbc/org/postgresql/fastpath/FastpathArg.java,v 1.12 2005/01/11 08:25:45 jurka Exp $
 
7
*
 
8
*-------------------------------------------------------------------------
 
9
*/
 
10
package org.postgresql.fastpath;
 
11
 
 
12
import java.sql.SQLException;
 
13
import org.postgresql.core.ParameterList;
 
14
 
 
15
// Not a very clean mapping to the new QueryExecutor/ParameterList
 
16
// stuff, but it seems hard to support both v2 and v3 cleanly with
 
17
// the same model while retaining API compatibility. So I've just
 
18
// done it the ugly way..
 
19
 
 
20
/**
 
21
 *     Each fastpath call requires an array of arguments, the number and type
 
22
 *     dependent on the function being called.
 
23
 */
 
24
public class FastpathArg
 
25
{
 
26
    /**
 
27
     * Encoded byte value of argument.
 
28
     */
 
29
    private final byte[] bytes;
 
30
    private final int bytesStart;
 
31
    private final int bytesLength;
 
32
 
 
33
    /**
 
34
     * Constructs an argument that consists of an integer value
 
35
     * @param value int value to set
 
36
     */
 
37
    public FastpathArg(int value)
 
38
    {
 
39
        bytes = new byte[4];
 
40
        bytes[3] = (byte) (value);
 
41
        bytes[2] = (byte) (value >> 8);
 
42
        bytes[1] = (byte) (value >> 16);
 
43
        bytes[0] = (byte) (value >> 24);
 
44
        bytesStart = 0;
 
45
        bytesLength = 4;
 
46
    }
 
47
 
 
48
    /**
 
49
     * Constructs an argument that consists of an array of bytes
 
50
     * @param bytes array to store
 
51
     */
 
52
    public FastpathArg(byte bytes[])
 
53
    {
 
54
        this(bytes, 0, bytes.length);
 
55
    }
 
56
 
 
57
    /**
 
58
     * Constructs an argument that consists of part of a byte array
 
59
     * @param buf source array
 
60
     * @param off offset within array
 
61
     * @param len length of data to include
 
62
     */
 
63
    public FastpathArg(byte buf[], int off, int len)
 
64
    {
 
65
        this.bytes = buf;
 
66
        this.bytesStart = off;
 
67
        this.bytesLength = len;
 
68
    }
 
69
 
 
70
    /**
 
71
     * Constructs an argument that consists of a String.
 
72
     * @param s String to store
 
73
     */
 
74
    public FastpathArg(String s)
 
75
    {
 
76
        this(s.getBytes());
 
77
    }
 
78
 
 
79
    void populateParameter(ParameterList params, int index) throws SQLException {
 
80
        if (bytes == null)
 
81
            params.setNull(index, 0);
 
82
        else
 
83
            params.setBytea(index, bytes, bytesStart, bytesLength);
 
84
    }
 
85
}
 
86