Package org.apache.cassandra.db

Examples of org.apache.cassandra.db.RowMutation


    }

    public RowMutation mutationForKey(ByteBuffer key, String keyspace, Long timestamp, ClientState clientState, List<ByteBuffer> variables)
    throws InvalidRequestException
    {
        RowMutation rm = new RowMutation(keyspace, key);

        CFMetaData metadata = validateColumnFamily(keyspace, columnFamily);
        QueryProcessor.validateKeyAlias(metadata, keyName);

        AbstractType<?> comparator = metadata.getComparatorFor(null);

        if (columns.size() < 1)
        {
            // No columns, delete the row
            rm.delete(new QueryPath(columnFamily), (timestamp == null) ? getTimestamp(clientState) : timestamp);
        }
        else
        {
            // Delete specific columns
            for (Term column : columns)
            {
                ByteBuffer columnName = column.getByteBuffer(comparator, variables);
                validateColumnName(columnName);
                rm.delete(new QueryPath(columnFamily, null, columnName), (timestamp == null) ? getTimestamp(clientState) : timestamp);
            }
        }

        return rm;
    }
View Full Code Here


    }

    public RowMutation mutationForKey(CFDefinition cfDef, ClientState clientState, ByteBuffer key, ColumnNameBuilder builder, List<ByteBuffer> variables)
    throws InvalidRequestException
    {
        RowMutation rm = new RowMutation(cfDef.cfm.ksName, key);

        if (columns.isEmpty() && builder.componentCount() == 0)
        {
            // No columns, delete the row
            rm.delete(new QueryPath(columnFamily()), getTimestamp(clientState));
        }
        else
        {
            for (ColumnIdentifier column : columns)
            {
                CFDefinition.Name name = cfDef.get(column);
                if (name == null)
                    throw new InvalidRequestException(String.format("Unknown identifier %s", column));

                // For compact, we only have one value except the key, so the only form of DELETE that make sense is without a column
                // list. However, we support having the value name for coherence with the static/sparse case
                if (name.kind != CFDefinition.Name.Kind.COLUMN_METADATA && name.kind != CFDefinition.Name.Kind.VALUE_ALIAS)
                    throw new InvalidRequestException(String.format("Invalid identifier %s for deletion (should not be a PRIMARY KEY part)", column));
            }

            if (cfDef.isCompact)
            {
                    ByteBuffer columnName = builder.build();
                    QueryProcessor.validateColumnName(columnName);
                    rm.delete(new QueryPath(columnFamily(), null, columnName), getTimestamp(clientState));
            }
            else
            {
                // Delete specific columns
                Iterator<ColumnIdentifier> iter = columns.iterator();
                while (iter.hasNext())
                {
                    ColumnIdentifier column = iter.next();
                    ColumnNameBuilder b = iter.hasNext() ? builder.copy() : builder;
                    ByteBuffer columnName = b.add(column.key).build();
                    QueryProcessor.validateColumnName(columnName);
                    rm.delete(new QueryPath(columnFamily(), null, columnName), getTimestamp(clientState));
                }
            }
        }

        return rm;
View Full Code Here

    {
        AbstractType<?> comparator = getComparator(keyspace);

        // if true we need to wrap RowMutation into CounterMutation
        boolean hasCounterColumn = false;
        RowMutation rm = new RowMutation(keyspace, key);

        for (Map.Entry<Term, Operation> column : getColumns().entrySet())
        {
            ByteBuffer colName = column.getKey().getByteBuffer(comparator, variables);
            Operation op = column.getValue();

            if (op.isUnary())
            {
                if (hasCounterColumn)
                    throw new InvalidRequestException("Mix of commutative and non-commutative operations is not allowed.");

                ByteBuffer colValue = op.a.getByteBuffer(getValueValidator(keyspace, colName),variables);

                validateColumn(metadata, colName, colValue);
                rm.add(new QueryPath(columnFamily, null, colName),
                       colValue,
                       (timestamp == null) ? getTimestamp(clientState) : timestamp,
                       getTimeToLive());
            }
            else
            {
                hasCounterColumn = true;

                if (!column.getKey().getText().equals(op.a.getText()))
                    throw new InvalidRequestException("Only expressions like X = X + <long> are supported.");

                long value;

                try
                {
                    value = Long.parseLong(op.b.getText());
                }
                catch (NumberFormatException e)
                {
                    throw new InvalidRequestException(String.format("'%s' is an invalid value, should be a long.",
                                                      op.b.getText()));
                }

                rm.addCounter(new QueryPath(columnFamily, null, colName), value);
            }
        }

        return (hasCounterColumn) ? new CounterMutation(rm, getConsistencyLevel()) : rm;
    }
View Full Code Here

    private IMutation mutationForKey(CFDefinition cfDef, ClientState clientState, ByteBuffer key, ColumnNameBuilder builder, List<ByteBuffer> variables)
    throws InvalidRequestException
    {
        // if true we need to wrap RowMutation into CounterMutation
        boolean hasCounterColumn = false;
        RowMutation rm = new RowMutation(cfDef.cfm.ksName, key);

        if (cfDef.isCompact)
        {
            if (builder.componentCount() == 0)
                throw new InvalidRequestException(String.format("Missing PRIMARY KEY part %s", cfDef.columns.values().iterator().next()));
View Full Code Here

    /* Migration Helper implementations */

    private static void addKeyspace(KSMetaData ksm, long timestamp, boolean withSchemaRecord) throws ConfigurationException, IOException
    {
        RowMutation keyspaceDef = ksm.toSchema(timestamp);

        if (withSchemaRecord)
            keyspaceDef.apply();

        Schema.instance.load(ksm);

        if (!StorageService.instance.isClientMode())
            Table.open(ksm.name);
View Full Code Here

    {
        KSMetaData oldKsm = Schema.instance.getKSMetaData(newState.name);

        if (withSchemaRecord)
        {
            RowMutation schemaUpdate = oldKsm.diff(newState, timestamp);
            schemaUpdate.apply();
        }

        KSMetaData newKsm = KSMetaData.cloneWith(oldKsm.reloadAttributes(), oldKsm.cfMetaData().values());

        Schema.instance.setTableDefinition(newKsm);
View Full Code Here

    {
        CFMetaData cfm = Schema.instance.getCFMetaData(newState.keyspace, newState.name);

        if (withSchemaRecord)
        {
            RowMutation schemaUpdate = cfm.diff(newState, timestamp);
            schemaUpdate.apply();
        }

        cfm.reload();

        if (!StorageService.instance.isClientMode())
View Full Code Here

    {
        // Test thrift conversion
        assert cfm.equals(CFMetaData.fromThrift(cfm.toThrift())) : String.format("\n%s\n!=\n%s", cfm, CFMetaData.fromThrift(cfm.toThrift()));

        // Test schema conversion
        RowMutation rm = cfm.toSchema(System.currentTimeMillis());
        ColumnFamily serializedCf = rm.getColumnFamily(Schema.instance.getId(Table.SYSTEM_TABLE, SystemTable.SCHEMA_COLUMNFAMILIES_CF));
        ColumnFamily serializedCD = rm.getColumnFamily(Schema.instance.getId(Table.SYSTEM_TABLE, SystemTable.SCHEMA_COLUMNS_CF));
        CfDef cfDef = CFMetaData.addColumnDefinitionSchema(CFMetaData.fromSchema(serializedCf), serializedCD);
        assert cfm.equals(CFMetaData.fromThrift(cfDef)) : String.format("\n%s\n!=\n%s", cfm, CFMetaData.fromThrift(cfDef));
    }
View Full Code Here

                if (expiredCallbackInfo.shouldHint())
                {
                    assert expiredCallbackInfo.message != null;
                    try
                    {
                        RowMutation rm = RowMutation.fromBytes(expiredCallbackInfo.message.getMessageBody(), expiredCallbackInfo.message.getVersion());
                        return StorageProxy.scheduleLocalHint(rm, expiredCallbackInfo.target, null, null);
                    }
                    catch (IOException e)
                    {
                        logger_.error("Unable to deserialize mutation when writting hint for: " + expiredCallbackInfo.target);
View Full Code Here

                ColumnFamily cf = ColumnFamily.create(cfMeta);
                Tracing.addColumn(cf, Tracing.buildName(cfMeta, eventId, ByteBufferUtil.bytes("source")), FBUtilities.getBroadcastAddress());
                Tracing.addColumn(cf, Tracing.buildName(cfMeta, eventId, ByteBufferUtil.bytes("thread")), threadName);
                Tracing.addColumn(cf, Tracing.buildName(cfMeta, eventId, ByteBufferUtil.bytes("source_elapsed")), elapsed);
                Tracing.addColumn(cf, Tracing.buildName(cfMeta, eventId, ByteBufferUtil.bytes("activity")), message);
                RowMutation mutation = new RowMutation(Tracing.TRACE_KS, sessionIdBytes);
                mutation.add(cf);
                StorageProxy.mutate(Arrays.asList(mutation), ConsistencyLevel.ANY);
            }
        });
    }
View Full Code Here

TOP

Related Classes of org.apache.cassandra.db.RowMutation

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.