@Test public void readTest() { String insertKey = "user0"; HashMap<String, ByteIterator> insertMap = insertRow(insertKey); Set<String> readFields = new HashSet<String>(); HashMap<String, ByteIterator> readResultMap = new HashMap<String, ByteIterator>(); readFields.add("FIELD0"); jdbcDBClient.read(TABLE_NAME, insertKey, readFields, readResultMap); assertEquals("Assert that result has correct number of fields", readFields.size(), readResultMap.size()); for (String field: readFields) { assertEquals("Assert " + field + " was read correctly", insertMap.get(field).toString(), readResultMap.get(field).toString()); } readResultMap = new HashMap<String, ByteIterator>(); readFields.add("FIELD1"); readFields.add("FIELD2"); jdbcDBClient.read(TABLE_NAME, insertKey, readFields, readResultMap); assertEquals("Assert that result has correct number of fields", readFields.size(), readResultMap.size()); for (String field: readFields) { assertEquals("Assert " + field + " was read correctly", insertMap.get(field).toString(), readResultMap.get(field).toString()); } }
@Override public Status read(String tableName, String key, Set<String> fields, Map<String, ByteIterator> result) { try { StatementType type = new StatementType(StatementType.Type.READ, tableName, 1, "", getShardIndexByKey(key)); PreparedStatement readStatement = cachedStatements.get(type); if (readStatement == null) { readStatement = createAndCacheReadStatement(type, key); } readStatement.setString(1, key); ResultSet resultSet = readStatement.executeQuery(); if (!resultSet.next()) { resultSet.close(); return Status.NOT_FOUND; } if (result != null && fields != null) { for (String field : fields) { String value = resultSet.getString(field); result.put(field, new StringByteIterator(value)); } } resultSet.close(); return Status.OK; } catch (SQLException e) { System.err.println("Error in processing read of table " + tableName + ": " + e); return Status.ERROR; } }
JdbcDBClient extends DB { @Override public Status read(String tableName, String key, Set<String> fields, Map<String, ByteIterator> result) { try { StatementType type = new StatementType(StatementType.Type.READ, tableName, 1, "", getShardIndexByKey(key)); PreparedStatement readStatement = cachedStatements.get(type); if (readStatement == null) { readStatement = createAndCacheReadStatement(type, key); } readStatement.setString(1, key); ResultSet resultSet = readStatement.executeQuery(); if (!resultSet.next()) { resultSet.close(); return Status.NOT_FOUND; } if (result != null && fields != null) { for (String field : fields) { String value = resultSet.getString(field); result.put(field, new StringByteIterator(value)); } } resultSet.close(); return Status.OK; } catch (SQLException e) { System.err.println("Error in processing read of table " + tableName + ": " + e); return Status.ERROR; } } }
JdbcDBClient extends DB { @Override public Status read(String tableName, String key, Set<String> fields, Map<String, ByteIterator> result) { try { StatementType type = new StatementType(StatementType.Type.READ, tableName, 1, "", getShardIndexByKey(key)); PreparedStatement readStatement = cachedStatements.get(type); if (readStatement == null) { readStatement = createAndCacheReadStatement(type, key); } readStatement.setString(1, key); ResultSet resultSet = readStatement.executeQuery(); if (!resultSet.next()) { resultSet.close(); return Status.NOT_FOUND; } if (result != null && fields != null) { for (String field : fields) { String value = resultSet.getString(field); result.put(field, new StringByteIterator(value)); } } resultSet.close(); return Status.OK; } catch (SQLException e) { System.err.println("Error in processing read of table " + tableName + ": " + e); return Status.ERROR; } }  }
JdbcDBClient extends DB { @Override public Status read(String tableName, String key, Set<String> fields, Map<String, ByteIterator> result) { try { StatementType type = new StatementType(StatementType.Type.READ, tableName, 1, "", getShardIndexByKey(key)); PreparedStatement readStatement = cachedStatements.get(type); if (readStatement == null) { readStatement = createAndCacheReadStatement(type, key); } readStatement.setString(1, key); ResultSet resultSet = readStatement.executeQuery(); if (!resultSet.next()) { resultSet.close(); return Status.NOT_FOUND; } if (result != null && fields != null) { for (String field : fields) { String value = resultSet.getString(field); result.put(field, new StringByteIterator(value)); } } resultSet.close(); return Status.OK; } catch (SQLException e) { System.err.println("Error in processing read of table " + tableName + ": " + e); return Status.ERROR; } }  @Override void init(); @Override void cleanup(); @Override Status read(String tableName, String key, Set<String> fields, Map<String, ByteIterator> result); @Override Status readLog(String table, int logcount); @Override Status readMeta(String tableName, String cond, String keymatch, Vector<HashMap<String, ByteIterator>> result); @Override Status scan(String tableName, String startKey, int recordcount, Set<String> fields,
                     Vector<HashMap<String, ByteIterator>> result); @Override Status update(String tableName, String key, Map<String, ByteIterator> values); @Override Status updateMeta(String table, String condition, String keymatch, String fieldname, String metadatavalue); @Override Status insert(String tableName, String key, Map<String, ByteIterator> values); @Override Status delete(String tableName, String key); @Override Status deleteMeta(String table, String condition, String keymatch); @Override Status verifyTTL(String table, long recordcount); @Override Status insertTTL(String table, String key,
                         Map<String, ByteIterator> values, int ttl); }
JdbcDBClient extends DB { @Override public Status read(String tableName, String key, Set<String> fields, Map<String, ByteIterator> result) { try { StatementType type = new StatementType(StatementType.Type.READ, tableName, 1, "", getShardIndexByKey(key)); PreparedStatement readStatement = cachedStatements.get(type); if (readStatement == null) { readStatement = createAndCacheReadStatement(type, key); } readStatement.setString(1, key); ResultSet resultSet = readStatement.executeQuery(); if (!resultSet.next()) { resultSet.close(); return Status.NOT_FOUND; } if (result != null && fields != null) { for (String field : fields) { String value = resultSet.getString(field); result.put(field, new StringByteIterator(value)); } } resultSet.close(); return Status.OK; } catch (SQLException e) { System.err.println("Error in processing read of table " + tableName + ": " + e); return Status.ERROR; } }  @Override void init(); @Override void cleanup(); @Override Status read(String tableName, String key, Set<String> fields, Map<String, ByteIterator> result); @Override Status readLog(String table, int logcount); @Override Status readMeta(String tableName, String cond, String keymatch, Vector<HashMap<String, ByteIterator>> result); @Override Status scan(String tableName, String startKey, int recordcount, Set<String> fields,
                     Vector<HashMap<String, ByteIterator>> result); @Override Status update(String tableName, String key, Map<String, ByteIterator> values); @Override Status updateMeta(String table, String condition, String keymatch, String fieldname, String metadatavalue); @Override Status insert(String tableName, String key, Map<String, ByteIterator> values); @Override Status delete(String tableName, String key); @Override Status deleteMeta(String table, String condition, String keymatch); @Override Status verifyTTL(String table, long recordcount); @Override Status insertTTL(String table, String key,
                         Map<String, ByteIterator> values, int ttl); static final String DRIVER_CLASS; static final String CONNECTION_URL; static final String CONNECTION_USER; static final String CONNECTION_PASSWD; static final String DB_BATCH_SIZE; static final String JDBC_FETCH_SIZE; static final String JDBC_AUTO_COMMIT; static final String JDBC_BATCH_UPDATES; static final String FIELD_COUNT_PROPERTY; static final String FIELD_COUNT_PROPERTY_DEFAULT; static final String NULL_VALUE; static final String PRIMARY_KEY; static final String COLUMN_PREFIX; }