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.querybuilder;
 
 import java.util.List;
 
A built UPDATE statement.
 
 public class Update extends BuiltStatement {
 
     private final String keyspace;
     private final String table;
     private final Assignments assignments;
     private final Where where;
     private final Options usings;
 
     Update(String keyspaceString table) {
         super();
         this. = keyspace;
         this. = table;
         this. = new Assignments(this);
         this. = new Where(this);
         this. = new Options(this);
     }
 
     Update(TableMetadata table) {
         super(table);
         this. = table.getKeyspace().getName();
         this. = table.getName();
         this. = new Assignments(this);
         this. = new Where(this);
         this. = new Options(this);
     }
 
     @Override
     protected StringBuilder buildQueryString() {
         StringBuilder builder = new StringBuilder();
 
         builder.append("UPDATE ");
         if ( != null)
             Utils.appendName(builder).append(".");
         Utils.appendName(builder);
 
         if (!..isEmpty()) {
             builder.append(" USING ");
             Utils.joinAndAppend(builder" AND ".);
         }
 
         if (!..isEmpty()) {
             builder.append(" SET ");
             Utils.joinAndAppend(builder",".);
         }
 
         if (!..isEmpty()) {
             builder.append(" WHERE ");
             Utils.joinAndAppend(builder" AND ".);
         }
 
         return builder;
     }

    
Adds an assignment to this UPDATE statement. This is a shorter/more readable version for with().and(assignment).

Parameters:
assignment the assignment to add.
Returns:
the Assignments of this UPDATE statement.
 
     public Assignments with(Assignment assignment) {
         return .and(assignment);
     }

    
Returns the assignments of this UPDATE statement.

Returns:
the assignments of this UPDATE statement.
 
     public Assignments with() {
         return ;
     }

    
Adds a WHERE clause to this statement. This is a shorter/more readable version for where().and(clause).

Parameters:
clause the clause to add.
Returns:
the where clause of this query to which more clause can be added.
    public Where where(Clause clause) {
        return .and(clause);
    }

    
Returns a Where statement for this query without adding clause.

Returns:
the where clause of this query to which more clause can be added.
    public Where where() {
        return ;
    }

    
Adds a new options for this UPDATE statement.

Parameters:
using the option to add.
Returns:
the options of this UPDATE statement.
    public Options using(Using using) {
        return .and(using);
    }

    
The assignments of an UPDATE statement.
    public static class Assignments extends BuiltStatement.ForwardingStatement<Update> {
        private final List<Assignmentassignments = new ArrayList<Assignment>();
        Assignments(Update statement) {
            super(statement);
        }

        
Adds a new assignment for this UPDATE statement.

Parameters:
assignment the new Assignment to add.
Returns:
these Assignments.
        public Assignments and(Assignment assignment) {
            .setCounterOp(assignment instanceof CounterAssignment);
            .add(assignment);
            setDirty();
            return this;
        }

        
Adds a where clause to the UPDATE statement those assignments are part of.

Parameters:
clause the clause to add.
Returns:
the where clause of the UPDATE statement those assignments are part of.
        public Where where(Clause clause) {
            return .where(clause);
        }

        
Adds an option to the UPDATE statement those assignments are part of.

Parameters:
using the using clause to add.
Returns:
the options of the UPDATE statement those assignments are part of.
        public Options using(Using using) {
            return .using(using);
        }
    }

    
The WHERE clause of an UPDATE statement.
    public static class Where extends BuiltStatement.ForwardingStatement<Update> {
        private final List<Clauseclauses = new ArrayList<Clause>();
        Where(Update statement) {
            super(statement);
        }

        
Adds the provided clause to this WHERE clause.

Parameters:
clause the clause to add.
Returns:
this WHERE clause.
        public Where and(Clause clause)
        {
            .add(clause);
            .maybeAddRoutingKey(clause.name(), clause.firstValue());
            setDirty();
            return this;
        }

        
Adds an assignment to the UPDATE statement this WHERE clause is part of.

Parameters:
assignment the assignment to add.
Returns:
the assignments of the UPDATE statement this WHERE clause is part of.
        public Assignments with(Assignment assignment) {
            return .with(assignment);
        }

        
Adds an option to the UPDATE statement this WHERE clause is part of.

Parameters:
using the using clause to add.
Returns:
the options of the UPDATE statement this WHERE clause is part of.
        public Options using(Using using) {
            return .using(using);
        }
    }

    
The options of a UDPATE statement.
    public static class Options extends BuiltStatement.ForwardingStatement<Update> {
        private final List<Usingusings = new ArrayList<Using>();
        Options(Update statement) {
            super(statement);
        }

        
Adds the provided option.

Parameters:
using an UPDATE option.
Returns:
this Options object.
        public Options and(Using using) {
            .add(using);
            setDirty();
            return this;
        }

        
Adds an assignment to the UPDATE statement those options are part of.

Parameters:
assignment the assignment to add.
Returns:
the assignments of the UPDATE statement those options are part of.
        public Assignments with(Assignment assignment) {
            return .with(assignment);
        }

        
Adds a where clause to the UPDATE statement these options are part of.

Parameters:
clause clause to add.
Returns:
the WHERE clause of the UPDATE statement these options are part of.
        public Where where(Clause clause) {
            return .where(clause);
        }
    }
New to GrepCode? Check out our FAQ X