@Test public void testRead() throws Exception { cluster.cache(DEFAULT_CACHE_NAME).clear(); final String key = "key"; final Map<String, String> input = new HashMap<>(); input.put("field0", "value1"); input.put("field1", "value2A"); input.put("field3", null); final Status sPut = client.insert(TABLE_NAME, key, StringByteIterator.getByteIteratorMap(input)); assertThat(sPut, is(Status.OK)); assertThat(cluster.cache(DEFAULT_CACHE_NAME).size(), is(1)); final Set<String> fld = new TreeSet<>(); fld.add("field0"); fld.add("field1"); fld.add("field3"); final HashMap<String, ByteIterator> result = new HashMap<>(); final Status sGet = client.read(TABLE_NAME, key, fld, result); assertThat(sGet, is(Status.OK)); final HashMap<String, String> strResult = new HashMap<String, String>(); for (final Map.Entry<String, ByteIterator> e : result.entrySet()) { if (e.getValue() != null) { strResult.put(e.getKey(), e.getValue().toString()); } } assertThat(strResult, hasEntry("field0", "value1")); assertThat(strResult, hasEntry("field1", "value2A")); }
@Override public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { try { StringBuilder sb = new StringBuilder("SELECT * FROM ").append(table) .append(" WHERE ").append(PRIMARY_KEY).append("=?"); SqlFieldsQuery qry = new SqlFieldsQuery(sb.toString()); qry.setArgs(key); FieldsQueryCursor<List<?>> cur = cache.query(qry); Iterator<List<?>> it = cur.iterator(); if (!it.hasNext()) { return Status.NOT_FOUND; } String[] colNames = new String[cur.getColumnsCount()]; for (int i = 0; i < colNames.length; ++i) { String colName = cur.getFieldName(i); if (F.isEmpty(fields)) { colNames[i] = colName.toLowerCase(); } else { for (String f : fields) { if (f.equalsIgnoreCase(colName)) { colNames[i] = f; } } } } while (it.hasNext()) { List<?> row = it.next(); for (int i = 0; i < colNames.length; ++i) { if (colNames[i] != null) { result.put(colNames[i], new StringByteIterator((String) row.get(i))); } } } return Status.OK; } catch (Exception e) { log.error(String.format("Error in processing read from table: %s", table), e); return Status.ERROR; } }
IgniteSqlClient extends IgniteAbstractClient { @Override public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { try { StringBuilder sb = new StringBuilder("SELECT * FROM ").append(table) .append(" WHERE ").append(PRIMARY_KEY).append("=?"); SqlFieldsQuery qry = new SqlFieldsQuery(sb.toString()); qry.setArgs(key); FieldsQueryCursor<List<?>> cur = cache.query(qry); Iterator<List<?>> it = cur.iterator(); if (!it.hasNext()) { return Status.NOT_FOUND; } String[] colNames = new String[cur.getColumnsCount()]; for (int i = 0; i < colNames.length; ++i) { String colName = cur.getFieldName(i); if (F.isEmpty(fields)) { colNames[i] = colName.toLowerCase(); } else { for (String f : fields) { if (f.equalsIgnoreCase(colName)) { colNames[i] = f; } } } } while (it.hasNext()) { List<?> row = it.next(); for (int i = 0; i < colNames.length; ++i) { if (colNames[i] != null) { result.put(colNames[i], new StringByteIterator((String) row.get(i))); } } } return Status.OK; } catch (Exception e) { log.error(String.format("Error in processing read from table: %s", table), e); return Status.ERROR; } } }
IgniteSqlClient extends IgniteAbstractClient { @Override public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { try { StringBuilder sb = new StringBuilder("SELECT * FROM ").append(table) .append(" WHERE ").append(PRIMARY_KEY).append("=?"); SqlFieldsQuery qry = new SqlFieldsQuery(sb.toString()); qry.setArgs(key); FieldsQueryCursor<List<?>> cur = cache.query(qry); Iterator<List<?>> it = cur.iterator(); if (!it.hasNext()) { return Status.NOT_FOUND; } String[] colNames = new String[cur.getColumnsCount()]; for (int i = 0; i < colNames.length; ++i) { String colName = cur.getFieldName(i); if (F.isEmpty(fields)) { colNames[i] = colName.toLowerCase(); } else { for (String f : fields) { if (f.equalsIgnoreCase(colName)) { colNames[i] = f; } } } } while (it.hasNext()) { List<?> row = it.next(); for (int i = 0; i < colNames.length; ++i) { if (colNames[i] != null) { result.put(colNames[i], new StringByteIterator((String) row.get(i))); } } } return Status.OK; } catch (Exception e) { log.error(String.format("Error in processing read from table: %s", table), e); return Status.ERROR; } }  }
IgniteSqlClient extends IgniteAbstractClient { @Override public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { try { StringBuilder sb = new StringBuilder("SELECT * FROM ").append(table) .append(" WHERE ").append(PRIMARY_KEY).append("=?"); SqlFieldsQuery qry = new SqlFieldsQuery(sb.toString()); qry.setArgs(key); FieldsQueryCursor<List<?>> cur = cache.query(qry); Iterator<List<?>> it = cur.iterator(); if (!it.hasNext()) { return Status.NOT_FOUND; } String[] colNames = new String[cur.getColumnsCount()]; for (int i = 0; i < colNames.length; ++i) { String colName = cur.getFieldName(i); if (F.isEmpty(fields)) { colNames[i] = colName.toLowerCase(); } else { for (String f : fields) { if (f.equalsIgnoreCase(colName)) { colNames[i] = f; } } } } while (it.hasNext()) { List<?> row = it.next(); for (int i = 0; i < colNames.length; ++i) { if (colNames[i] != null) { result.put(colNames[i], new StringByteIterator((String) row.get(i))); } } } return Status.OK; } catch (Exception e) { log.error(String.format("Error in processing read from table: %s", table), e); return Status.ERROR; } }  @Override Status read(String table, String key, Set<String> fields,
                     Map<String, ByteIterator> result); @Override Status update(String table, String key,
                       Map<String, ByteIterator> values); @Override Status insert(String table, String key, Map<String, ByteIterator> values); @Override Status delete(String table, String key); }
IgniteSqlClient extends IgniteAbstractClient { @Override public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { try { StringBuilder sb = new StringBuilder("SELECT * FROM ").append(table) .append(" WHERE ").append(PRIMARY_KEY).append("=?"); SqlFieldsQuery qry = new SqlFieldsQuery(sb.toString()); qry.setArgs(key); FieldsQueryCursor<List<?>> cur = cache.query(qry); Iterator<List<?>> it = cur.iterator(); if (!it.hasNext()) { return Status.NOT_FOUND; } String[] colNames = new String[cur.getColumnsCount()]; for (int i = 0; i < colNames.length; ++i) { String colName = cur.getFieldName(i); if (F.isEmpty(fields)) { colNames[i] = colName.toLowerCase(); } else { for (String f : fields) { if (f.equalsIgnoreCase(colName)) { colNames[i] = f; } } } } while (it.hasNext()) { List<?> row = it.next(); for (int i = 0; i < colNames.length; ++i) { if (colNames[i] != null) { result.put(colNames[i], new StringByteIterator((String) row.get(i))); } } } return Status.OK; } catch (Exception e) { log.error(String.format("Error in processing read from table: %s", table), e); return Status.ERROR; } }  @Override Status read(String table, String key, Set<String> fields,
                     Map<String, ByteIterator> result); @Override Status update(String table, String key,
                       Map<String, ByteIterator> values); @Override Status insert(String table, String key, Map<String, ByteIterator> values); @Override Status delete(String table, String key);  }