@Test public void testUpdate() { System.out.println("update"); int i; HashMap<String, ByteIterator> newValues = new HashMap<String, ByteIterator>(10); for (i = 1; i <= 10; i++) { newValues.put("field" + i, new StringByteIterator("newvalue" + i)); } int expResult = 0; int result = instance.update(MOCK_TABLE, MOCK_KEY1, newValues); assertEquals(expResult, result); HashMap<String, ByteIterator> resultParam = new HashMap<String, ByteIterator>(10); instance.read(MOCK_TABLE, MOCK_KEY1, MOCK_DATA.keySet(), resultParam); for (i = 1; i <= 10; i++) { assertEquals("newvalue" + i, resultParam.get("field" + i).toString()); } }
@Override public int update(String table, String key, HashMap<String, ByteIterator> values) { try { final GetResponse response = client.prepareGet(indexKey, table, key) .execute() .actionGet(); if (response.isExists()) { for (Entry<String, String> entry : StringByteIterator.getStringMap(values).entrySet()) { response.getSource().put(entry.getKey(), entry.getValue()); } client.prepareIndex(indexKey, table, key) .setSource(response.getSource()) .execute() .actionGet(); return 0; } } catch (Exception e) { e.printStackTrace(); } return 1; }
ElasticSearchClient extends DB { @Override public int update(String table, String key, HashMap<String, ByteIterator> values) { try { final GetResponse response = client.prepareGet(indexKey, table, key) .execute() .actionGet(); if (response.isExists()) { for (Entry<String, String> entry : StringByteIterator.getStringMap(values).entrySet()) { response.getSource().put(entry.getKey(), entry.getValue()); } client.prepareIndex(indexKey, table, key) .setSource(response.getSource()) .execute() .actionGet(); return 0; } } catch (Exception e) { e.printStackTrace(); } return 1; } }
ElasticSearchClient extends DB { @Override public int update(String table, String key, HashMap<String, ByteIterator> values) { try { final GetResponse response = client.prepareGet(indexKey, table, key) .execute() .actionGet(); if (response.isExists()) { for (Entry<String, String> entry : StringByteIterator.getStringMap(values).entrySet()) { response.getSource().put(entry.getKey(), entry.getValue()); } client.prepareIndex(indexKey, table, key) .setSource(response.getSource()) .execute() .actionGet(); return 0; } } catch (Exception e) { e.printStackTrace(); } return 1; }  }
ElasticSearchClient extends DB { @Override public int update(String table, String key, HashMap<String, ByteIterator> values) { try { final GetResponse response = client.prepareGet(indexKey, table, key) .execute() .actionGet(); if (response.isExists()) { for (Entry<String, String> entry : StringByteIterator.getStringMap(values).entrySet()) { response.getSource().put(entry.getKey(), entry.getValue()); } client.prepareIndex(indexKey, table, key) .setSource(response.getSource()) .execute() .actionGet(); return 0; } } catch (Exception e) { e.printStackTrace(); } return 1; }  @Override void init(); @Override void cleanup(); @Override int insert(String table, String key, HashMap<String, ByteIterator> values); @Override int delete(String table, String key); @Override int read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result); @Override int update(String table, String key, HashMap<String, ByteIterator> values); @Override int scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result); }
ElasticSearchClient extends DB { @Override public int update(String table, String key, HashMap<String, ByteIterator> values) { try { final GetResponse response = client.prepareGet(indexKey, table, key) .execute() .actionGet(); if (response.isExists()) { for (Entry<String, String> entry : StringByteIterator.getStringMap(values).entrySet()) { response.getSource().put(entry.getKey(), entry.getValue()); } client.prepareIndex(indexKey, table, key) .setSource(response.getSource()) .execute() .actionGet(); return 0; } } catch (Exception e) { e.printStackTrace(); } return 1; }  @Override void init(); @Override void cleanup(); @Override int insert(String table, String key, HashMap<String, ByteIterator> values); @Override int delete(String table, String key); @Override int read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result); @Override int update(String table, String key, HashMap<String, ByteIterator> values); @Override int scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result); static final String DEFAULT_CLUSTER_NAME; static final String DEFAULT_INDEX_KEY; }