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

com.backendless.hive.HiveMap Maven / Gradle / Ivy

The newest version!
package com.backendless.hive;

import com.backendless.core.responder.AdaptingResponder;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;


public final class HiveMap extends HiveGeneralForComplexStore
{
  public final static String HIVE_MAP_ALIAS = "com.backendless.services.hive.HiveMapService";

  HiveMap( String hiveName, String storeKey )
  {
    super( hiveName, StoreType.Map, storeKey );
  }


  public CompletableFuture> get()
  {
    return this.>makeRemoteCall( "get" )
            .thenApply( HiveSerializer::deserialize );
  }

  public CompletableFuture get( String objKey )
  {
    return this.makeRemoteCall( "get", objKey )
            .thenApply( HiveSerializer::deserialize );
  }

  public CompletableFuture> get( List objKeys )
  {
    return this.>makeRemoteCall( "multiGet", objKeys )
            .thenApply( HiveSerializer::deserialize );
  }

  public CompletableFuture> keys()
  {
    return makeRemoteCall( "getKeys", new AdaptingResponder<>( List.class ) )
            .thenApply( result -> (List) result );
  }

  public CompletableFuture> values()
  {
    return this.makeRemoteCall( "getValues" )
            .thenApply( HiveSerializer::deserializeAsList );
  }

  public CompletableFuture set( Map values )
  {
    return makeRemoteCall( "set", new AdaptingResponder<>( Long.class ), HiveSerializer.serializeAsMap( values ) );
  }

  private CompletableFuture set( String objKey, T value )
  {
    return makeRemoteCall( "set", objKey, HiveSerializer.serialize( value ) );
  }

  private CompletableFuture setIfNotExist( String objKey, T value )
  {
    return makeRemoteCall( "setIfNotExist", objKey, HiveSerializer.serialize( value ) );
  }

  public CompletableFuture set( String objKey, T value, boolean overwrite )
  {
    if( overwrite )
      return set( objKey, value );
    else
      return setIfNotExist( objKey, value );
  }

  public CompletableFuture increment( String objKey, Integer value )
  {
    return makeRemoteCall( "incrementBy", new AdaptingResponder<>( Long.class ), objKey, value );
  }

  public CompletableFuture decrement( String objKey, Integer value )
  {
    return increment( objKey, -value );
  }

  public CompletableFuture keyExists( String objKey )
  {
    return makeRemoteCall( "exists", objKey );
  }

  public CompletableFuture length()
  {
    return makeRemoteCall( "length", new AdaptingResponder<>( Long.class ) );
  }

  public CompletableFuture delete( String objKey )
  {
    return delete( Collections.singletonList( objKey ) );
  }

  public CompletableFuture delete( List objKeys )
  {
    return makeRemoteCall( "del", new AdaptingResponder<>( Long.class ), objKeys );
  }

  // ----------------------------------------

  private  CompletableFuture makeRemoteCall( String methodName, Object... args )
  {
    return makeRemoteCallWithStoreKey( HIVE_MAP_ALIAS, methodName, args );
  }

  private  CompletableFuture makeRemoteCall( String methodName, AdaptingResponder adaptingResponder, Object... args )
  {
    return makeRemoteCallWithStoreKey( HIVE_MAP_ALIAS, methodName, adaptingResponder, args );
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy