Package com.basho.riak.client.core.query.functions

Examples of com.basho.riak.client.core.query.functions.Function


  }

  @Test
  public void testSerializeErlangFunction() throws IOException
  {
    Function function = Function.newErlangFunction("mod", "fun");
     PhaseFunction phaseFunction = new PhaseFunction(function, true);

    jg.writeObject(phaseFunction);

    assertEquals("{\"language\":\"erlang\",\"module\":\"mod\",\"function\":\"fun\",\"keep\":true}", out.toString());
View Full Code Here


  }

  @Test
  public void testSerializeAnonJsFunction() throws IOException
  {
    Function function = Function.newAnonymousJsFunction("function() {}");
    PhaseFunction phaseFunction = new PhaseFunction(function, true);

    jg.writeObject(phaseFunction);

    assertEquals("{\"language\":\"javascript\",\"source\":\"function() {}\",\"keep\":true}", out.toString());
View Full Code Here

  }

  @Test
  public void testSerializeNamedJsFunction() throws IOException
  {
    Function function = Function.newNamedJsFunction("the_func");
    PhaseFunction phaseFunction = new PhaseFunction(function, true);

    jg.writeObject(phaseFunction);

    assertEquals("{\"language\":\"javascript\",\"name\":\"the_func\",\"keep\":true}", out.toString());
View Full Code Here

  @Test
  public void testSerializeMapPhase() throws IOException
  {

    Function function = Function.newNamedJsFunction("the_func");
    MapPhase phase = new MapPhase(function, "Arg", true);

    jg.writeObject(phase);

    assertEquals("{\"map\":{\"language\":\"javascript\",\"name\":\"the_func\",\"keep\":true,\"arg\":\"Arg\"}}", out.toString());
View Full Code Here

  }

  @Test
  public void testSerializeReducePhase() throws IOException
  {
    Function function = Function.newNamedJsFunction("the_func");
    ReducePhase phase = new ReducePhase(function, "Arg", true);

    jg.writeObject(phase);

    assertEquals("{\"reduce\":{\"language\":\"javascript\",\"name\":\"the_func\",\"keep\":true,\"arg\":\"Arg\"}}", out.toString());
View Full Code Here

class FunctionPhaseSerializer extends JsonSerializer<FunctionPhase>
{

  private void writePhaseFunction(JsonGenerator jg, FunctionPhase phase) throws IOException
  {
    Function function = phase.getFunction();

    jg.writeStartObject();

    jg.writeStringField("language", function.isJavascript() ? "javascript" : "erlang");

    if (function.isJavascript())
    {
      if (function.isNamed())
      {
        jg.writeStringField("name", function.getName());
      } else if (function.isStored())
      {
        jg.writeStringField("bucket", function.getBucket());
        jg.writeStringField("key", function.getKey());
      } else if (function.isAnonymous())
      {
        jg.writeStringField("source", function.getSource());
      } else
      {
        throw new IllegalStateException("Cannot determine function type");
      }
    } else if (!function.isJavascript())
    {
      jg.writeStringField("module", function.getModule());
      jg.writeStringField("function", function.getFunction());
    }

    jg.writeBooleanField("keep", phase.isKeep());
    jg.writeObjectField("arg", phase.getArg());
View Full Code Here

class PhaseFunctionSerializer extends JsonSerializer<PhaseFunction>
{
  @Override
  public void serialize(PhaseFunction phaseFunction, JsonGenerator jg, SerializerProvider sp) throws IOException
  {
    Function function = phaseFunction.getFunction();

    jg.writeStartObject();

    jg.writeStringField("language", function.isJavascript() ? "javascript" : "erlang");

    if (function.isJavascript())
    {
      if (function.isNamed())
      {
        jg.writeStringField("name", function.getName());
      } else if (function.isStored())
      {
        jg.writeStringField("bucket", function.getBucket());
        jg.writeStringField("key", function.getKey());
      } else if (function.isAnonymous())
      {
        jg.writeStringField("source", function.getSource());
      } else
      {
        throw new IllegalStateException("Cannot determine function type");
      }
    } else if (!function.isJavascript())
    {
      jg.writeStringField("module", function.getModule());
      jg.writeStringField("function", function.getFunction());
    }

    jg.writeBooleanField("keep", phaseFunction.isKeep());

    jg.writeEndObject();
View Full Code Here

   
    private static List<Function> parseHooks(List<RiakPB.RpbCommitHook> hooks) {
        List<Function> list = new ArrayList<Function>(hooks.size());
        for ( RiakPB.RpbCommitHook hook : hooks) {
            if (hook.hasName()) {
                Function f =
                    new Function.Builder()
                        .withName(hook.getName().toStringUtf8())
                        .build();
                list.add(f);
            } else {
                Function f = new Function.Builder()
                    .withModule(hook.getModfun().getModule().toStringUtf8())
                    .withFunction(hook.getModfun().getFunction().toStringUtf8())
                    .build();
                list.add(f);
            }
View Full Code Here

TOP

Related Classes of com.basho.riak.client.core.query.functions.Function

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.