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

com.aerospike.documentapi.pathparts.MapPathPart Maven / Gradle / Ivy

Go to download

This project provides an API which allows Aerospike CDT (Collection Data Type) objects to be accessed and mutated using JSON like syntax. Effectively this provides what can be termed a document API as CDT objects can be used to represent JSON in the Aerospike database.

There is a newer version: 2.0.3
Show newest version
package com.aerospike.documentapi.pathparts;

import com.aerospike.client.Operation;
import com.aerospike.client.Value;
import com.aerospike.client.cdt.CTX;
import com.aerospike.client.cdt.MapOperation;
import com.aerospike.client.cdt.MapPolicy;
import com.aerospike.client.cdt.MapReturnType;

import java.util.Objects;

/**
 * MapPart is a representation of key access
 */
public class MapPathPart extends PathPart {

    private final String key;

    public MapPathPart(String key) {
        this.key = key;
    }

    public String getKey() {
        return key;
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(key);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof MapPathPart)) {
            return false;
        }
        MapPathPart that = (MapPathPart) obj;
        return key.equals(that.key);
    }

    @Override
    public CTX toAerospikeContext() {
        return CTX.mapKey(Value.get(key));
    }

    @Override
    public Operation toAerospikeGetOperation(String binName, CTX[] contexts) {
        return MapOperation.getByKey(binName, Value.get(key), MapReturnType.VALUE, contexts);
    }

    @Override
    public Operation toAerospikePutOperation(String binName, Object object, CTX[] contexts) {
        return MapOperation.put(new MapPolicy(), binName, Value.get(key), Value.get(object), contexts);
    }

    @Override
    public Operation toAerospikeDeleteOperation(String binName, CTX[] contexts) {
        return MapOperation.removeByKey(binName, Value.get(key), MapReturnType.NONE, contexts);
    }

    @Override
    public PathPartTypeEnum getType() {
        return PathPartTypeEnum.MAP;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy