All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ing.data.cassandra.jdbc.CassandraStatementJsonSupport Maven / Gradle / Ivy

There is a newer version: 4.13.1
Show newest version
/*
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

package com.ing.data.cassandra.jdbc;

import java.math.BigInteger;
import java.net.InetAddress;
import java.nio.ByteBuffer;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

/**
 * Extension of {@link PreparedStatement} interface providing additional methods specific to Cassandra statements using
 * JSON features {@code INSERT INTO ... JSON} and {@code fromJson()}.
 * 
* Using the methods defined into this interface requires some considerations relative to the acceptable types for * serialization. The table below lists the acceptable type(s) in the Java object serialized to JSON to be correctly * parsed on Cassandra side. Note that all non-collection fields in the Java object to serialize can be {@link String} * (be careful with the format to use for some CQL types like dates for example) and the collections can contain * {@link String} items. * * * * * * * * * * * * * * * * * * * * * * * * * * *
CQL Type Accepted JSON types Acceptable Java types
ascii string {@link String}
bigint integer, string {@link Integer}, {@link BigInteger}
blob string {@link ByteBuffer}, {@link String} (should be an * even-length hexadecimal representation of the blob bytes starting with '0x')
boolean boolean, string {@link Boolean}
date string {@link Date}, {@link LocalDate}
decimal integer, float, string{@link Number}
double integer, float, string{@link Number}
float integer, float, string{@link Number}
inet string {@link InetAddress}
int integer, string {@link Integer}
list list, string {@link List}
map map, string {@link Map}
set list, string {@link Set}, {@link List}
smallint integer, string {@link Short}
text string {@link String}
time string {@link LocalTime}
timestampinteger, string {@link Integer}, {@link OffsetDateTime}
timeuuid string {@link UUID}
tinyint integer, string {@link Byte}
tuple list, string {@link List}
udt map, string {@link Map} or a suitable object serializable * and matching the target UDT
uuid string {@link UUID}
varchar string {@link String}
varint integer, string {@link Integer}, {@link BigInteger}
* See: * CQL reference for JSON support. */ public interface CassandraStatementJsonSupport extends PreparedStatement { /** * Sets the value of the designated parameter with the given object converted to a JSON string. *

* Typically, this method can be called to bind a JSON parameter in a CQL query like:
* * INSERT INTO exampleTable JSON ?; * *
or on a specific column using with the function {@code fromJson()}:
* * INSERT INTO exampleTable (item) VALUES (fromJson(?)); * *

* * @param parameterIndex The parameter index (the first parameter is 1). * @param x The object containing the input parameter value. * @param The type of the original object before conversion to a JSON string. * @throws SQLException if the parameter index does not correspond to a parameter marker in the SQL statement; if a * database access error occurs; if this method is called on a closed {@link PreparedStatement} * or if the object specified by {@code x} cannot be converted into a valid JSON string. */ void setJson(int parameterIndex, T x) throws SQLException; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy