Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *      Copyright (C) 2012-2014 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.mapping;
 
 import java.util.*;
 
 
 import static com.datastax.driver.core.querybuilder.QueryBuilder.*;
 
 class QueryType {
 
     private enum Kind { SAVE, GET, DEL, SLICE, REVERSED_SLICE };
     private final Kind kind;
 
     // For slices
     private final int startBoundSize;
     private final boolean startInclusive;
     private final int endBoundSize;
     private final boolean endInclusive;
 
     public static final QueryType SAVE = new QueryType(.);
     public static final QueryType DEL = new QueryType(.);
     public static final QueryType GET = new QueryType(.);
 
     private QueryType(Kind kind) {
         this(kind, 0, false, 0, false);
     }
 
     private QueryType(Kind kindint startBoundSizeboolean startInclusiveint endBoundSizeboolean endInclusive) {
         this. = kind;
         this. = startBoundSize;
         this. = startInclusive;
         this. = endBoundSize;
         this. = endInclusive;
     }
 
     public static QueryType slice(int startBoundSizeboolean startInclusiveint endBoundSizeboolean endInclusiveboolean reversed) {
         return new QueryType(reversed ? . : .startBoundSizestartInclusiveendBoundSizeendInclusive);
     }
 
     String makePreparedQueryString(TableMetadata tableEntityMapper<?> mapper) {
         switch () {
             case :
                 {
                     Insert insert = table == null
                                   ? insertInto(mapper.getKeyspace(), mapper.getTable())
                                   : insertInto(table);
                     for (ColumnMapper<?> cm : mapper.allColumns())
                         insert.value(cm.getColumnName(), bindMarker());
                     return insert.toString();
                 }
             case :
                 {
                     Select select = table == null
                                   ? select().all().from(mapper.getKeyspace(), mapper.getTable())
                                   : select().all().from(table);
                     Select.Where where = select.where();
                     for (int i = 0; i < mapper.primaryKeySize(); i++)
                         where.and(eq(mapper.getPrimaryKeyColumn(i).getColumnName(), bindMarker()));
                     return select.toString();
                 }
             case :
                 {
                     Delete delete = table == null
                                   ? delete().all().from(mapper.getKeyspace(), mapper.getTable())
                                   : delete().all().from(table);
                     Delete.Where where = delete.where();
                     for (int i = 0; i < mapper.primaryKeySize(); i++)
                         where.and(eq(mapper.getPrimaryKeyColumn(i).getColumnName(), bindMarker()));
                     return delete.toString();
                 }
             case :
             case :
                 {
                     Select select = table == null
                                   ? select().all().from(mapper.getKeyspace(), mapper.getTable())
                                   : select().all().from(table);
                     Select.Where where = select.where();
                     for (int i = 0; i < mapper.partitionKeys.size(); i++)
                         where.and(eq(mapper.partitionKeys.get(i).getColumnName(), bindMarker()));
 
                    if ( > 0) {
                        if ( == 1) {
                            String name = mapper.clusteringColumns.get(0).getColumnName();
                            where.and( ? gte(namebindMarker()) : gt(namebindMarker()));
                        } else {
                            List<Stringnames = new ArrayList<String>();
                            List<Objectvalues = new ArrayList<Object>();
                            for (int i = 0; i < i++) {
                                names.add(mapper.clusteringColumns.get(i).getColumnName());
                                values.add(bindMarker());
                            }
                            where.and( ? gte(namesvalues) : gt(namesvalues));
                        }
                    }
                    if ( > 0) {
                        if ( == 1) {
                            String name = mapper.clusteringColumns.get(0).getColumnName();
                            where.and( ? gte(namebindMarker()) : gt(namebindMarker()));
                        } else {
                            List<Stringnames = new ArrayList<String>();
                            List<Objectvalues = new ArrayList<Object>();
                            for (int i = 0; i < i++) {
                                names.add(mapper.clusteringColumns.get(i).getColumnName());
                                values.add(bindMarker());
                            }
                            where.and( ? lte(namesvalues) : lt(namesvalues));
                        }
                    }
                    select = select.limit(bindMarker());
                    if ( == .)
                        select = select.orderBy(desc(mapper.clusteringColumns.get(0).getColumnName()));
                    return select.toString();
                }
        }
        throw new AssertionError();
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null || this.getClass() != obj.getClass())
            return false;
        QueryType that = (QueryType)obj;
        return  == that.kind
            &&  == that.startBoundSize
            &&  == that.startInclusive
            &&  == that.endBoundSize
            &&  == that.endInclusive;
    }
    @Override
    public int hashCode() {
        return Objects.hashCode();
    }
New to GrepCode? Check out our FAQ X