@Test(groups = {"unit"}) public void testBasicMultiGetAsMap() throws Exception { Rows<String,String,String> resultRows = mock(Rows.class); Row<String,String,String> row1 = mock(Row.class); Row<String,String,String> row2 = mock(Row.class); when(row1.getKey()).thenReturn("row1Key"); when(row2.getKey()).thenReturn("row2Key"); ColumnSlice columnSlice1 = mock(ColumnSlice.class); HColumn column1 = mock(HColumn.class); HColumn column2 = mock(HColumn.class); when(column1.getName()).thenReturn(columnNames.get(0)); when(column1.getValue()).thenReturn(columnValues.get(0)); when(column2.getName()).thenReturn(columnNames.get(1)); when(column2.getValue()).thenReturn(columnValues.get(1)); when(columnSlice1.getColumns()).thenReturn(Arrays.asList(column1, column2)); when(row1.getColumnSlice()).thenReturn(columnSlice1); when(row2.getColumnSlice()).thenReturn(columnSlice1); Iterator<Row<String,String,String>> iterator = Arrays.asList(row1,row2).iterator(); when(resultRows.iterator()).thenReturn(iterator); when(executionResult.get()).thenReturn(resultRows); Iterable<String> rowKeys = Arrays.asList("key1", "key2"); Map<String,String> oneRowMap = new HashMap<String,String>(); oneRowMap.put("columnName1", "columnValue1"); oneRowMap.put("columnName2", "columnValue2"); Map<String,Map<String,String>> expectedResultMap = new HashMap<String,Map<String,String>>(); expectedResultMap.put("row1Key", oneRowMap); expectedResultMap.put("row2Key", oneRowMap); Map<String,Map<String,String>> resultMap = columnFamilyTestDao.multiGetAsMap(rowKeys); assertNotNull(resultMap); assertEquals(resultMap, expectedResultMap); }
private Map<K,Map<N,V>> basicMultiGetAsMap(Iterable <K> rowKeys, @Nullable N[] columnNames) { Map<K,Map<N,V>> resultMap = new HashMap<K,Map<N,V>>(); MultigetSliceQuery<K,N,V> query = HFactory.createMultigetSliceQuery(getKeyspace(), getKeySerializer(), getColumnNameSerializer(), getValueSerializer()); query.setKeys(rowKeys). setColumnFamily(getColumnFamily()). setRange(null, null, false, ALL); if (columnNames != null) { query.setColumnNames(columnNames); } QueryResult<Rows<K,N,V>> result = query.execute(); for (Row<K,N,V> row : result.get()) { K key = row.getKey(); ColumnSlice<N,V> slice = row.getColumnSlice(); Map<N,V> columns = new HashMap<N,V>(); for (HColumn<N,V> column : slice.getColumns()) { V value = column.getValue(); columns.put(column.getName(), value); } resultMap.put(key, columns); } if (LOG.isDebugEnabled()) { LOG.debug("Returning result from multiGetColumnsAsMap: " + resultMap); } return resultMap; }
ColumnFamilyTemplate extends AbstractColumnFamilyTemplate<K,N,V> implements ColumnFamilyOperations<K,N,V> { private Map<K,Map<N,V>> basicMultiGetAsMap(Iterable <K> rowKeys, @Nullable N[] columnNames) { Map<K,Map<N,V>> resultMap = new HashMap<K,Map<N,V>>(); MultigetSliceQuery<K,N,V> query = HFactory.createMultigetSliceQuery(getKeyspace(), getKeySerializer(), getColumnNameSerializer(), getValueSerializer()); query.setKeys(rowKeys). setColumnFamily(getColumnFamily()). setRange(null, null, false, ALL); if (columnNames != null) { query.setColumnNames(columnNames); } QueryResult<Rows<K,N,V>> result = query.execute(); for (Row<K,N,V> row : result.get()) { K key = row.getKey(); ColumnSlice<N,V> slice = row.getColumnSlice(); Map<N,V> columns = new HashMap<N,V>(); for (HColumn<N,V> column : slice.getColumns()) { V value = column.getValue(); columns.put(column.getName(), value); } resultMap.put(key, columns); } if (LOG.isDebugEnabled()) { LOG.debug("Returning result from multiGetColumnsAsMap: " + resultMap); } return resultMap; } }
ColumnFamilyTemplate extends AbstractColumnFamilyTemplate<K,N,V> implements ColumnFamilyOperations<K,N,V> { private Map<K,Map<N,V>> basicMultiGetAsMap(Iterable <K> rowKeys, @Nullable N[] columnNames) { Map<K,Map<N,V>> resultMap = new HashMap<K,Map<N,V>>(); MultigetSliceQuery<K,N,V> query = HFactory.createMultigetSliceQuery(getKeyspace(), getKeySerializer(), getColumnNameSerializer(), getValueSerializer()); query.setKeys(rowKeys). setColumnFamily(getColumnFamily()). setRange(null, null, false, ALL); if (columnNames != null) { query.setColumnNames(columnNames); } QueryResult<Rows<K,N,V>> result = query.execute(); for (Row<K,N,V> row : result.get()) { K key = row.getKey(); ColumnSlice<N,V> slice = row.getColumnSlice(); Map<N,V> columns = new HashMap<N,V>(); for (HColumn<N,V> column : slice.getColumns()) { V value = column.getValue(); columns.put(column.getName(), value); } resultMap.put(key, columns); } if (LOG.isDebugEnabled()) { LOG.debug("Returning result from multiGetColumnsAsMap: " + resultMap); } return resultMap; } ColumnFamilyTemplate(Keyspace keyspace,
                                Serializer<K> keySerializer,
                                Serializer<N> columnNameSerializer,
                                Serializer<V> valueSerializer);  ColumnFamilyTemplate(Keyspace keyspace,
                                @Nullable String defaultColumnFamily,
                                Serializer<K> keySerializer,
                                Serializer<N> columnNameSerializer,
                                Serializer<V> valueSerializer); }
ColumnFamilyTemplate extends AbstractColumnFamilyTemplate<K,N,V> implements ColumnFamilyOperations<K,N,V> { private Map<K,Map<N,V>> basicMultiGetAsMap(Iterable <K> rowKeys, @Nullable N[] columnNames) { Map<K,Map<N,V>> resultMap = new HashMap<K,Map<N,V>>(); MultigetSliceQuery<K,N,V> query = HFactory.createMultigetSliceQuery(getKeyspace(), getKeySerializer(), getColumnNameSerializer(), getValueSerializer()); query.setKeys(rowKeys). setColumnFamily(getColumnFamily()). setRange(null, null, false, ALL); if (columnNames != null) { query.setColumnNames(columnNames); } QueryResult<Rows<K,N,V>> result = query.execute(); for (Row<K,N,V> row : result.get()) { K key = row.getKey(); ColumnSlice<N,V> slice = row.getColumnSlice(); Map<N,V> columns = new HashMap<N,V>(); for (HColumn<N,V> column : slice.getColumns()) { V value = column.getValue(); columns.put(column.getName(), value); } resultMap.put(key, columns); } if (LOG.isDebugEnabled()) { LOG.debug("Returning result from multiGetColumnsAsMap: " + resultMap); } return resultMap; } ColumnFamilyTemplate(Keyspace keyspace,
                                Serializer<K> keySerializer,
                                Serializer<N> columnNameSerializer,
                                Serializer<V> valueSerializer);  ColumnFamilyTemplate(Keyspace keyspace,
                                @Nullable String defaultColumnFamily,
                                Serializer<K> keySerializer,
                                Serializer<N> columnNameSerializer,
                                Serializer<V> valueSerializer); @Override V readColumnValue(K rowKey, N columnName); @Override Map<N,V> readColumnsAsMap(K rowKey); @Override Map<N,V> readColumnsAsMap(K rowKey, N start, N finish, int count, boolean reversed); @Override List<T> readColumns(K rowKey, ColumnMapper <T,N,V> columnMapper); @Override List<T> readColumns(K rowKey,
                                   N start,
                                   N finish,
                                   int count,
                                   boolean reversed,
                                   ColumnMapper<T,N,V> columnMapper); @Override Map<K,Map<N,V>> multiGetAsMap(Iterable<K> rowKeys); @Override Map<K,Map<N,V>> multiGetColumnsAsMap(Iterable<K> rowKeys, N... columnNames); @Override Map<K,Map<N,V>> readRowsAsMap(); @Override List<T> multiGet(Iterable<K> rowKeys, ColumnFamilyRowMapper<T,K,N,V> rowMapper); @Override List<T> multiGetColumns(Iterable<K> rowKeys, ColumnFamilyRowMapper<T,K,N,V> rowMapper,
                                       N... columnNames); @Override void writeColumn(K rowKey, N columnName, V columnValue); @Override void writeColumn(K rowKey, N columnName, V columnValue, long timeToLive, TimeUnit timeToLiveTimeUnit); @Override void writeColumn(K rowKey, N columnName, V columnValue, @Nonnull BatchContext batchContext); @Override void writeColumn(K rowKey,
                            N columnName,
                            V columnValue,
                            int timeToLive,
                            TimeUnit timeToLiveTimeUnit,
                            @Nonnull BatchContext batchContext); @Override void writeColumns(K rowKey, Map<N,V> map); @Override void writeColumns(K rowKey, Map<N,V> map, @Nonnull BatchContext batchContext); @Override void deleteColumns(K rowKey, N... columnNames); @Override void deleteColumns(K rowKey, N start, N finish); @Override void deleteColumns(K rowKey, N start, N finish, @Nullable BatchContext batchContext); }
ColumnFamilyTemplate extends AbstractColumnFamilyTemplate<K,N,V> implements ColumnFamilyOperations<K,N,V> { private Map<K,Map<N,V>> basicMultiGetAsMap(Iterable <K> rowKeys, @Nullable N[] columnNames) { Map<K,Map<N,V>> resultMap = new HashMap<K,Map<N,V>>(); MultigetSliceQuery<K,N,V> query = HFactory.createMultigetSliceQuery(getKeyspace(), getKeySerializer(), getColumnNameSerializer(), getValueSerializer()); query.setKeys(rowKeys). setColumnFamily(getColumnFamily()). setRange(null, null, false, ALL); if (columnNames != null) { query.setColumnNames(columnNames); } QueryResult<Rows<K,N,V>> result = query.execute(); for (Row<K,N,V> row : result.get()) { K key = row.getKey(); ColumnSlice<N,V> slice = row.getColumnSlice(); Map<N,V> columns = new HashMap<N,V>(); for (HColumn<N,V> column : slice.getColumns()) { V value = column.getValue(); columns.put(column.getName(), value); } resultMap.put(key, columns); } if (LOG.isDebugEnabled()) { LOG.debug("Returning result from multiGetColumnsAsMap: " + resultMap); } return resultMap; } ColumnFamilyTemplate(Keyspace keyspace,
                                Serializer<K> keySerializer,
                                Serializer<N> columnNameSerializer,
                                Serializer<V> valueSerializer);  ColumnFamilyTemplate(Keyspace keyspace,
                                @Nullable String defaultColumnFamily,
                                Serializer<K> keySerializer,
                                Serializer<N> columnNameSerializer,
                                Serializer<V> valueSerializer); @Override V readColumnValue(K rowKey, N columnName); @Override Map<N,V> readColumnsAsMap(K rowKey); @Override Map<N,V> readColumnsAsMap(K rowKey, N start, N finish, int count, boolean reversed); @Override List<T> readColumns(K rowKey, ColumnMapper <T,N,V> columnMapper); @Override List<T> readColumns(K rowKey,
                                   N start,
                                   N finish,
                                   int count,
                                   boolean reversed,
                                   ColumnMapper<T,N,V> columnMapper); @Override Map<K,Map<N,V>> multiGetAsMap(Iterable<K> rowKeys); @Override Map<K,Map<N,V>> multiGetColumnsAsMap(Iterable<K> rowKeys, N... columnNames); @Override Map<K,Map<N,V>> readRowsAsMap(); @Override List<T> multiGet(Iterable<K> rowKeys, ColumnFamilyRowMapper<T,K,N,V> rowMapper); @Override List<T> multiGetColumns(Iterable<K> rowKeys, ColumnFamilyRowMapper<T,K,N,V> rowMapper,
                                       N... columnNames); @Override void writeColumn(K rowKey, N columnName, V columnValue); @Override void writeColumn(K rowKey, N columnName, V columnValue, long timeToLive, TimeUnit timeToLiveTimeUnit); @Override void writeColumn(K rowKey, N columnName, V columnValue, @Nonnull BatchContext batchContext); @Override void writeColumn(K rowKey,
                            N columnName,
                            V columnValue,
                            int timeToLive,
                            TimeUnit timeToLiveTimeUnit,
                            @Nonnull BatchContext batchContext); @Override void writeColumns(K rowKey, Map<N,V> map); @Override void writeColumns(K rowKey, Map<N,V> map, @Nonnull BatchContext batchContext); @Override void deleteColumns(K rowKey, N... columnNames); @Override void deleteColumns(K rowKey, N start, N finish); @Override void deleteColumns(K rowKey, N start, N finish, @Nullable BatchContext batchContext);  }