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

org.apache.cassandra.cql.BatchStatement Maven / Gradle / Ivy

Go to download

A fork of the Apache Cassandra Project that uses Lucene indexes for providing near real time search such as ElasticSearch or Solr, including full text search capabilities, multi-dimensional queries, and relevance scoring.

The newest version!
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 org.apache.cassandra.cql;

import java.nio.ByteBuffer;
import java.util.LinkedList;
import java.util.List;

import org.apache.cassandra.db.IMutation;
import org.apache.cassandra.db.ConsistencyLevel;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.exceptions.UnauthorizedException;
import org.apache.cassandra.thrift.ThriftClientState;

/**
 * A BATCH statement parsed from a CQL query.
 *
 */
public class BatchStatement
{
    // statements to execute
    protected final List statements;

    // global consistency level
    protected final ConsistencyLevel consistency;

    // global timestamp to apply for each mutation
    protected final Long timestamp;

    // global time to live
    protected final int timeToLive;

    /**
     * Creates a new BatchStatement from a list of statements and a
     * Thrift consistency level.
     *
     * @param statements a list of UpdateStatements
     * @param attrs additional attributes for statement (CL, timestamp, timeToLive)
     */
    public BatchStatement(List statements, Attributes attrs)
    {
        this.statements = statements;
        this.consistency = attrs.getConsistencyLevel();
        this.timestamp = attrs.getTimestamp();
        this.timeToLive = attrs.getTimeToLive();
    }

    public List getStatements()
    {
        return statements;
    }

    public ConsistencyLevel getConsistencyLevel()
    {
        return consistency;
    }

    public int getTimeToLive()
    {
        return timeToLive;
    }

    public long getTimestamp()
    {
        return timestamp;
    }

    public List getMutations(String keyspace, ThriftClientState clientState, List variables)
    throws InvalidRequestException, UnauthorizedException
    {
        List batch = new LinkedList();

        for (AbstractModification statement : statements) {
            batch.addAll(statement.prepareRowMutations(keyspace, clientState, timestamp, variables));
        }

        return batch;
    }

    public boolean isSetTimestamp()
    {
        return timestamp != null;
    }

    public String toString()
    {
        return String.format("BatchStatement(statements=%s, consistency=%s)", statements, consistency);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy