1
/*-------------------------------------------------------------------------
3
* Copyright (c) 2003-2005, PostgreSQL Global Development Group
6
* $PostgreSQL: pgjdbc/org/postgresql/fastpath/FastpathArg.java,v 1.12 2005/01/11 08:25:45 jurka Exp $
8
*-------------------------------------------------------------------------
10
package org.postgresql.fastpath;
12
import java.sql.SQLException;
13
import org.postgresql.core.ParameterList;
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..
21
* Each fastpath call requires an array of arguments, the number and type
22
* dependent on the function being called.
24
public class FastpathArg
27
* Encoded byte value of argument.
29
private final byte[] bytes;
30
private final int bytesStart;
31
private final int bytesLength;
34
* Constructs an argument that consists of an integer value
35
* @param value int value to set
37
public FastpathArg(int value)
40
bytes[3] = (byte) (value);
41
bytes[2] = (byte) (value >> 8);
42
bytes[1] = (byte) (value >> 16);
43
bytes[0] = (byte) (value >> 24);
49
* Constructs an argument that consists of an array of bytes
50
* @param bytes array to store
52
public FastpathArg(byte bytes[])
54
this(bytes, 0, bytes.length);
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
63
public FastpathArg(byte buf[], int off, int len)
66
this.bytesStart = off;
67
this.bytesLength = len;
71
* Constructs an argument that consists of a String.
72
* @param s String to store
74
public FastpathArg(String s)
79
void populateParameter(ParameterList params, int index) throws SQLException {
81
params.setNull(index, 0);
83
params.setBytea(index, bytes, bytesStart, bytesLength);