Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *      Copyright (C) 2012 DataStax Inc.
   *
   *   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.datastax.driver.core;
 
 import java.util.*;
 
 
A prepared statement with values bound to the bind variables.

Once values has been provided for the variables of the PreparedStatement it has been created from, such BoundStatement can be executed (through Session.execute(com.datastax.driver.core.Query)).

The values of a BoundStatement can be set by either index or name. When setting them by name, names follow the case insensitivity rules explained in ColumnDefinitions. If multiple bind variables correspond to the same column (as would be the case if you prepare SELECT * FROM t WHERE x > ? AND x < ?), you will have to set values by indexes (or the bind(java.lang.Object[]) method) as the methods to set by name only allows to set the first prepared occurrence of the column.

Any variable that hasn't been specifically set will be considered null.

 
 public class BoundStatement extends Query {
 
     final PreparedStatement statement;
     final ByteBuffer[] values;

    
Creates a new BoundStatement from the provided prepared statement.

Parameters:
statement the prepared statement from which to create a BoundStatement.
 
     public BoundStatement(PreparedStatement statement) {
         this. = statement;
         this. = new ByteBuffer[statement.getVariables().size()];
 
         if (statement.getConsistencyLevel() != null)
             this.setConsistencyLevel(statement.getConsistencyLevel());
         if (statement.isTracing())
             this.enableTracing();
         if (statement.getRetryPolicy() != null)
             this.setRetryPolicy(statement.getRetryPolicy());
     }

    
Returns the prepared statement on which this BoundStatement is based.

Returns:
the prepared statement on which this BoundStatement is based.
 
     public PreparedStatement preparedStatement() {
         return ;
     }

    
Returns whether the ith variable has been bound to a non null value.

Parameters:
i the index of the variable to check.
Returns:
whether the ith variable has been bound to a non null value.
Throws:
java.lang.IndexOutOfBoundsException if i < 0 || i >= this.preparedStatement().variables().size().
 
     public boolean isSet(int i) {
         metadata().checkBounds(i);
         return [i] != null;
     }

    
Returns whether the first occurrence of variable name has been bound to a non-null value.

Parameters:
name the name of the variable to check.
Returns:
whether the first occurrence of variable name has been bound to a non-null value.
Throws:
java.lang.IllegalArgumentException if name is not a prepared variable, that is if !this.preparedStatement().variables().names().contains(name).
 
    public boolean isSet(String name) {
        return isSet(metadata().getIdx(name));
    }

    
Bound values to the variables of this statement. This is a convenience method to bind all the variables of the BoundStatement in one call.

Parameters:
values the values to bind to the variables of the newly created BoundStatement. The first element of values will be bound to the first bind variable, etc. It is legal to provide fewer values than the statement has bound variables. In that case, the remaining variable need to be bound before execution. If more values than variables are provided however, an IllegalArgumentException wil be raised.
Returns:
this bound statement.
Throws:
java.lang.IllegalArgumentException if more values are provided than there is of bound variables in this statement.
com.datastax.driver.core.exceptions.InvalidTypeException if any of the provided value is not of correct type to be bound to the corresponding bind variable.
java.lang.NullPointerException if one of values is a collection (List, Set or Map) containing a null value. Nulls are not supported in collections by CQL.
    public BoundStatement bind(Object... values) {
        if (values.length > .getVariables().size())
            throw new IllegalArgumentException(String.format("Prepared statement has only %d variables, %d values provided".getVariables().size(), values.length));
        for (int i = 0; i < values.lengthi++)
        {
            Object toSet = values[i];
            if (toSet == null) {
                setValue(inull);
                continue;
            }
            DataType columnType = .getVariables().getType(i);
            switch (columnType.getName()) {
                case :
                    if (!(toSet instanceof List))
                        throw new InvalidTypeException(String.format("Invalid type for value %d, column is a list but %s provided"itoSet.getClass()));
                    List<?> l = (List<?>)toSet;
                    // If the list is empty, it will never fail validation, but otherwise we should check the list given if of the right type
                    if (!l.isEmpty()) {
                        // Ugly? Yes
                        Class<?> providedClass = l.get(0).getClass();
                        Class<?> expectedClass = columnType.getTypeArguments().get(0).asJavaClass();
                        if (!expectedClass.isAssignableFrom(providedClass))
                            throw new InvalidTypeException(String.format("Invalid type for value %d of CQL type %s, expecting list of %s but provided list of %s"icolumnTypeexpectedClassprovidedClass));
                    }
                    break;
                case :
                    if (!(toSet instanceof Set))
                        throw new InvalidTypeException(String.format("Invalid type for value %d, column is a set but %s provided"itoSet.getClass()));
                    Set<?> s = (Set<?>)toSet;
                    // If the list is empty, it will never fail validation, but otherwise we should check the list given if of the right type
                    if (!s.isEmpty()) {
                        // Ugly? Yes
                        Class<?> providedClass = s.iterator().next().getClass();
                        Class<?> expectedClass = columnType.getTypeArguments().get(0).getName().;
                        if (!expectedClass.isAssignableFrom(providedClass))
                            throw new InvalidTypeException(String.format("Invalid type for value %d of CQL type %s, expecting set of %s but provided set of %s"icolumnTypeexpectedClassprovidedClass));
                    }
                    break;
                case :
                    if (!(toSet instanceof Map))
                        throw new InvalidTypeException(String.format("Invalid type for value %d, column is a map but %s provided"itoSet.getClass()));
                    Map<?, ?> m = (Map<?, ?>)toSet;
                    // If the list is empty, it will never fail validation, but otherwise we should check the list given if of the right type
                    if (!m.isEmpty()) {
                        // Ugly? Yes
                        Map.Entry<?, ?> entry = m.entrySet().iterator().next();
                        Class<?> providedKeysClass = entry.getKey().getClass();
                        Class<?> providedValuesClass = entry.getValue().getClass();
                        Class<?> expectedKeysClass = columnType.getTypeArguments().get(0).getName().;
                        Class<?> expectedValuesClass = columnType.getTypeArguments().get(1).getName().;
                        if (!expectedKeysClass.isAssignableFrom(providedKeysClass) || !expectedValuesClass.isAssignableFrom(providedValuesClass))
                            throw new InvalidTypeException(String.format("Invalid type for value %d of CQL type %s, expecting map of %s->%s but provided set of %s->%s"icolumnTypeexpectedKeysClassexpectedValuesClassprovidedKeysClassprovidedValuesClass));
                    }
                    break;
                default:
                    Class<?> providedClass = toSet.getClass();
                    Class<?> expectedClass = columnType.getName().;
                    if (!expectedClass.isAssignableFrom(providedClass))
                        throw new InvalidTypeException(String.format("Invalid type for value %d of CQL type %s, expecting %s but %s provided"icolumnTypeexpectedClassprovidedClass));
                    break;
            }
            setValue(i, Codec.getCodec(columnType).decompose(toSet));
        }
        return this;
    }

    
The routing key for this bound query.

This method will return a non-null value if either of the following occur:

  • All the columns composing the partition key are bound variables of this BoundStatement. The routing key will then be built using the values provided for these partition key columns.
  • The routing key has been set through PreparedStatement.setRoutingKey(java.nio.ByteBuffer[]) for the PreparedStatement this statement has been built from.
Otherwise, null is returned.

Note that if the routing key has been set through PreparedStatement.setRoutingKey(java.nio.ByteBuffer[]), that value takes precedence even if the partition key is part of the bound variables.

Returns:
the routing key for this statement or null.
    @Override
    public ByteBuffer getRoutingKey() {
        if (. != null)
            return .;
        if (. != null) {
            if (.. == 1) {
                return [.[0]];
            } else {
                ByteBuffer[] components = new ByteBuffer[..];
                for (int i = 0; i < components.length; ++i) {
                    ByteBuffer value = [.[i]];
                    if (value == null)
                        return null;
                    components[i] = value;
                }
                return SimpleStatement.compose(components);
            }
        }
        return null;
    }

    
Set the ith value to the provided boolean.

Parameters:
i the index of the variable to set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IndexOutOfBoundsException if i < 0 || i >= this.preparedStatement().variables().size().
com.datastax.driver.core.exceptions.InvalidTypeException if column i is not of type BOOLEAN.
    public BoundStatement setBool(int iboolean v) {
        metadata().checkType(i..);
        return setValue(i..decompose(v));
    }

    
Set the value for the first occurrence of column name to the provided boolean.

Parameters:
name the name of the variable to set; if multiple variables name are prepared, only the first one is set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IllegalArgumentException if name is not a prepared variable, that is, if !this.preparedStatement().variables().names().contains(name).
com.datastax.driver.core.exceptions.InvalidTypeException if column name is not of type BOOLEAN.
    public BoundStatement setBool(String nameboolean v) {
        return setBool(metadata().getIdx(name), v);
    }

    
Set the ith value to the provided integer.

Parameters:
i the index of the variable to set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IndexOutOfBoundsException if i < 0 || i >= this.preparedStatement().variables().size().
com.datastax.driver.core.exceptions.InvalidTypeException if column i is not of type INT.
    public BoundStatement setInt(int iint v) {
        metadata().checkType(i..);
        return setValue(i..decompose(v));
    }

    
Set the value for the first occurrence of column name to the provided integer.

Parameters:
name the name of the variable to set; if multiple variables name are prepared, only the first one is set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IllegalArgumentException if name is not a prepared variable, that is if !this.preparedStatement().variables().names().contains(name).
com.datastax.driver.core.exceptions.InvalidTypeException if column i is not of type INT.
    public BoundStatement setInt(String nameint v) {
        return setInt(metadata().getIdx(name), v);
    }

    
Set the ith value to the provided long.

Parameters:
i the index of the variable to set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IndexOutOfBoundsException if i < 0 || i >= this.preparedStatement().variables().size().
com.datastax.driver.core.exceptions.InvalidTypeException if column i is of type BIGINT or COUNTER.
    public BoundStatement setLong(int ilong v) {
        return setValue(i..decompose(v));
    }

    
Set the value for the first occurrence of column name to the provided long.

Parameters:
name the name of the variable to set; if multiple variables name are prepared, only the first one is set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IllegalArgumentException if name is not a prepared variable, that is if !this.preparedStatement().variables().names().contains(name).
com.datastax.driver.core.exceptions.InvalidTypeException if column i is of type BIGINT or COUNTER.
    public BoundStatement setLong(String namelong v) {
        return setLong(metadata().getIdx(name), v);
    }

    
Set the ith value to the provided date.

Parameters:
i the index of the variable to set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IndexOutOfBoundsException if i < 0 || i >= this.preparedStatement().variables().size().
com.datastax.driver.core.exceptions.InvalidTypeException if column i is not of type TIMESTAMP.
    public BoundStatement setDate(int iDate v) {
        metadata().checkType(i..);
        return setValue(iv == null ? null : ..decompose(v));
    }

    
Sets the value for the first occurrence of column name to the provided date.

Parameters:
name the name of the variable to set; if multiple variables name are prepared, only the first one is set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IllegalArgumentException if name is not a prepared variable, that is if !this.preparedStatement().variables().names().contains(name).
com.datastax.driver.core.exceptions.InvalidTypeException if column name is not of type TIMESTAMP.
    public BoundStatement setDate(String nameDate v) {
        return setDate(metadata().getIdx(name), v);
    }

    
Sets the ith value to the provided float.

Parameters:
i the index of the variable to set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IndexOutOfBoundsException if i < 0 || i >= this.preparedStatement().variables().size().
com.datastax.driver.core.exceptions.InvalidTypeException if column i is not of type FLOAT.
    public BoundStatement setFloat(int ifloat v) {
        metadata().checkType(i..);
        return setValue(i..decompose(v));
    }

    
Sets the value for the first occurrence of column name to the provided float.

Parameters:
name the name of the variable to set; if multiple variables name are prepared, only the first one is set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IllegalArgumentException if name is not a prepared variable, that is if !this.preparedStatement().variables().names().contains(name).
com.datastax.driver.core.exceptions.InvalidTypeException if column i is not of type FLOAT.
    public BoundStatement setFloat(String namefloat v) {
        return setFloat(metadata().getIdx(name), v);
    }

    
Sets the ith value to the provided double.

Parameters:
i the index of the variable to set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IndexOutOfBoundsException if i < 0 || i >= this.preparedStatement().variables().size().
com.datastax.driver.core.exceptions.InvalidTypeException if column i is not of type DOUBLE.
    public BoundStatement setDouble(int idouble v) {
        metadata().checkType(i..);
        return setValue(i..decompose(v));
    }

    
Sets the value for the first occurrence of column name to the provided double.

Parameters:
name the name of the variable to set; if multiple variables name are prepared, only the first one is set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IllegalArgumentException if name is not a prepared variable, that is if !this.preparedStatement().variables().names().contains(name).
com.datastax.driver.core.exceptions.InvalidTypeException if column i is not of type DOUBLE.
    public BoundStatement setDouble(String namedouble v) {
        return setDouble(metadata().getIdx(name), v);
    }

    
Sets the ith value to the provided string.

Parameters:
i the index of the variable to set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IndexOutOfBoundsException if i < 0 || i >= this.preparedStatement().variables().size().
com.datastax.driver.core.exceptions.InvalidTypeException if column i is of neither of the following types: VARCHAR, TEXT or ASCII.
    public BoundStatement setString(int iString v) {
        DataType.Name type = metadata().checkType(i..,
                                                     ..,
                                                     ..);
        switch (type) {
            case :
                return setValue(iv == null ? null : ..decompose(v));
            case :
            case :
                return setValue(iv == null ? null : ..decompose(v));
            default:
                throw new AssertionError();
        }
    }

    
Sets the value for the first occurrence of column name to the provided string.

Parameters:
name the name of the variable to set; if multiple variables name are prepared, only the first one is set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IllegalArgumentException if name is not a prepared variable, that is if !this.preparedStatement().variables().names().contains(name).
com.datastax.driver.core.exceptions.InvalidTypeException if column name is of neither of the following types: VARCHAR, TEXT or ASCII.
    public BoundStatement setString(String nameString v) {
        return setString(metadata().getIdx(name), v);
    }

    
Sets the ith value to the provided byte buffer. This method validate that the type of the column set is BLOB. If you want to insert manually serialized data into columns of another type, use setBytesUnsafe(int,java.nio.ByteBuffer) instead.

Parameters:
i the index of the variable to set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IndexOutOfBoundsException if i < 0 || i >= this.preparedStatement().variables().size().
com.datastax.driver.core.exceptions.InvalidTypeException if column i is not of type BLOB.
    public BoundStatement setBytes(int iByteBuffer v) {
        metadata().checkType(i..);
        return setBytesUnsafe(iv);
    }

    
Sets the value for the first occurrence of column name to the provided byte buffer. This method validate that the type of the column set is BLOB. If you want to insert manually serialized data into columns of another type, use setBytesUnsafe(int,java.nio.ByteBuffer) instead.

Parameters:
name the name of the variable to set; if multiple variables name are prepared, only the first one is set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IllegalArgumentException if name is not a prepared variable, that is if !this.preparedStatement().variables().names().contains(name).
com.datastax.driver.core.exceptions.InvalidTypeException if column name is not of type BLOB.
    public BoundStatement setBytes(String nameByteBuffer v) {
        return setBytes(metadata().getIdx(name), v);
    }

    
Sets the ith value to the provided byte buffer. Contrary to setBytes(int,java.nio.ByteBuffer), this method does not check the type of the column set. If you insert data that is not compatible with the type of the column, you will get an InvalidQueryException at execute time.

Parameters:
i the index of the variable to set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IndexOutOfBoundsException if i < 0 || i >= this.preparedStatement().variables().size().
    public BoundStatement setBytesUnsafe(int iByteBuffer v) {
        return setValue(iv == null ? null : v.duplicate());
    }

    
Sets the value for the first occurrence of column name to the provided byte buffer. Contrary to setBytes(int,java.nio.ByteBuffer), this method does not check the type of the column set. If you insert data that is not compatible with the type of the column, you will get an InvalidQueryException at execute time.

Parameters:
name the name of the variable to set; if multiple variables name are prepared, only the first one is set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IllegalArgumentException if name is not a prepared variable, that is if !this.preparedStatement().variables().names().contains(name).
    public BoundStatement setBytesUnsafe(String nameByteBuffer v) {
        return setBytesUnsafe(metadata().getIdx(name), v);
    }

    
Sets the ith value to the provided big integer.

Parameters:
i the index of the variable to set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IndexOutOfBoundsException if i < 0 || i >= this.preparedStatement().variables().size().
com.datastax.driver.core.exceptions.InvalidTypeException if column i is not of type VARINT.
    public BoundStatement setVarint(int iBigInteger v) {
        metadata().checkType(i..);
        return setValue(iv == null ? null : ..decompose(v));
    }

    
Sets the value for the first occurrence of column name to the provided big integer.

Parameters:
name the name of the variable to set; if multiple variables name are prepared, only the first one is set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IllegalArgumentException if name is not a prepared variable, that is if !this.preparedStatement().variables().names().contains(name).
com.datastax.driver.core.exceptions.InvalidTypeException if column name is not of type VARINT.
    public BoundStatement setVarint(String nameBigInteger v) {
        return setVarint(metadata().getIdx(name), v);
    }

    
Sets the ith value to the provided big decimal.

Parameters:
i the index of the variable to set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IndexOutOfBoundsException if i < 0 || i >= this.preparedStatement().variables().size().
com.datastax.driver.core.exceptions.InvalidTypeException if column i is not of type DECIMAL.
    public BoundStatement setDecimal(int iBigDecimal v) {
        metadata().checkType(i..);
        return setValue(iv == null ? null : ..decompose(v));
    }

    
Sets the value for the first occurrence of column name to the provided big decimal.

Parameters:
name the name of the variable to set; if multiple variables name are prepared, only the first one is set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IllegalArgumentException if name is not a prepared variable, that is if !this.preparedStatement().variables().names().contains(name).
com.datastax.driver.core.exceptions.InvalidTypeException if column name is not of type DECIMAL.
    public BoundStatement setDecimal(String nameBigDecimal v) {
        return setDecimal(metadata().getIdx(name), v);
    }

    
Sets the ith value to the provided UUID.

Parameters:
i the index of the variable to set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IndexOutOfBoundsException if i < 0 || i >= this.preparedStatement().variables().size().
com.datastax.driver.core.exceptions.InvalidTypeException if column i is not of type UUID or TIMEUUID, or if column i is of type TIMEUUID but v is not a type 1 UUID.
    public BoundStatement setUUID(int iUUID v) {
        DataType.Name type = metadata().checkType(i..,
                                                       ..);
        if (v == null)
            return setValue(inull);
        if (type == .. && v.version() != 1)
            throw new InvalidTypeException(String.format("%s is not a Type 1 (time-based) UUID"v));
        return type == ..
             ? setValue(i..decompose(v))
             : setValue(i..decompose(v));
    }

    
Sets the value for the first occurrence of column name to the provided UUID.

Parameters:
name the name of the variable to set; if multiple variables name are prepared, only the first one is set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IllegalArgumentException if name is not a prepared variable, that is if !this.preparedStatement().variables().names().contains(name).
com.datastax.driver.core.exceptions.InvalidTypeException if column name is not of type UUID or TIMEUUID, or if column name is of type TIMEUUID but v is not a type 1 UUID.
    public BoundStatement setUUID(String nameUUID v) {
        return setUUID(metadata().getIdx(name), v);
    }

    
Sets the ith value to the provided inet address.

Parameters:
i the index of the variable to set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IndexOutOfBoundsException if i < 0 || i >= this.preparedStatement().variables().size().
com.datastax.driver.core.exceptions.InvalidTypeException if column i is not of type INET.
    public BoundStatement setInet(int iInetAddress v) {
        metadata().checkType(i..);
        return setValue(iv == null ? null : ..decompose(v));
    }

    
Sets the value for the first occurrence of column name to the provided inet address.

Parameters:
name the name of the variable to set; if multiple variables name are prepared, only the first one is set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IllegalArgumentException if name is not a prepared variable, that is if !this.preparedStatement().variables().names().contains(name).
com.datastax.driver.core.exceptions.InvalidTypeException if column name is not of type INET.
    public BoundStatement setInet(String nameInetAddress v) {
        return setInet(metadata().getIdx(name), v);
    }

    
Sets the ith value to the provided list.

Please note that null values are not supported inside collection by CQL.

Parameters:
i the index of the variable to set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IndexOutOfBoundsException if i < 0 || i >= this.preparedStatement().variables().size().
com.datastax.driver.core.exceptions.InvalidTypeException if column i is not a list type or if the elements of v are not of the type of the elements of column i.
java.lang.NullPointerException if v contains null values. Nulls are not supported in collections by CQL.
    public <T> BoundStatement setList(int iList<T> v) {
        DataType type = metadata().getType(i);
        if (type.getName() != ..)
            throw new InvalidTypeException(String.format("Column %s is of type %s, cannot set to a list"metadata().getName(i), type));
        if (v == null)
            return setValue(inull);
        // If the list is empty, it will never fail validation, but otherwise we should check the list given if of the right type
        if (!v.isEmpty()) {
            // Ugly? Yes
            Class<?> providedClass = v.get(0).getClass();
            Class<?> expectedClass = type.getTypeArguments().get(0).asJavaClass();
            if (!expectedClass.isAssignableFrom(providedClass))
                throw new InvalidTypeException(String.format("Invalid value for column %s of CQL type %s, expecting list of %s but provided list of %s"metadata().getName(i), typeexpectedClassprovidedClass));
        }
        return setValue(i, Codec.<List<T>>getCodec(type).decompose(v));
    }

    
Sets the value for the first occurrence of column name to the provided list.

Please note that null values are not supported inside collection by CQL.

Parameters:
name the name of the variable to set; if multiple variables name are prepared, only the first one is set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IllegalArgumentException if name is not a prepared variable, that is if !this.preparedStatement().variables().names().contains(name).
com.datastax.driver.core.exceptions.InvalidTypeException if column name is not a list type or if the elements of v are not of the type of the elements of column name.
java.lang.NullPointerException if v contains null values. Nulls are not supported in collections by CQL.
    public <T> BoundStatement setList(String nameList<T> v) {
        return setList(metadata().getIdx(name), v);
    }

    
Sets the ith value to the provided map.

Please note that null values are not supported inside collection by CQL.

Parameters:
i the index of the variable to set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IndexOutOfBoundsException if i < 0 || i >= this.preparedStatement().variables().size().
com.datastax.driver.core.exceptions.InvalidTypeException if column i is not a map type or if the elements (keys or values) of v are not of the type of the elements of column i.
java.lang.NullPointerException if v contains null values. Nulls are not supported in collections by CQL.
    public <K, V> BoundStatement setMap(int iMap<K, V> v) {
        DataType type = metadata().getType(i);
        if (type.getName() != ..)
            throw new InvalidTypeException(String.format("Column %s is of type %s, cannot set to a map"metadata().getName(i), type));
        if (v == null)
            return setValue(inull);
        if (!v.isEmpty()) {
            // Ugly? Yes
            Map.Entry<K, V> entry = v.entrySet().iterator().next();
            Class<?> providedKeysClass = entry.getKey().getClass();
            Class<?> providedValuesClass = entry.getValue().getClass();
            Class<?> expectedKeysClass = type.getTypeArguments().get(0).getName().;
            Class<?> expectedValuesClass = type.getTypeArguments().get(1).getName().;
            if (!expectedKeysClass.isAssignableFrom(providedKeysClass) || !expectedValuesClass.isAssignableFrom(providedValuesClass))
                throw new InvalidTypeException(String.format("Invalid value for column %s of CQL type %s, expecting map of %s->%s but provided map of %s->%s"metadata().getName(i), typeexpectedKeysClassexpectedValuesClassprovidedKeysClassprovidedValuesClass));
        }
        return setValue(i, Codec.<Map<K, V>>getCodec(type).decompose(v));
    }

    
Sets the value for the first occurrence of column name to the provided map.

Please note that null values are not supported inside collection by CQL.

Parameters:
name the name of the variable to set; if multiple variables name are prepared, only the first one is set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IllegalArgumentException if name is not a prepared variable, that is if !this.preparedStatement().variables().names().contains(name).
com.datastax.driver.core.exceptions.InvalidTypeException if column name is not a map type or if the elements (keys or values) of v are not of the type of the elements of column name.
java.lang.NullPointerException if v contains null values. Nulls are not supported in collections by CQL.
    public <K, V> BoundStatement setMap(String nameMap<K, V> v) {
        return setMap(metadata().getIdx(name), v);
    }

    
Sets the ith value to the provided set.

Please note that null values are not supported inside collection by CQL.

Parameters:
i the index of the variable to set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IndexOutOfBoundsException if i < 0 || i >= this.preparedStatement().variables().size().
com.datastax.driver.core.exceptions.InvalidTypeException if column i is not a set type or if the elements of v are not of the type of the elements of column i.
java.lang.NullPointerException if v contains null values. Nulls are not supported in collections by CQL.
    public <T> BoundStatement setSet(int iSet<T> v) {
        DataType type = metadata().getType(i);
        if (type.getName() != ..)
            throw new InvalidTypeException(String.format("Column %s is of type %s, cannot set to a set"metadata().getName(i), type));
        if (v == null)
            return setValue(inull);
        if (!v.isEmpty()) {
            // Ugly? Yes
            Class<?> providedClass = v.iterator().next().getClass();
            Class<?> expectedClass = type.getTypeArguments().get(0).getName().;
            if (!expectedClass.isAssignableFrom(providedClass))
                throw new InvalidTypeException(String.format("Invalid value for column %s of CQL type %s, expecting set of %s but provided set of %s"metadata().getName(i), typeexpectedClassprovidedClass));
        }
        return setValue(i, Codec.<Set<T>>getCodec(type).decompose(v));
    }

    
Sets the value for the first occurrence of column name to the provided set.

Please note that null values are not supported inside collection by CQL.

Parameters:
name the name of the variable to set; if multiple variables name are prepared, only the first one is set.
v the value to set.
Returns:
this BoundStatement.
Throws:
java.lang.IllegalArgumentException if name is not a prepared variable, that is if !this.preparedStatement().variables().names().contains(name).
com.datastax.driver.core.exceptions.InvalidTypeException if column name is not a set type or if the elements of v are not of the type of the elements of column name.
java.lang.NullPointerException if v contains null values. Nulls are not supported in collections by CQL.
    public <T> BoundStatement setSet(String nameSet<T> v) {
        return setSet(metadata().getIdx(name), v);
    }
    private ColumnDefinitions metadata() {
        return .;
    }
    private BoundStatement setValue(int iByteBuffer value) {
        [i] = value;
        return this;
    }
New to GrepCode? Check out our FAQ X