本文整理汇总了Java中org.apache.cassandra.thrift.Mutation类的典型用法代码示例。如果您正苦于以下问题:Java Mutation类的具体用法?Java Mutation怎么用?Java Mutation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Mutation类属于org.apache.cassandra.thrift包,在下文中一共展示了Mutation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMutation
import org.apache.cassandra.thrift.Mutation; //导入依赖的package包/类
private Mutation getMutation(String columnName, Object value, long timestamp) {
byte[] columnNameBytes;
try {
columnNameBytes = columnName.getBytes("UTF-8");
}
catch (UnsupportedEncodingException exc) {
throw new StorageException("Unsupported character encoding for column name", exc);
}
byte[] valueBytes = convertValueToBytes(value);
Column column = new Column();
column.setName(columnNameBytes);
column.setValue(valueBytes);
column.setTimestamp(timestamp);
ColumnOrSuperColumn columnOrSuperColumn = new ColumnOrSuperColumn();
columnOrSuperColumn.setColumn(column);
Mutation mutation = new Mutation();
mutation.setColumn_or_supercolumn(columnOrSuperColumn);
return mutation;
}
示例2: updateRows
import org.apache.cassandra.thrift.Mutation; //导入依赖的package包/类
public void updateRows(String columnFamily, String primaryKeyName, List<Map<String,Object>> rowUpdateList) {
long timestamp = getNextTimestamp();
for (Map<String,Object> rowUpdateMap: rowUpdateList) {
String rowId = (String) rowUpdateMap.get(primaryKeyName);
if (rowId == null)
rowId = generateRowId();
List<Mutation> rowMutationList = getRowMutationList(columnFamily, rowId);
for (Map.Entry<String,Object> entry: rowUpdateMap.entrySet()) {
String columnName = entry.getKey();
// FIXME: For now we include the primary key data as column data too.
// This is not completely efficient, because it means we're storing that
// data twice in Cassandra, but if you don't do that, then you can't set
// up secondary indexes on the primary key column in order to do range
// queries on that data (not supported currently in 0.7.0, but is targeted
// for the 0.7.1 release). Also there are (arguably pathological) cases
// where if you don't store the data as column data too then the row could
// be incorrectly interpreted as a deleted (tombstoned) row. So to make
// things simpler (at least for now) we just always included the key as
// column data too.
//if (!columnName.equals(primaryKeyName)) {
Mutation mutation = getMutation(columnName, entry.getValue(), timestamp);
rowMutationList.add(mutation);
//}
}
}
}
示例3: createMutation
import org.apache.cassandra.thrift.Mutation; //导入依赖的package包/类
private static Mutation createMutation(byte[] colName, byte[] colValue, long timestamp) {
if (colValue == null) {
colValue = EMPTY_BYTES;
}
Column col = new Column();
col.setName(colName);
col.setValue(colValue);
col.setTimestamp(timestamp);
ColumnOrSuperColumn cosc = new ColumnOrSuperColumn();
cosc.setColumn(col);
Mutation mutation = new Mutation();
mutation.setColumn_or_supercolumn(cosc);
return mutation;
}
示例4: accept
import org.apache.cassandra.thrift.Mutation; //导入依赖的package包/类
@Override
public boolean accept(final OutputHandler handler, final PType<?> pType) {
if (pType instanceof PTableType) {
PTableType pTableType = (PTableType) pType;
PType<?> keyType = pTableType.getKeyType();
PType<?> valueType = pTableType.getValueType();
List<PType> subTypes = valueType.getSubTypes();
if (ByteBuffer.class.equals(keyType.getTypeClass())
&& Collection.class.equals(valueType.getTypeClass())
&& subTypes.size() == 1
&& Mutation.class.equals(subTypes.get(0).getTypeClass())) {
handler.configure(this, pType);
return true;
}
}
return false;
}
示例5: setTypes
import org.apache.cassandra.thrift.Mutation; //导入依赖的package包/类
private void setTypes(Mutation mutation)
{
if (cfType == null)
{
if (mutation.getColumn_or_supercolumn().isSetSuper_column() || mutation.getColumn_or_supercolumn().isSetCounter_super_column())
cfType = CFType.SUPER;
else
cfType = CFType.NORMAL;
if (mutation.getColumn_or_supercolumn().isSetCounter_column() || mutation.getColumn_or_supercolumn().isSetCounter_super_column())
colType = ColType.COUNTER;
else
colType = ColType.NORMAL;
}
}
示例6: run
import org.apache.cassandra.thrift.Mutation; //导入依赖的package包/类
public void run(final ThriftClient client) throws IOException
{
List<CounterColumn> columns = new ArrayList<>();
for (ByteBuffer name : select().select(settings.columns.names))
columns.add(new CounterColumn(name, counteradd.next()));
List<Mutation> mutations = new ArrayList<>(columns.size());
for (CounterColumn c : columns)
{
ColumnOrSuperColumn cosc = new ColumnOrSuperColumn().setCounter_column(c);
mutations.add(new Mutation().setColumn_or_supercolumn(cosc));
}
Map<String, List<Mutation>> row = Collections.singletonMap(type.table, mutations);
final ByteBuffer key = getKey();
final Map<ByteBuffer, Map<String, List<Mutation>>> record = Collections.singletonMap(key, row);
timeWithRetry(new RunOp()
{
@Override
public boolean run() throws Exception
{
client.batch_mutate(record, settings.command.consistencyLevel);
return true;
}
@Override
public int partitionCount()
{
return 1;
}
@Override
public int rowCount()
{
return 1;
}
});
}
示例7: run
import org.apache.cassandra.thrift.Mutation; //导入依赖的package包/类
public void run(final ThriftClient client) throws IOException
{
final ByteBuffer key = getKey();
final List<Column> columns = getColumns();
List<Mutation> mutations = new ArrayList<>(columns.size());
for (Column c : columns)
{
ColumnOrSuperColumn column = new ColumnOrSuperColumn().setColumn(c);
mutations.add(new Mutation().setColumn_or_supercolumn(column));
}
Map<String, List<Mutation>> row = Collections.singletonMap(type.table, mutations);
final Map<ByteBuffer, Map<String, List<Mutation>>> record = Collections.singletonMap(key, row);
timeWithRetry(new RunOp()
{
@Override
public boolean run() throws Exception
{
client.batch_mutate(record, settings.command.consistencyLevel);
return true;
}
@Override
public int partitionCount()
{
return 1;
}
@Override
public int rowCount()
{
return 1;
}
});
}
示例8: update
import org.apache.cassandra.thrift.Mutation; //导入依赖的package包/类
/**
* update
*
* @throws Exception
*/
@Test
public void update() throws Exception {
String KEYSPACE = "mock";
client.set_keyspace(KEYSPACE);
List<Mutation> mutations = new LinkedList<Mutation>();
// <columnFamily,mutations>
Map<String, List<Mutation>> columnfamilyMutaions = new HashMap<String, List<Mutation>>();// keyMutations
// <rowKey,keyMutations>
Map<ByteBuffer, Map<String, List<Mutation>>> rowKeyMutations = new HashMap<ByteBuffer, Map<String, List<Mutation>>>();
long timestamp = System.nanoTime();
//
Column column = new Column();
column.setName(ByteBufferHelper.toByteBuffer("grad"));
column.setValue(ByteBufferHelper.toByteBuffer("9"));
column.setTimestamp(timestamp);
//
ColumnOrSuperColumn cos = new ColumnOrSuperColumn();
cos.setColumn(column);
//
Mutation mutation = new Mutation();
mutation.setColumn_or_supercolumn(cos);
mutations.add(mutation);
String COLUMN_FAMILY = "student";
columnfamilyMutaions.put(COLUMN_FAMILY, mutations);
String ROW_KEY = "Jack";
rowKeyMutations.put(ByteBufferHelper.toByteBuffer(ROW_KEY),
columnfamilyMutaions);
// mutation_map, consistency_level
client.batch_mutate(rowKeyMutations, ConsistencyLevel.ONE);
}
示例9: delete
import org.apache.cassandra.thrift.Mutation; //导入依赖的package包/类
/**
* delete
*
* @throws Exception
*/
@Test
public void delete() throws Exception {
String KEYSPACE = "mock";
client.set_keyspace(KEYSPACE);
List<Mutation> mutations = new ArrayList<Mutation>();
// <columnFamily,mutations>
Map<String, List<Mutation>> columnfamilyMutaions = new HashMap<String, List<Mutation>>();// keyMutations
// <rowKey,keyMutations>
Map<ByteBuffer, Map<String, List<Mutation>>> rowKeyMutations = new HashMap<ByteBuffer, Map<String, List<Mutation>>>();
//
List<ByteBuffer> columns = new ArrayList<ByteBuffer>();
// Add as many supercolumns as you want here
columns.add(ByteBufferHelper.toByteBuffer("grad"));
columns.add(ByteBufferHelper.toByteBuffer("math"));
//
SlicePredicate predicate = new SlicePredicate();
predicate.setColumn_names(columns);
// delete
Deletion deletion = new Deletion();
deletion.setPredicate(predicate);
// timestamp in microseconds
long timestamp = System.nanoTime();
deletion.setTimestamp(timestamp);
Mutation mutation = new Mutation();
mutation.setDeletion(deletion);
mutations.add(mutation);
String COLUMN_FAMILY = "student";
columnfamilyMutaions.put(COLUMN_FAMILY, mutations);
String ROW_KEY = "Jack";
rowKeyMutations.put(ByteBufferHelper.toByteBuffer(ROW_KEY),
columnfamilyMutaions);
// mutation_map, consistency_level
client.batch_mutate(rowKeyMutations, ConsistencyLevel.ONE);
}
示例10: insertPOISpringTraining
import org.apache.cassandra.thrift.Mutation; //导入依赖的package包/类
private void insertPOISpringTraining() throws Exception {
Map<ByteBuffer, Map<String, List<Mutation>>> outerMap = new HashMap<ByteBuffer, Map<String, List<Mutation>>>();
List<Mutation> columnsToAdd = new ArrayList<Mutation>();
long timestamp = System.nanoTime();
String keyName = "Spring Training";
Column descCol = new Column(bytes("desc"));
Column phoneCol = new Column(bytes("phone"));
List<Column> cols = new ArrayList<Column>();
cols.add(descCol);
cols.add(phoneCol);
Map<String, List<Mutation>> innerMap = new HashMap<String, List<Mutation>>();
Mutation columns = new Mutation();
ColumnOrSuperColumn descCosc = new ColumnOrSuperColumn();
SuperColumn sc = new SuperColumn();
sc.name = bytes(CAMBRIA_NAME);
sc.columns = cols;
descCosc.super_column = sc;
columns.setColumn_or_supercolumn(descCosc);
columnsToAdd.add(columns);
String superCFName = "PointOfInterest";
ColumnPath cp = new ColumnPath();
cp.column_family = superCFName;
cp.setSuper_column(CAMBRIA_NAME.getBytes());
cp.setSuper_columnIsSet(true);
innerMap.put(superCFName, columnsToAdd);
outerMap.put(bytes(keyName), innerMap);
client.batch_mutate(outerMap, CL);
LOG.debug("Done inserting Spring Training.");
}
示例11: insertPOICentralPark
import org.apache.cassandra.thrift.Mutation; //导入依赖的package包/类
private void insertPOICentralPark() throws Exception {
Map<ByteBuffer, Map<String, List<Mutation>>> outerMap = new HashMap<ByteBuffer, Map<String, List<Mutation>>>();
List<Mutation> columnsToAdd = new ArrayList<Mutation>();
long ts = System.nanoTime();
String keyName = "Central Park";
Column descCol = new Column(bytes("desc"));
// no phone column for park
List<Column> cols = new ArrayList<Column>();
cols.add(descCol);
Map<String, List<Mutation>> innerMap = new HashMap<String, List<Mutation>>();
Mutation columns = new Mutation();
ColumnOrSuperColumn descCosc = new ColumnOrSuperColumn();
SuperColumn waldorfSC = new SuperColumn();
waldorfSC.name = bytes(WALDORF_NAME);
waldorfSC.columns = cols;
descCosc.super_column = waldorfSC;
columns.setColumn_or_supercolumn(descCosc);
columnsToAdd.add(columns);
String superCFName = "PointOfInterest";
ColumnPath cp = new ColumnPath();
cp.column_family = superCFName;
cp.setSuper_column(WALDORF_NAME.getBytes());
cp.setSuper_columnIsSet(true);
innerMap.put(superCFName, columnsToAdd);
outerMap.put(bytes(keyName), innerMap);
client.batch_mutate(outerMap, CL);
LOG.debug("Done inserting Central Park.");
}
示例12: insertAllHotels
import org.apache.cassandra.thrift.Mutation; //导入依赖的package包/类
public void insertAllHotels() throws Exception {
String columnFamily = "Hotel";
// row keys
String cambriaKey = "AZC_043";
String clarionKey = "AZS_011";
String wKey = "CAS_021";
String waldorfKey = "NYN_042";
// conveniences
Map<ByteBuffer, Map<String, List<Mutation>>> cambriaMutationMap = createCambriaMutation(columnFamily,
cambriaKey);
Map<ByteBuffer, Map<String, List<Mutation>>> clarionMutationMap = createClarionMutation(columnFamily,
clarionKey);
Map<ByteBuffer, Map<String, List<Mutation>>> waldorfMutationMap = createWaldorfMutation(columnFamily,
waldorfKey);
Map<ByteBuffer, Map<String, List<Mutation>>> wMutationMap = createWMutation(columnFamily, wKey);
client.batch_mutate(cambriaMutationMap, CL);
LOG.debug("Inserted " + cambriaKey);
client.batch_mutate(clarionMutationMap, CL);
LOG.debug("Inserted " + clarionKey);
client.batch_mutate(wMutationMap, CL);
LOG.debug("Inserted " + wKey);
client.batch_mutate(waldorfMutationMap, CL);
LOG.debug("Inserted " + waldorfKey);
LOG.debug("Done inserting at " + System.nanoTime());
}
示例13: getRowMutationList
import org.apache.cassandra.thrift.Mutation; //导入依赖的package包/类
private List<Mutation> getRowMutationList(String columnFamily, Object rowKey) {
if (pendingMutations == null)
pendingMutations = new HashMap<ByteBuffer,Map<String,List<Mutation>>>();
ByteBuffer rowKeyBytes;
try {
rowKeyBytes = ByteBuffer.wrap(rowKey.toString().getBytes("UTF-8"));
}
catch (UnsupportedEncodingException exc) {
throw new StorageException("Unsupported character encoding for row ID", exc);
}
Map<String,List<Mutation>> rowIdMap = pendingMutations.get(rowKeyBytes);
if (rowIdMap == null) {
rowIdMap = new HashMap<String,List<Mutation>>();
pendingMutations.put(rowKeyBytes, rowIdMap);
}
List<Mutation> rowMutationList = rowIdMap.get(columnFamily);
if (rowMutationList == null) {
rowMutationList = new ArrayList<Mutation>();
rowIdMap.put(columnFamily, rowMutationList);
}
return rowMutationList;
}
示例14: createDeleteColumnMutation
import org.apache.cassandra.thrift.Mutation; //导入依赖的package包/类
private static Mutation createDeleteColumnMutation(byte[] colName, long timestamp) {
SlicePredicate slicePred = new SlicePredicate();
slicePred.addToColumn_names(ByteBuffer.wrap(colName));
Deletion deletion = new Deletion();
deletion.setPredicate(slicePred);
deletion.setTimestamp(timestamp);
Mutation mutation = new Mutation();
mutation.setDeletion(deletion);
return mutation;
}
示例15: getMutation
import org.apache.cassandra.thrift.Mutation; //导入依赖的package包/类
private static Mutation getMutation(Text word, int sum) {
Column c = new Column();
c.setName(Arrays.copyOf(word.getBytes(), word.getLength()));
c.setValue(ByteBufferUtil.bytes(String.valueOf(sum)));
c.setTimestamp(System.currentTimeMillis());
Mutation m = new Mutation();
m.setColumn_or_supercolumn(new ColumnOrSuperColumn());
m.column_or_supercolumn.setColumn(c);
return m;
}