Package com.datastax.driver.core.querybuilder

Examples of com.datastax.driver.core.querybuilder.Batch


        }
      };
    }

    String tableName = getTableName(entities.get(0).getClass()).toCql();
    Batch b = insert ? createInsertBatchQuery(tableName, entities, options, cassandraConverter)
        : createUpdateBatchQuery(tableName, entities, options, cassandraConverter);

    AsynchronousQueryListener aql = listener == null ? null : new AsynchronousQueryListener() {

      @Override
View Full Code Here


   * @return The Query object to run with session.execute();
   */
  public static <T> Batch createUpdateBatchQuery(String tableName, List<T> objectsToSave, WriteOptions options,
      EntityWriter<Object, Object> entityWriter) {

    Batch b = QueryBuilder.batch();

    for (T objectToSave : objectsToSave) {
      b.add(createUpdateQuery(tableName, objectToSave, options, entityWriter));
    }

    CqlTemplate.addQueryOptions(b, options);

    return b;
View Full Code Here

   * @return The Query object to run with session.execute();
   */
  public static <T> Batch createInsertBatchQuery(String tableName, List<T> entities, WriteOptions options,
      EntityWriter<Object, Object> entityWriter) {

    Batch batch = QueryBuilder.batch();

    for (T entity : entities) {
      batch.add(createInsertQuery(tableName, entity, options, entityWriter));
    }

    CqlTemplate.addQueryOptions(batch, options);

    return batch;
View Full Code Here

      EntityWriter<Object, Object> entityWriter) {

    Assert.notEmpty(entities);
    Assert.hasText(tableName);

    Batch batch = QueryBuilder.batch();

    for (T entity : entities) {
      batch.add(createDeleteQuery(tableName, entity, options, entityWriter));
    }

    CqlTemplate.addQueryOptions(batch, options);

    return batch;
View Full Code Here

        return new CqlBatchContext();
    }

    @Override
    public void applyBatch(BatchContext batchContext) {
        Batch batch = validateAndGetBatch(batchContext);
        List<Object> bindArguments = ((CqlBatchContext)batchContext).getBindArguments();
        if (bindArguments.isEmpty()) {
            session.execute(batch.getQueryString());
        } else {
            session.execute(session.prepare(batch.getQueryString()).bind(bindArguments.toArray()));
        }
        ((CqlBatchContext)batchContext).reset();
    }
View Full Code Here

    @Override
    public void writeToPath(K rowKey,
                            Path path,
                            Object structuredValue,
                            BatchContext batchContext) {
        Batch batch = validateAndGetBatch(batchContext);

        validateArgs(rowKey, path);
        Object simplifiedStructure = writeMapper.convertValue(structuredValue, Object.class);
        Map<Path,Object> pathMap = Collections.singletonMap(path, simplifiedStructure);
        Map<Path,Object> objectMap = Decomposer.get().decompose(pathMap);

        batch = batchContext == null ? batch() : batch;
        List<Object> bindArguments = batchContext == null ?
                                        new ArrayList<Object>() :
                                        ((CqlBatchContext)batchContext).getBindArguments();

        for (Map.Entry<Path,Object> entry : objectMap.entrySet()) {
            batch.add(insertStatement);

            String stringValue = StructureConverter.get().toString(entry.getValue());

            bindArguments.add(rowKey);
            bindArguments.add(entry.getKey().toString());
            bindArguments.add(stringValue);
        }

        if (batchContext == null) {
            session.execute(session.prepare(batch.getQueryString()).bind(bindArguments.toArray()));
        }
    }
View Full Code Here

        deletePath(rowKey, path, null);
    }

    @Override
    public void deletePath(K rowKey, Path path, BatchContext batchContext) {
        Batch batch = validateAndGetBatch(batchContext);

        validateArgs(rowKey, path);

        // converting from a string and back normalizes the path, e.g. makes sure ends with the delimiter character
        String start = path.toString();
        String finish = getFinishString(start);

        // would like to just do a delete with a where clause, but unfortunately Cassandra can't do that in CQL (either)
        // with >= and <=

        // Since the path column is in the primary key, we need to just delete whole rows.

        Object[] args = {rowKey,start,finish};
        ResultSet resultSet = session.execute(readForDeleteQuery.bind(args));
        if (resultSet.isExhausted()) {
            // not found
            return;
        }

        Delete deleteStatement = delete().from(tableName);
        deleteStatement
                .where(eq(partitionKeyColumnName, rowKey))
                .and(eq(pathColumnName, bindMarker()));

        batch = batchContext == null ? batch() : batch;
        List<Object> bindArguments = batchContext == null ?
                new ArrayList<Object>() :
                ((CqlBatchContext)batchContext).getBindArguments();

        for (Row row : resultSet) {
            String pathToDelete = row.getString(0);
            batch.add(deleteStatement);
            bindArguments.add(pathToDelete);
        }

        if (batchContext == null) {
          session.execute(session.prepare(batch.getQueryString()).bind(bindArguments.toArray()));
        }
    }
View Full Code Here

TOP

Related Classes of com.datastax.driver.core.querybuilder.Batch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.