/
BooleanParameter.java
72 lines (59 loc) · 1.84 KB
/
BooleanParameter.java
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
67
68
69
70
71
72
/*
*
* MariaDB Client for Java
*
* Copyright (c) 2012-2014 Monty Program Ab.
* Copyright (c) 2015-2019 MariaDB Ab.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with this library; if not, write to Monty Program Ab info@montyprogram.com.
*
*/
package org.mariadb.jdbc.internal.com.send.parameters;
import org.mariadb.jdbc.internal.ColumnType;
import org.mariadb.jdbc.internal.io.output.PacketOutputStream;
import java.io.IOException;
public class BooleanParameter implements Cloneable, ParameterHolder {
private final boolean value;
public BooleanParameter(boolean value) {
this.value = value;
}
public void writeTo(final PacketOutputStream os) throws IOException {
os.write(value ? '1' : '0');
}
public int getApproximateTextProtocolLength() {
return 1;
}
/**
* Write data to socket in binary format.
*
* @param pos socket output stream
* @throws IOException if socket error occur
*/
public void writeBinary(final PacketOutputStream pos) throws IOException {
pos.write(value ? 1 : 0);
}
public ColumnType getColumnType() {
return ColumnType.TINYINT;
}
@Override
public String toString() {
return Boolean.toString(value);
}
public boolean isNullData() {
return false;
}
public boolean isLongData() {
return false;
}
}