本文整理汇总了Java中me.prettyprint.hector.api.mutation.Mutator.insert方法的典型用法代码示例。如果您正苦于以下问题:Java Mutator.insert方法的具体用法?Java Mutator.insert怎么用?Java Mutator.insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类me.prettyprint.hector.api.mutation.Mutator
的用法示例。
在下文中一共展示了Mutator.insert方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insertSingleColumnData
import me.prettyprint.hector.api.mutation.Mutator; //导入方法依赖的package包/类
private void insertSingleColumnData() {
Mutator<String> mutator = HFactory.createMutator(keyspace, stringSerializer);
mutator.addInsertion("jsmith0", COLUMN_FAMILY_NAME_1, HFactory.createStringColumn("first", "John"))
.addInsertion("jsmith0", COLUMN_FAMILY_NAME_1, HFactory.createStringColumn("last", "Smith"))
.addInsertion("jsmith0", COLUMN_FAMILY_NAME_1, HFactory.createStringColumn("middle", "Q"));
mutator.execute();
mutator.insert("jsmith", COLUMN_FAMILY_NAME_1, HFactory.createStringColumn("first", "John"));
ColumnQuery<String, String, String> columnQuery = HFactory.createStringColumnQuery(keyspace);
columnQuery.setColumnFamily(COLUMN_FAMILY_NAME_1).setKey("jsmith").setName("first");
QueryResult<HColumn<String, String>> result = columnQuery.execute();
System.out.println("Read HColumn from cassandra: " + result.get());
System.out.println("Verify on CLI with: get DynamicKeyspace1.Keyspace1['jsmith'] ");
}
示例2: insertSuperColumnData
import me.prettyprint.hector.api.mutation.Mutator; //导入方法依赖的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'] ");
}
示例3: insert
import me.prettyprint.hector.api.mutation.Mutator; //导入方法依赖的package包/类
public void insert(Mutator<String> mutator, String key,
Map<String, String> columnsMap, String columnFamily,
String superColumn) {
List<HColumn<String, String>> columns = new ArrayList<HColumn<String, String>>();
for (String name : columnsMap.keySet()) {
HFactory.createStringColumn(name, columnsMap.get(name));
}
mutator.insert(key, columnFamily, HFactory.createSuperColumn(superColumn, columns, stringSerializer, stringSerializer, stringSerializer));
}
示例4: setColumn
import me.prettyprint.hector.api.mutation.Mutator; //导入方法依赖的package包/类
public void setColumn( Keyspace ko, Object columnFamily, Object key, Object columnName, Object columnValue,
int ttl ) throws Exception {
if ( db_logger.isTraceEnabled() ) {
db_logger.trace( "setColumn cf={} key={} name={} value={}", columnFamily, key, columnName, columnValue );
}
ByteBuffer name_bytes = null;
if ( columnName instanceof List ) {
name_bytes = DynamicComposite.toByteBuffer( ( List<?> ) columnName );
}
else {
name_bytes = bytebuffer( columnName );
}
ByteBuffer value_bytes = null;
if ( columnValue instanceof List ) {
value_bytes = DynamicComposite.toByteBuffer( ( List<?> ) columnValue );
}
else {
value_bytes = bytebuffer( columnValue );
}
HColumn<ByteBuffer, ByteBuffer> col = createColumn( name_bytes, value_bytes, be, be );
if ( ttl != 0 ) {
col.setTtl( ttl );
}
Mutator<ByteBuffer> m = CountingMutator.createFlushingMutator( ko, be );
m.insert( bytebuffer( key ), columnFamily.toString(), col );
}
示例5: insert
import me.prettyprint.hector.api.mutation.Mutator; //导入方法依赖的package包/类
@Override
public <R, T> void insert(Keyspace keyspace, String columnFamily, DataOperationsProfile dataOperationsProfile, RowSerializer<R, T> rowSerializer, R rowKey, T topKey, Object value, int ttl) {
Serializer<R> rowKeySerializer = rowSerializer.getRowKeySerializer();
ByteBuffer serializedRowKey = rowKeySerializer.toByteBuffer(rowKey);
if (serializedRowKey == null) {
return;
}
Mutator<ByteBuffer> mutator = HFactory.createMutator(keyspace, ByteBufferSerializer.get());
StopWatch monitor = monitoring.start(HerculesMonitoringGroup.HERCULES_DD, "Insert " + columnFamily);
int serializedDataSize = 0;
try {
if (value == null) {
mutator.delete(serializedRowKey, columnFamily, topKey, rowSerializer.getTopKeySerializer());
} else {
Serializer serializer = rowSerializer.hasValueSerializer(topKey) ? rowSerializer.getValueSerializer(topKey) : getSerializerForObject(value);
ByteBuffer serializedValue = serializer.toByteBuffer(value);
serializedDataSize += serializedValue.remaining();
HColumn<T, ByteBuffer> column;
if (ttl > 0) {
column = HFactory.createColumn(topKey, serializedValue, ttl, rowSerializer.getTopKeySerializer(), ByteBufferSerializer.get());
} else {
column = HFactory.createColumn(topKey, serializedValue, rowSerializer.getTopKeySerializer(), ByteBufferSerializer.get());
}
mutator.insert(serializedRowKey, columnFamily, column);
}
} finally {
long time = monitor.stop();
if (dataOperationsProfile != null) {
dataOperationsProfile.ms += time;
dataOperationsProfile.bytes += serializedDataSize;
dataOperationsProfile.dbQueries++;
}
}
}
示例6: createHeader
import me.prettyprint.hector.api.mutation.Mutator; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void createHeader(String key, String metricsJson)
throws IOException {
PerfHeader header = new PerfHeader();
header.setStep(60);
PerfArchive.setDefaultArchives(header);
logger.info("createHeader:"+key);
// write info header
List<HColumn<String, String>> columns = Arrays.asList(
HFactory.createStringColumn(UPDATED, "0" ),
HFactory.createStringColumn(STEP, new Integer(header.getStep()).toString() ),
HFactory.createStringColumn(IP, "" )
);
Mutator<byte[]> mutator = createMutator(keyspace, bytesSerializer);
mutator.insert(key.getBytes(), HEADER, HFactory.createSuperColumn(INFO,
columns, stringSerializer, stringSerializer, stringSerializer));
logger.debug("write INFO :: UPDATED:"+new Long(header.getUpdated()).toString()+
" STEP:"+new Integer(header.getStep()).toString() +
" IP:"+ header.getIp());
String keysPending = "info";
// update datasource headers
HashMap<String,HashMap<String,String>> metricMap =
mapper.readValue(metricsJson, new TypeReference<Map<String,Map<String,String>>>() { });
for (String metricKey : metricMap.keySet() ) {
HashMap<String,String> attrs = metricMap.get(metricKey);
String dsType = PerfDatasource.GAUGE;
if (attrs.containsKey(DS_TYPE)) {
dsType = attrs.get(DS_TYPE);
}
columns = Arrays.asList(
HFactory.createStringColumn(TYPE, dsType ),
HFactory.createStringColumn(HEARTBEAT, "300"),
HFactory.createStringColumn(MIN, NAN ),
HFactory.createStringColumn(MAX, NAN ),
HFactory.createStringColumn(LAST, NAN ),
HFactory.createStringColumn(INPUT, NAN ),
HFactory.createStringColumn(PDP, NAN )
);
mutator.insert(key.getBytes(), HEADER, HFactory
.createSuperColumn(metricKey, columns, stringSerializer, stringSerializer, stringSerializer));
keysPending += ", "+metricKey;
}
Map<String,PerfArchive> rraMap = header.getRraMap();
for (String rraKey : rraMap.keySet() ) {
PerfArchive rra = rraMap.get(rraKey);
columns = Arrays.asList(
HFactory.createStringColumn(CF, rra.getConsolidationFunction() ),
HFactory.createStringColumn(XFF, new Double(rra.getXff()).toString() ),
HFactory.createStringColumn(STEPS, new Integer(rra.getSteps()).toString() ),
HFactory.createStringColumn(ROWS, new Integer(rra.getRows()).toString() )
);
mutator.insert(key.getBytes(), HEADER, HFactory.createSuperColumn(
rraKey, columns, stringSerializer, stringSerializer,
stringSerializer));
keysPending += ", "+rraKey;
}
logger.debug("write keys:"+keysPending);
// perform the insert
mutator.execute();
}
示例7: createSingleHeader
import me.prettyprint.hector.api.mutation.Mutator; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public String createSingleHeader(String key, String step, String metricsJson)
throws IOException {
logger.info("createHeader: "+key+" step: "+step+" metrics: "+metricsJson);
PerfHeader header = new PerfHeader();
header.setStep(60);
PerfArchive.setDefaultArchives(header);
// write info header
List<HColumn<String, String>> columns = Arrays.asList(
HFactory.createStringColumn(UPDATED, "0"),
HFactory.createStringColumn(STEP, "60"),
HFactory.createStringColumn(IP, "" )
);
Mutator<byte[]> mutator = createMutator(keyspace, bytesSerializer);
mutator.insert(key.getBytes(), HEADER, HFactory.createSuperColumn(INFO,
columns, stringSerializer, stringSerializer, stringSerializer));
logger.debug("write INFO :: UPDATED:"+new Long(header.getUpdated()).toString()+
" STEP:"+new Integer(header.getStep()).toString() +
" IP:"+ header.getIp());
String keysPending = "info";
//"metrics":"{\"WriteOperations\":{\"display\":true,\"unit\":\"Per Second\",\"dstype\":\"DERIVE\",\"description\":\"Write Operations\"}}"
//"metrics":"{\"ReadOperations\":{\"display\":true,\"unit\":\"per second\",\"dstype\":\"DERIVE\",\"description\":\"Read Operations\"}}"
HashMap<String,HashMap<String,String>> metricMap =
mapper.readValue(metricsJson, new TypeReference<Map<String,Map<String,String>>>() { });
for (String metricKey : metricMap.keySet() ) {
HashMap<String,String> attrs = metricMap.get(metricKey);
String dsType = PerfDatasource.GAUGE;
if (attrs.containsKey(DS_TYPE)) {
dsType = attrs.get(DS_TYPE);
}
columns = Arrays.asList(
HFactory.createStringColumn(TYPE, dsType ),
HFactory.createStringColumn(HEARTBEAT, "300" ),
HFactory.createStringColumn(MIN, NAN ),
HFactory.createStringColumn(MAX, NAN ),
HFactory.createStringColumn(LAST, NAN ),
HFactory.createStringColumn(INPUT, NAN ),
HFactory.createStringColumn(PDP, NAN )
);
mutator.insert(key.getBytes(), HEADER, HFactory
.createSuperColumn(metricKey, columns, stringSerializer, stringSerializer, stringSerializer));
keysPending += ", "+metricKey;
}
Map<String,PerfArchive> rraMap = header.getRraMap();
for (String rraKey : rraMap.keySet() ) {
PerfArchive rra = rraMap.get(rraKey);
columns = Arrays.asList(
HFactory.createStringColumn(CF, rra.getConsolidationFunction() ),
HFactory.createStringColumn(XFF, new Double(rra.getXff()).toString() ),
HFactory.createStringColumn(STEPS, new Integer(rra.getSteps()).toString() ),
HFactory.createStringColumn(ROWS, new Integer(rra.getRows()).toString() )
);
mutator.insert(key.getBytes(), HEADER, HFactory.createSuperColumn(
rraKey, columns, stringSerializer, stringSerializer,
stringSerializer));
keysPending += ", "+rraKey;
}
logger.debug("write keys:"+keysPending);
// perform the insert
mutator.execute();
return "{\"result_code\":200}\n";
}
示例8: putHeader
import me.prettyprint.hector.api.mutation.Mutator; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void putHeader(String key, PerfHeader header, Mutator<byte[]> mutator) {
headerCache.put(key, header);
// write info header
List<HColumn<String, String>> columns = Arrays.asList(
HFactory.createStringColumn(UPDATED, Long.valueOf(header.getUpdated()).toString() ),
HFactory.createStringColumn(STEP, Integer.valueOf(header.getStep()).toString() ),
HFactory.createStringColumn(IP, header.getIp() ));
mutator.insert(key.getBytes(), HEADER, HFactory.createSuperColumn(INFO,
columns, stringSerializer, stringSerializer, stringSerializer));
logger.debug("write INFO :: UPDATED:"+ Long.valueOf(header.getUpdated()) +
" STEP:"+ Integer.valueOf(header.getStep()).toString() +
" IP:"+ header.getIp());
// update datasource headers
Map<String,PerfDatasource> dsMap = header.getDsMap();
for (String dsKey : dsMap.keySet() ) {
PerfDatasource ds = dsMap.get(dsKey);
columns = Arrays.asList(
HFactory.createStringColumn(TYPE, ds.getType() ),
HFactory.createStringColumn(HEARTBEAT, Integer.valueOf(ds.getHeartbeat()).toString() ),
HFactory.createStringColumn(MIN, Double.valueOf(ds.getMin() ).toString() ),
HFactory.createStringColumn(MAX, Double.valueOf(ds.getMax() ).toString() ),
HFactory.createStringColumn(LAST, Double.valueOf(ds.getLast() ).toString() ),
HFactory.createStringColumn(INPUT, Double.valueOf(ds.getInput() ).toString() ),
HFactory.createStringColumn(PDP, Double.valueOf(ds.getPdp() ).toString() )
);
logger.debug("setting ds header last:"+ ds.getLast());
mutator.insert(key.getBytes(), HEADER, HFactory
.createSuperColumn(dsKey, columns, stringSerializer, stringSerializer, stringSerializer));
}
Map<String,Double> cdpMap = header.getCdpMap();
columns = new ArrayList<HColumn<String, String>>();
for (String cdpKey: cdpMap.keySet()) {
String value = cdpMap.get(cdpKey).toString();
if (value != null)
columns.add(HFactory.createStringColumn(cdpKey, value ));
if (cdpKey.contains(LOGBUCKET)) {
logger.debug("CDP PUT: "+cdpKey +" "+cdpMap.get(cdpKey).toString());
}
}
mutator.insert(key.getBytes(), HEADER, HFactory.createSuperColumn(
CDP, columns, stringSerializer, stringSerializer,
stringSerializer));
}
示例9: insertColumn
import me.prettyprint.hector.api.mutation.Mutator; //导入方法依赖的package包/类
public static<K> void insertColumn(Mutator<K> mutator, K key, String columnFamily, ByteBuffer columnName, ByteBuffer columnValue, String ttlAttr) {
mutator.insert(key, columnFamily, createColumn(columnName, columnValue, ttlAttr));
}
示例10: insertSubColumn
import me.prettyprint.hector.api.mutation.Mutator; //导入方法依赖的package包/类
public static<K> void insertSubColumn(Mutator<K> mutator, K key, String columnFamily, String superColumnName, ByteBuffer columnName, ByteBuffer columnValue, String ttlAttr) {
mutator.insert(key, columnFamily, createSuperColumn(superColumnName, columnName, columnValue, ttlAttr));
}
示例11: insertColumn
import me.prettyprint.hector.api.mutation.Mutator; //导入方法依赖的package包/类
public static<K> void insertColumn(Mutator<K> mutator, K key, String columnFamily, ByteBuffer columnName, ByteBuffer columnValue) {
mutator.insert(key, columnFamily, createColumn(columnName, columnValue));
}
示例12: insertSubColumn
import me.prettyprint.hector.api.mutation.Mutator; //导入方法依赖的package包/类
public static<K> void insertSubColumn(Mutator<K> mutator, K key, String columnFamily, String superColumnName, ByteBuffer columnName, ByteBuffer columnValue) {
mutator.insert(key, columnFamily, createSuperColumn(superColumnName, columnName, columnValue));
}