public int insertEntity(
      String entitySet,
      String entityPK,
      HashMap<String, ByteIterator> values,
      boolean insertImage) {
    // TODO Auto-generated method stub
    /* Insert into table */
    try {
      long mutator = client.mutator_open(namespace, entitySet, 0, 0);
      List<Cell> cells = new ArrayList<Cell>();
      Key key = null;
      Cell cell = null;

      for (HashMap.Entry<String, ByteIterator> entry : values.entrySet()) {
        key = new Key(entityPK, entry.getKey(), null, KeyFlag.INSERT);
        cell = new Cell(key);
        cell.setValue(entry.getValue().toArray());
        cells.add(cell);
      }

      client.mutator_set_cells(mutator, cells);
      client.mutator_flush(mutator);
      cells.clear();
      client.mutator_close(mutator);
    } catch (ClientException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return -1;
    } catch (TException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return -1;
    }
    return 0;
  }
Beispiel #2
0
 /**
  * Disconnects from all the connected brokers. The client first unsubscribe/unadvertise all the
  * subscriptions/advertisements before disconnecting from brokers.
  *
  * @return A String message that describes the success/failure of the operation.
  */
 public String disconnectAll() {
   String outStr = "";
   for (BrokerState brokerState : new HashMap<NodeAddress, BrokerState>(brokerStates).values()) {
     try {
       disconnect(brokerState);
       outStr += "disconnected from " + brokerState.getBrokerAddress() + "\n";
     } catch (ClientException e) {
       outStr += e.getMessage() + "\n";
     }
   }
   return outStr;
 }
  @Test
  public void testFooUrl() {

    // Should throw an exception but no help message

    try {
      tested.run(new String[] {"--find", "--url=foobar"});
    } catch (ClientException e) {
      assertEquals("Unexpected exception message", Main.INVALID_URL + "foobar", e.getMessage());
      String outputString = baos.toString();
      assertTrue(
          "The expected output wasn't produced, was:\n" + outputString,
          outputString.contains(Main.INVALID_URL));
      String errorOutput = ebaos.toString();
      assertEquals("No output was expected to stderr", "", errorOutput);
      return;
    }
    fail("The expected client exception was not thrown");
  }
  @Test
  public void testNoUrl() {

    // Should throw an exception and print out a help message

    try {
      tested.run(new String[] {"--find"});
    } catch (ClientException e) {
      assertEquals("Unexpected exception message", Main.MISSING_URL, e.getMessage());
      String outputString = baos.toString();
      assertTrue(
          "The expected help output wasn't produced, was:\n" + outputString,
          TestUtils.checkForHelpMessage(outputString));

      String errorOutput = ebaos.toString();
      assertEquals("No output was expected to stderr", "", errorOutput);
      return;
    }
    fail("The expected client exception was not thrown");
  }
 @Override
 public String toString() {
   return exceptionType.toString();
 }
 public HttpClientException(ClientException clientExp) {
   super(clientExp.toString());
   exceptionType = clientExp;
 }