All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alachisoft.ncache.client.internal.command.HashSetAddCommand Maven / Gradle / Ivy

package com.alachisoft.ncache.client.internal.command;

import Alachisoft.NCache.Common.Caching.UserBinaryObject;
import Alachisoft.NCache.Common.DataTypes.HashSet.HashSetAddOperation;
import Alachisoft.NCache.Common.JSON.ExtendedJsonValueBase;
import com.alachisoft.ncache.common.protobuf.CollectionItemProtocol;
import com.alachisoft.ncache.common.protobuf.HashSetAddProtocol;
import com.alachisoft.ncache.common.protobuf.HashSetCommandProtocol;
import com.alachisoft.ncache.runtime.exceptions.CommandException;
import com.google.protobuf.ByteString;

import java.nio.charset.StandardCharsets;
import java.util.Set;

public class HashSetAddCommand extends HashSetCommandBase {
    private Set _collection;
    private HashSetAddProtocol.HashSetAdd.Builder _hashSetAddBuilder;

    public HashSetAddCommand(HashSetAddOperation operation)
    {
        super.name = "HashSetAdd";
        super.key = operation.getName();
        _writeThruOption = operation.getWriteThruOptions();
        _lockId = (String)operation.getLockId();
        _lockTimeout = operation.getLockTimeout();
        _collection = operation.getCollection();
    }

    @Override
    public RequestType getCommandRequestType()
    {
        return RequestType.KeyBulkWrite;
    }

    @Override
    public CommandType getCommandType()
    {
        return CommandType.DATA_TYPE;
    }

    @Override
    protected void createCommand() throws CommandException {

        _hashSetAddBuilder = HashSetAddProtocol.HashSetAdd.newBuilder();

        for (ExtendedJsonValueBase value : _collection)
        {
            UserBinaryObject valueObject = UserBinaryObject.createUserBinaryObject(value.toJson().getBytes(StandardCharsets.UTF_8));
            CollectionItemProtocol.CollectionItem.Builder valueItemBuilder = CollectionItemProtocol.CollectionItem.newBuilder();
            for(byte[] bytes : valueObject.getDataList())
                valueItemBuilder.addData(ByteString.copyFrom(bytes));
            _hashSetAddBuilder.addValues(valueItemBuilder.build());
        }


        super.createCommand();

        _hashSetCommandBuilder.setType(HashSetCommandProtocol.HashSetCommand.Type.HASHSET_ADD);
        _hashSetCommandBuilder.setHashSetAdd(_hashSetAddBuilder);

    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy