File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\expression\ParameterRemote.java.html

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.expression;
8
9 import java.io.IOException;
10 import java.sql.ResultSetMetaData;
11 import org.h2.constant.ErrorCode;
12 import org.h2.message.DbException;
13 import org.h2.value.Transfer;
14 import org.h2.value.Value;
15
16 /**
17 * A client side (remote) parameter.
18 */
19 public class ParameterRemote implements ParameterInterface {
20
21 private Value value;
22 private final int index;
23 private int dataType = Value.UNKNOWN;
24 private long precision;
25 private int scale;
26 private int nullable = ResultSetMetaData.columnNullableUnknown;
27
28 public ParameterRemote(int index) {
29 this.index = index;
30 }
31
32 public void setValue(Value newValue, boolean closeOld) {
33 if (closeOld && value != null) {
34 value.close();
35 }
36 value = newValue;
37 }
38
39 public Value getParamValue() {
40 return value;
41 }
42
43 public void checkSet() {
44 if (value == null) {
45 throw DbException.get(ErrorCode.PARAMETER_NOT_SET_1, "#" + (index + 1));
46 }
47 }
48
49 public boolean isValueSet() {
50 return value != null;
51 }
52
53 public int getType() {
54 return value == null ? dataType : value.getType();
55 }
56
57 public long getPrecision() {
58 return value == null ? precision : value.getPrecision();
59 }
60
61 public int getScale() {
62 return value == null ? scale : value.getScale();
63 }
64
65 public int getNullable() {
66 return nullable;
67 }
68
69 /**
70 * Write the parameter meta data from the transfer object.
71 *
72 * @param transfer the transfer object
73 */
74 public void readMetaData(Transfer transfer) throws IOException {
75 dataType = transfer.readInt();
76 precision = transfer.readLong();
77 scale = transfer.readInt();
78 nullable = transfer.readInt();
79 }
80
81 /**
82 * Write the parameter meta data to the transfer object.
83 *
84 * @param transfer the transfer object
85 * @param p the parameter
86 */
87 public static void writeMetaData(Transfer transfer, ParameterInterface p) throws IOException {
88 transfer.writeInt(p.getType());
89 transfer.writeLong(p.getPrecision());
90 transfer.writeInt(p.getScale());
91 transfer.writeInt(p.getNullable());
92 }
93
94 }
95