本文整理汇总了Java中me.prettyprint.hector.api.beans.HSuperColumn类的典型用法代码示例。如果您正苦于以下问题:Java HSuperColumn类的具体用法?Java HSuperColumn怎么用?Java HSuperColumn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HSuperColumn类属于me.prettyprint.hector.api.beans包,在下文中一共展示了HSuperColumn类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addSuperColumns
import me.prettyprint.hector.api.beans.HSuperColumn; //导入依赖的package包/类
/**
* When we add supercolumns, Gora keys are mapped to Cassandra partition keys only.
* This is because we follow the Cassandra logic where column family data is
* partitioned across nodes based on row Key.
*/
private void addSuperColumns(String family, CassandraQuery<K, T> cassandraQuery,
CassandraResultSet<K> cassandraResultSet) {
List<SuperRow<K, String, ByteBuffer, ByteBuffer>> superRows = this.cassandraClient.executeSuper(cassandraQuery, family);
for (SuperRow<K, String, ByteBuffer, ByteBuffer> superRow: superRows) {
K key = superRow.getKey();
CassandraRow<K> cassandraRow = cassandraResultSet.getRow(key);
if (cassandraRow == null) {
cassandraRow = new CassandraRow<>();
cassandraResultSet.putRow(key, cassandraRow);
cassandraRow.setKey(key);
}
SuperSlice<String, ByteBuffer, ByteBuffer> superSlice = superRow.getSuperSlice();
for (HSuperColumn<String, ByteBuffer, ByteBuffer> hSuperColumn: superSlice.getSuperColumns()) {
CassandraSuperColumn cassandraSuperColumn = new CassandraSuperColumn();
cassandraSuperColumn.setValue(hSuperColumn);
cassandraSuperColumn.setFamily(family);
cassandraRow.add(cassandraSuperColumn);
}
}
}
示例2: readRow
import me.prettyprint.hector.api.beans.HSuperColumn; //导入依赖的package包/类
/**
* Read an entire row as a list of mapped supercolumns.
*
* @param key the row key
* @return a List of T as returned by the supercolumn mapper.
*
*/
@Override
public <T> List<T> readRow(K key, SuperColumnMapper<T,K,SN,N,V> superColumnMapper) {
SuperSliceQuery<K,SN,N,V> query = HFactory.createSuperSliceQuery(getKeyspace(),
getKeySerializer(),
getSuperColumnNameSerializer(),
getSubcolumnNameSerializer(),
getValueSerializer());
query.setKey(key).
setColumnFamily(getColumnFamily()).
setRange(null, null, false, ALL);
QueryResult<SuperSlice<SN,N,V>> queryResult = query.execute();
List<HSuperColumn<SN,N,V>> superColumns = queryResult.get().getSuperColumns();
List<T> results = new ArrayList<T>( superColumns.size());
for (HSuperColumn<SN,N,V> superColumn : superColumns) {
T mappedSuperColumn = superColumnMapper.mapSuperColumn(key, superColumn.getName(), superColumn.getColumns());
// don't include null
if (mappedSuperColumn != null) {
results.add(mappedSuperColumn);
}
}
return results;
// we used to translate hector exceptions into spring exceptions here, but spring dependency was removed
}
示例3: basicWriteColumn
import me.prettyprint.hector.api.beans.HSuperColumn; //导入依赖的package包/类
private void basicWriteColumn(K rowKey,
SN superColumnName,
N columnName,
V columnValue,
@Nullable BatchContext txnContext) {
// create the subcolumns for the super column
@SuppressWarnings({"unchecked"})
List<HColumn<N,V>> columns = Arrays.asList(
HFactory.createColumn(
columnName, columnValue, subSerializer, getValueSerializer()
)
);
HSuperColumn<SN,N,V> superColumn = HFactory.createSuperColumn(superColumnName,
columns,
getSuperColumnNameSerializer(),
getSubcolumnNameSerializer(),
getValueSerializer());
if (txnContext == null) {
insertSuperColumn(rowKey, superColumn);
} else {
insertSuperColumn(rowKey, superColumn, txnContext);
}
}
示例4: testWriteColumnsTranslateHectorException
import me.prettyprint.hector.api.beans.HSuperColumn; //导入依赖的package包/类
@Test(groups={"unit"}, expectedExceptions = HectorTransportException.class)
public void testWriteColumnsTranslateHectorException() {
when(mutator.addInsertion(eq(rowKey),
eq(columnFamily),
any(HSuperColumn.class))).thenThrow(new HectorTransportException(
"test hector exception"));
Map<String,String> properties = new HashMap<String,String>();
Iterator<String> itr = columnValues.iterator();
for (String columnName : columnNames) {
properties.put(columnName, itr.next());
}
//=========================
superColumnFamilyTestDao.writeColumns(rowKey, superColumnName, properties, txnContext);
//=========================
}
示例5: testWriteColumn
import me.prettyprint.hector.api.beans.HSuperColumn; //导入依赖的package包/类
@Test(groups={"unit"})
public void testWriteColumn() {
String propertyValue = columnValue;
//=========================
superColumnFamilyTestDao.writeColumn(rowKey, superColumnName, columnName, propertyValue, txnContext);
//=========================
HColumn<String,String> column = HFactory.createColumn(columnName,
columnValue,
StringSerializer.get(),
StringSerializer.get());
HSuperColumn<String,String,String> superColumn = HFactory.createSuperColumn(superColumnName,
Arrays.asList(column),
StringSerializer.get(),
StringSerializer.get(),
StringSerializer.get());
ArgumentCaptor<HSuperColumn> superColumnCaptor = ArgumentCaptor.forClass(HSuperColumn.class);
verify(mutator).addInsertion(eq(rowKey), eq(columnFamily), superColumnCaptor.capture());
HSuperColumn actualSuperColumn = superColumnCaptor.getValue();
assertTrue(areSuperColumnsEqual(actualSuperColumn, superColumn));
}
示例6: insertSuperColumnData
import me.prettyprint.hector.api.beans.HSuperColumn; //导入依赖的package包/类
private void insertSuperColumnData() {
Mutator<String> mutator = HFactory.createMutator(keyspace, stringSerializer);
mutator.insert("billing", COLUMN_FAMILY_SUPER_1, HFactory.createSuperColumn("jsmith",
Arrays.asList(HFactory.createStringColumn("first", "John")), stringSerializer, stringSerializer,
stringSerializer));
SuperColumnQuery<String, String, String, String> superColumnQuery = HFactory.createSuperColumnQuery(keyspace,
stringSerializer, stringSerializer, stringSerializer, stringSerializer);
superColumnQuery.setColumnFamily(COLUMN_FAMILY_SUPER_1).setKey("billing").setSuperName("jsmith");
QueryResult<HSuperColumn<String, String, String>> result = superColumnQuery.execute();
System.out.println("Read HSuperColumn from cassandra: " + result.get());
System.out.println("Verify on CLI with: get DynamicKeyspace1.ColumnFamilySuper1['billing']['jsmith'] ");
}
示例7: multiGetAllSuperColumns
import me.prettyprint.hector.api.beans.HSuperColumn; //导入依赖的package包/类
@Override
public <T> List<T> multiGetAllSuperColumns(Collection<K> rowKeys, SuperColumnFamilyRowMapper<T,K,SN,N,V>
superColumnFamilyRowMapper) {
List<T> result = new LinkedList<T>();
MultigetSuperSliceQuery<K,SN,N,V> query = HFactory.createMultigetSuperSliceQuery(getKeyspace(),
getKeySerializer(),
getTopSerializer(),
subSerializer,
getValueSerializer());
query.setKeys(rowKeys).
setColumnFamily(getColumnFamily()).
setRange(null, null, false, ALL);
QueryResult<SuperRows<K,SN,N,V>> queryResult = query.execute();
for (SuperRow<K,SN,N,V> row : queryResult.get()) {
K key = row.getKey();
SuperSlice<SN,N,V> slice = row.getSuperSlice();
List<HSuperColumn<SN,N,V>> columns = slice.getSuperColumns();
T t = superColumnFamilyRowMapper.mapRow(key, columns);
result.add(t);
}
// we used to translate hector exceptions into spring exceptions here, but spring dependency was removed
return result;
}
示例8: readRowAsMap
import me.prettyprint.hector.api.beans.HSuperColumn; //导入依赖的package包/类
/**
* Read an entire row as a map of maps.
*
* @param key the row key
* @return the row as a map of maps
* where the key is the super column name and the value is a map of column names to column values.
*/
@Override
public Map<SN,Map<N,V>> readRowAsMap(K key) {
SuperSliceQuery<K,SN,N,V> query = HFactory.createSuperSliceQuery(getKeyspace(),
getKeySerializer(),
getSuperColumnNameSerializer(),
getSubcolumnNameSerializer(),
getValueSerializer());
query.setKey(key).
setColumnFamily(getColumnFamily()).
setRange(null, null, false, ALL);
QueryResult<SuperSlice<SN,N,V>> queryResult = query.execute();
Map<SN,Map<N,V>> results = new HashMap<SN,Map<N,V>>();
for (HSuperColumn<SN,N,V> superColumn : queryResult.get().getSuperColumns()) {
List<HColumn<N,V>> allColumns = superColumn.getColumns();
Map<N,V> columnMap = new HashMap<N,V>(allColumns.size());
for (HColumn<N,V> column : allColumns) {
columnMap.put(column.getName(), column.getValue());
}
if (!columnMap.isEmpty()) {
results.put(superColumn.getName(), columnMap);
}
}
return results;
// we used to translate hector exceptions into spring exceptions here, but spring dependency was removed
}
示例9: basicWriteColumns
import me.prettyprint.hector.api.beans.HSuperColumn; //导入依赖的package包/类
/**
* Set subcolumn values for a specified super column as a batch operation.
*
* @param rowKey the row key of type K
* @param superColumnName the super column name of type SN
* @param columnMap a map of column names type N and column values type V.
* @param txnContext BatchContext for batch operations
*/
private void basicWriteColumns(K rowKey,
SN superColumnName,
Map<N,V> columnMap,
@Nullable BatchContext txnContext) {
// create the subcolumns for the super column
List<HColumn<N,V>> columns = new ArrayList<HColumn<N,V>>(columnMap.size());
for (Map.Entry<N,V> mapEntry : columnMap.entrySet()) {
columns.add(HFactory.createColumn(mapEntry.getKey(),
mapEntry.getValue(),
getSubcolumnNameSerializer(),
getValueSerializer()));
}
HSuperColumn<SN,N,V> superColumn = HFactory.createSuperColumn(superColumnName,
columns,
getSuperColumnNameSerializer(),
subSerializer,
getValueSerializer());
if (txnContext == null) {
insertSuperColumn(rowKey, superColumn);
} else {
insertSuperColumn(rowKey, superColumn, txnContext);
}
}
示例10: insertSuperColumn
import me.prettyprint.hector.api.beans.HSuperColumn; //导入依赖的package包/类
private void insertSuperColumn(K rowKey,
HSuperColumn<SN,N,V> superColumn,
@Nonnull BatchContext txnContext) {
Validate.notNull(txnContext);
Mutator<K> mutator = validateAndGetMutator(txnContext);
mutator.addInsertion(rowKey, getColumnFamily(), superColumn);
// we used to translate hector exceptions into spring exceptions here, but spring dependency was removed
}
示例11: shouldMultiGetAllSuperColumns
import me.prettyprint.hector.api.beans.HSuperColumn; //导入依赖的package包/类
@Test(groups = "system")
public void shouldMultiGetAllSuperColumns() throws Exception {
Keyspace keyspace = getKeyspace();
SuperColumnFamilyTemplate<String,String,String,String> template = new
SuperColumnFamilyTemplate<String,String,String,String>(
keyspace,
SUPER_COLUMN_FAMILY,
StringSerializer.get(),
StringSerializer.get(),
StringSerializer.get(),
StringSerializer.get());
template.multiGetAllSuperColumns(Arrays.asList(ALEX_ROW_KEY, MIKE_ROW_KEY),
new SuperColumnFamilyRowMapper<Object,String,String,String,String>() {
@Override
public Void mapRow(String rowKey, List<HSuperColumn<String,String,String>> hColumns) {
if (LOG.isDebugEnabled()) {
LOG.debug("Mapping SuperColumns: rowKey=" + rowKey +
";hColumns=" + hColumns);
}
if (rowKey.equals(ALEX_ROW_KEY)) {
assertEquals(hColumns.size(), 2);
assertEquals(hColumns.get(0).getName(), "alex");
assertEquals(hColumns.get(1).getName(), "tom");
}
if (rowKey.equals(MIKE_ROW_KEY)) {
assertEquals(hColumns.size(), 1);
assertEquals(hColumns.get(0).getName(), "mike");
}
return null;
}
});
}
示例12: testReadRowAsMap
import me.prettyprint.hector.api.beans.HSuperColumn; //导入依赖的package包/类
@Test(groups={"unit"})
public void testReadRowAsMap() {
Map<String,Map<String,String>> expectedResult = new HashMap<String,Map<String,String>>();
for (String superColumnName : superColumnNames) {
Map<String,String> properties = new HashMap<String,String>();
Iterator<String> itr = columnValues.iterator();
for (String columnName : columnNames) {
properties.put(columnName, itr.next());
}
expectedResult.put(superColumnName, properties);
}
SuperSlice superSlice = mock(SuperSlice.class);
when(executionResult.get()).thenReturn(superSlice);
HSuperColumn superColumn = mock(HSuperColumn.class);
when(superSlice.getSuperColumns()).thenReturn(Arrays.asList(superColumn, superColumn));
when(superColumn.getName()).thenReturn(superColumnNames.get(0)).thenReturn(superColumnNames.get(1));
HColumn column = mock(HColumn.class);
when(superColumn.getColumns()).thenReturn(Arrays.asList(column,column));
when(column.getName()).thenReturn(columnNames.get(0)).
thenReturn(columnNames.get(1)).
thenReturn(columnNames.get(0)).
thenReturn(columnNames.get(1));
when(column.getValue()).
thenReturn(columnValues.get(0)).
thenReturn(columnValues.get(1)).
thenReturn(columnValues.get(0)).
thenReturn(columnValues.get(1));
//=========================
Map<String,Map<String,String>> result = superColumnFamilyTestDao.readRowAsMap(rowKey);
//=========================
assertEquals(result, expectedResult);
}
示例13: testWriteColumnTranslateHectorException
import me.prettyprint.hector.api.beans.HSuperColumn; //导入依赖的package包/类
@Test(groups={"unit"}, expectedExceptions = HectorTransportException.class)
public void testWriteColumnTranslateHectorException() {
when(mutator.addInsertion(eq(rowKey),
eq(columnFamily),
any(HSuperColumn.class))).
thenThrow(new HectorTransportException("test hector exception"));
String propertyValue = columnValue;
//=========================
superColumnFamilyTestDao.writeColumn(rowKey, superColumnName, columnName, propertyValue, txnContext);
//=========================
}
示例14: areSuperColumnsEqual
import me.prettyprint.hector.api.beans.HSuperColumn; //导入依赖的package包/类
@SuppressWarnings({"ControlFlowStatementWithoutBraces"})
private boolean areSuperColumnsEqual(HSuperColumn superColumn1, HSuperColumn superColumn2) {
if (superColumn1 == superColumn2) return true;
if (superColumn2 == null) return false;
if (superColumn1 == null) return false;
if (superColumn1.getClass() != superColumn2.getClass()) return false;
if (!ObjectUtils.equals(superColumn1.getName(), superColumn2.getName())) return false;
if (superColumn1.getColumns().size() != superColumn2.getColumns().size()) return false;
Iterator<HColumn> itr1 = superColumn1.getColumns().iterator();
Iterator<HColumn> itr2 = superColumn2.getColumns().iterator();
while(itr1.hasNext()) {
if (!areColumnsEqual(itr1.next(), itr2.next())) return false;
}
return true;
}
示例15: addSubDelete
import me.prettyprint.hector.api.beans.HSuperColumn; //导入依赖的package包/类
@Override
public <SN, N, V> Mutator<K> addSubDelete( final K key, final String cf, final HSuperColumn<SN, N, V> sc,
final long clock ) {
target.addSubDelete( key, cf, sc, clock );
checkAndFlush();
return this;
}