Package com.datastax.driver.core

Examples of com.datastax.driver.core.BatchStatement$IdAndValues


                {
                    stmt = substmts.get(0);
                }
                else
                {
                    BatchStatement batch = new BatchStatement(batchType);
                    batch.setConsistencyLevel(JavaDriverClient.from(cl));
                    batch.addAll(substmts);
                    stmt = batch;
                }

                try
                {
View Full Code Here


    @Test(expected = InvalidQueryException.class)
    public void testOversizedBatch()
    {
        int SIZE_FOR_FAILURE = 2500;
        BatchStatement b = new BatchStatement(BatchStatement.Type.UNLOGGED);
        for (int i = 0; i < SIZE_FOR_FAILURE; i++)
        {
            b.add(noncounter.bind(i, "foobar"));
        }
        session.execute(b);
    }
View Full Code Here

    public void sendBatch(BatchStatement.Type type, boolean addCounter, boolean addNonCounter)
    {

        assert addCounter || addNonCounter;
        BatchStatement b = new BatchStatement(type);

        for (int i = 0; i < 10; i++)
        {
            if (addNonCounter)
                b.add(noncounter.bind(i, "foo"));

            if (addCounter)
                b.add(counter.bind((long)i, i));
        }

        session.execute(b);
    }
View Full Code Here

        if (statements.size() > 0) {
          final Statement statement;
          if (statements.size() == 1) {
            statement = statements.get(0);
          } else {
            statement = new BatchStatement(Type.UNLOGGED).addAll(statements);
          }

          futures.add(mTable.getAdmin().executeAsync(statement));
        }
      }
View Full Code Here

      Preconditions.checkState(mStatements.size() > 0, "No transactions to commit.");

      final Statement statement;
      if (mStatements.size() > 1) {
        statement = new BatchStatement(BatchStatement.Type.UNLOGGED).addAll(mStatements);
      } else {
        statement = mStatements.get(0);
      }

      ResultSet result = mTable.getAdmin().execute(statement);
View Full Code Here

                {
                    stmt = stmts.get(0);
                }
                else
                {
                    BatchStatement batch = new BatchStatement(batchType);
                    batch.setConsistencyLevel(JavaDriverClient.from(cl));
                    batch.addAll(stmts);
                    stmt = batch;
                }
                validate(client.getSession().execute(stmt));

            } while (!done);
View Full Code Here

    public void sendBatch(BatchStatement.Type type, boolean addCounter, boolean addNonCounter)
    {

        assert addCounter || addNonCounter;
        BatchStatement b = new BatchStatement(type);

        for (int i = 0; i < 10; i++)
        {
            if (addNonCounter)
                b.add(noncounter.bind(i, "foo"));

            if (addCounter)
                b.add(counter.bind((long)i, i));
        }

        session.execute(b);
    }
View Full Code Here

            RegularStatement rstmt = (RegularStatement) statement;
            queryKeyspace = rstmt.getKeyspace();
            queryString = rstmt.getQueryString();
        }
        else if (statement instanceof BatchStatement) {
            BatchStatement bstmt = (BatchStatement) statement;
            bstmt.getKeyspace();
            StringBuilder qs = new StringBuilder("\n");
            for (Statement st : bstmt.getStatements()) {
                String q;
                if (st instanceof BoundStatement)
                    q = ((BoundStatement)st).preparedStatement().getQueryString();
                else if (st instanceof RegularStatement)
                    q = ((RegularStatement)st).getQueryString();
View Full Code Here

        persistOptions = withTTL(persistOptions);

        Session session = persistenceSession.driverSession();

        BatchStatement batch = new BatchStatement();

        //TODO adding a DELETE...WHERE partitionKey=? in front of INSERTs for the same partition key results in no insert at all *SICK*
        //Binder binder = new Binder(null, true, partitionKeyColumns, PersistMode.DELETE);
        //buildModifyBindColumns(instance, binder, partitionAttributes);
        //BoundStatement bStmt = buildModifyInitial(session, persistOptions, PreparedStatements.StatementType.DELETE, binder);
        //batch.add(bStmt);

        // INSERT INTO keyspace_name.table_name
        // ( column_name, column_name...)
        // VALUES ( value, value ... )
        // IF NOT EXISTS
        // USING option AND option
        boolean serializeDefault = PersistOption.WriteDefaultValueOption.get(persistOptions, writeNullOnInsert);
        CqlColumn[] columns = PersistOption.ColumnRestrictionOption.filter(persistOptions, writeDataColumns);
        Binder binder = new Binder(columns, true, primaryKeyColumns, PersistMode.INSERT, serializeDefault);

        int protocolVersion = persistenceSession.persistenceManager.protocolVersion;

        for (Map.Entry entry : instance.getCluster().entrySet()) {
            binder.reset();

            buildModifyBindColumns(instance, binder, partitionAttributes);
            if (clusteringColumn != null) {
                binder.setBytesUnsafe(clusteringColumn, clusteringPrimitive.serialize(entry.getKey(), protocolVersion));
            } else {
                buildModifyBindColumns(entry.getKey(), binder, clusteringKeyAttributes);
            }
            if (valueColumn != null) {
                binder.setBytesUnsafe(valueColumn, valuePrimitive.serialize(entry.getValue(), protocolVersion));
            } else {
                buildModifyBindColumns(entry.getValue(), binder, valueAttributes);
            }

            BoundStatement bStmt = buildModifyInitial(session, persistOptions, PreparedStatements.StatementType.INSERT, binder);
            int idx = binder.bindColumns(0, bStmt);
            bindUsingOptions(bStmt, persistOptions, idx);
            statementOptions.applyWrite(bStmt, writeConsistencyLevel, serialConsistencyLevel, persistOptions);

            if (prePersist != null) {
                prePersist.invoke(instance, this, type, bStmt);
            }

            batch.add(bStmt);
        }

        // TODO reset MapEntity only if batch was successful
        instance.reset();

View Full Code Here

        persistOptions = withTTL(persistOptions);

        Session session = persistenceSession.driverSession();

        BatchStatement batch = new BatchStatement();

        Set removed = instance.getRemoved();
        if (!removed.isEmpty()) {
            int protocolVersion = persistenceSession.persistenceManager.protocolVersion;

            Binder binder = new Binder(null, true, primaryKeyColumns, PersistMode.DELETE, true);
            for (Object key : removed) {
                binder.reset();

                buildModifyBindColumns(instance, binder, partitionAttributes);
                if (clusteringColumn != null) {
                    binder.setBytesUnsafe(clusteringColumn, clusteringPrimitive.serialize(key, protocolVersion));
                } else {
                    buildModifyBindColumns(key, binder, clusteringKeyAttributes);
                }
            }

            BoundStatement bStmt = buildModifyInitial(session, persistOptions, PreparedStatements.StatementType.DELETE, binder);
            int idx = binder.bindColumns(0, bStmt);
            bindUsingOptions(bStmt, persistOptions, idx);
            statementOptions.applyWrite(bStmt, writeConsistencyLevel, serialConsistencyLevel, persistOptions);

            if (prePersist != null) {
                prePersist.invoke(instance, this, type, bStmt);
            }

            batch.add(bStmt);
        }

        // UPDATE keyspace_name.table_name
        // USING option AND option
        // SET assignment , assignment, ...
        // WHERE row_specification
        // IF column_name = literal AND column_name = literal . . .

        int protocolVersion = persistenceSession.persistenceManager.protocolVersion;

        CqlColumn[] columns = PersistOption.ColumnRestrictionOption.filter(persistOptions, writeDataColumns);
        Binder binder = new Binder(columns, true, primaryKeyColumns, PersistMode.UPDATE, true);
        for (Map.Entry entry : instance.getCluster().entrySet()) {
            binder.reset();

            buildModifyBindColumns(instance, binder, partitionAttributes);
            if (clusteringColumn != null) {
                binder.setBytesUnsafe(clusteringColumn, clusteringPrimitive.serialize(entry.getKey(), protocolVersion));
            } else {
                buildModifyBindColumns(entry.getKey(), binder, clusteringKeyAttributes);
            }
            if (valueColumn != null) {
                binder.setBytesUnsafe(valueColumn, valuePrimitive.serialize(entry.getValue(), protocolVersion));
            } else {
                buildModifyBindColumns(entry.getValue(), binder, valueAttributes);
            }

            BoundStatement bStmt = buildModifyInitial(session, persistOptions, PreparedStatements.StatementType.UPDATE, binder);
            int idx = bindUsingOptions(bStmt, persistOptions, 0);
            idx = binder.bindColumns(idx, bStmt);
            bindIfOptions(binder, bStmt, persistOptions, idx);
            statementOptions.applyWrite(bStmt, writeConsistencyLevel, serialConsistencyLevel, persistOptions);

            if (prePersist != null) {
                prePersist.invoke(instance, this, type, bStmt);
            }

            batch.add(bStmt);
        }

        // TODO reset MapEntity only if batch was successful
        instance.reset();
View Full Code Here

TOP

Related Classes of com.datastax.driver.core.BatchStatement$IdAndValues

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.