Ether Framework
Unified API docs for Ether modules
Loading...
Searching...
No Matches
SQLiteParameters.java
Go to the documentation of this file.
1package dev.rafex.ether.database.sqlite.sql;
2
3/*-
4 * #%L
5 * ether-database-sqlite
6 * %%
7 * Copyright (C) 2025 - 2026 Raúl Eduardo González Argote
8 * %%
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 * THE SOFTWARE.
26 * #L%
27 */
28
29import java.sql.Types;
30
31import dev.rafex.ether.database.core.sql.SqlParameter;
32
33/**
34 * SQLite-specific parameter helpers.
35 * <p>
36 * SQLite has a dynamic type system with five storage classes:
37 * <ul>
38 * <li>NULL</li>
39 * <li>INTEGER (signed 64-bit)</li>
40 * <li>REAL (64-bit floating point)</li>
41 * <li>TEXT (UTF-8, UTF-16BE or UTF-16LE)</li>
42 * <li>BLOB (binary data)</li>
43 * </ul>
44 * JSON support is available via the optional JSON1 extension.
45 */
46public final class SQLiteParameters {
47
48 private SQLiteParameters() {
49 }
50
51 /**
52 * Creates a BLOB parameter for binary data.
53 *
54 * @param data the binary data, may be {@code null}
55 * @return a {@code SqlParameter} with type {@link Types#BLOB}
56 */
57 public static SqlParameter blob(final byte[] data) {
58 return data == null ? SqlParameter.nullOf(Types.BLOB) : new SqlParameter(data, Types.BLOB, null);
59 }
60
61 /**
62 * Creates a JSON parameter.
63 * <p>
64 * <strong>Note:</strong> Requires the JSON1 extension to be available at runtime.
65 * If the extension is not loaded, this will be treated as ordinary TEXT.
66 *
67 * @param json the JSON string, may be {@code null}
68 * @return a {@code SqlParameter} with type {@link Types#OTHER}
69 */
70 public static SqlParameter json(final String json) {
71 return json == null ? SqlParameter.nullOf(Types.OTHER) : new SqlParameter(json, Types.OTHER, null);
72 }
73
74 /**
75 * Creates an INTEGER parameter.
76 *
77 * @param value the integer value, may be {@code null}
78 * @return a {@code SqlParameter} with type {@link Types#BIGINT}
79 */
80 public static SqlParameter integer(final Long value) {
81 return value == null ? SqlParameter.nullOf(Types.BIGINT) : new SqlParameter(value, Types.BIGINT, null);
82 }
83
84 /**
85 * Creates a REAL (floating-point) parameter.
86 *
87 * @param value the floating-point value, may be {@code null}
88 * @return a {@code SqlParameter} with type {@link Types#DOUBLE}
89 */
90 public static SqlParameter real(final Double value) {
91 return value == null ? SqlParameter.nullOf(Types.DOUBLE) : new SqlParameter(value, Types.DOUBLE, null);
92 }
93
94 /**
95 * Creates a TEXT parameter.
96 *
97 * @param text the text value, may be {@code null}
98 * @return a {@code SqlParameter} with type {@link Types#VARCHAR}
99 */
100 public static SqlParameter text(final String text) {
101 return text == null ? SqlParameter.nullOf(Types.VARCHAR) : new SqlParameter(text, Types.VARCHAR, null);
102 }
103}
static SqlParameter integer(final Long value)
Creates an INTEGER parameter.
static SqlParameter blob(final byte[] data)
Creates a BLOB parameter for binary data.
static SqlParameter json(final String json)
Creates a JSON parameter.
static SqlParameter text(final String text)
Creates a TEXT parameter.
static SqlParameter real(final Double value)
Creates a REAL (floating-point) parameter.