本文整理汇总了Java中org.apache.cassandra.thrift.ColumnPath.setColumn方法的典型用法代码示例。如果您正苦于以下问题:Java ColumnPath.setColumn方法的具体用法?Java ColumnPath.setColumn怎么用?Java ColumnPath.setColumn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.cassandra.thrift.ColumnPath
的用法示例。
在下文中一共展示了ColumnPath.setColumn方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import org.apache.cassandra.thrift.ColumnPath; //导入方法依赖的package包/类
/**
* get 讀取1個column
*
* @throws Exception
*/
@Test
public void get() throws Exception {
String KEYSPACE = "mock";
client.set_keyspace(KEYSPACE);
// 讀取1個column
String COLUMN_FAMILY = "student";
ColumnPath columnPath = new ColumnPath(COLUMN_FAMILY);
//
String COLUMN = "grad";
columnPath.setColumn(ByteBufferHelper.toByteBuffer(COLUMN));
String ROW_KEY = "Jack";
// key, column_path, consistency_level
ColumnOrSuperColumn cos = client.get(
ByteBufferHelper.toByteBuffer(ROW_KEY), columnPath,
ConsistencyLevel.ONE);// NotFoundException
Column column = cos.getColumn();
System.out.println(ROW_KEY + ", "
+ ByteHelper.toString(column.getName()) + ": "
+ ByteHelper.toString(column.getValue()) + ", "
+ column.getTimestamp());
// Jack, grad: 5, 1380932164492000
}
示例2: authorize
import org.apache.cassandra.thrift.ColumnPath; //导入方法依赖的package包/类
@Override
public EnumSet<Permission> authorize(ByteBuffer inputKey, AuthenticatedUser user,
List<Object> resources, CassandraServer server) {
EnumSet<Permission> authorized = Permission.NONE;
readPolicyFile();
ConsistencyLevel consistency_level = ConsistencyLevel.findByValue(1);
try {
// 1. Read patient's name
ByteBuffer key1 = ByteBuffer.allocate(1024);
key1.put("name".getBytes(ISO_8859_1));
ColumnPath column_path1 = new ColumnPath();
column_path1.setColumn_family("Patient");
column_path1.setColumn("username".getBytes(ISO_8859_1));
server.get(key1, column_path1, consistency_level);
ByteBuffer key = ByteBuffer.allocate(1024);
key.put("curr_patients".getBytes(ISO_8859_1));
ColumnPath column_path = new ColumnPath();
column_path.setColumn_family("Doctor");
column_path.setColumn("username".getBytes(ISO_8859_1));
server.get(key, column_path, consistency_level);
} catch (Exception exp) {
exp.printStackTrace();
}
return authorized;
}
示例3: testInProcessCassandraServer
import org.apache.cassandra.thrift.ColumnPath; //导入方法依赖的package包/类
@Test
public void testInProcessCassandraServer()
throws UnsupportedEncodingException, InvalidRequestException,
UnavailableException, TimedOutException, TException,
NotFoundException, AuthenticationException, AuthorizationException {
Cassandra.Client client = getClient();
client.set_keyspace("Keyspace1");
String key_user_id = "1";
long timestamp = System.currentTimeMillis();
// insert
ColumnParent colParent = new ColumnParent("Standard1");
Column column = new Column(ByteBufferUtil.bytes("name"),
ByteBufferUtil.bytes("Ran"), timestamp);
client.insert(ByteBufferUtil.bytes(key_user_id), colParent, column, ConsistencyLevel.ONE);
// read
ColumnPath cp = new ColumnPath("Standard1");
cp.setColumn(ByteBufferUtil.bytes("name"));
ColumnOrSuperColumn got = client.get(ByteBufferUtil.bytes(key_user_id), cp,
ConsistencyLevel.ONE);
// assert
assertNotNull("Got a null ColumnOrSuperColumn", got);
assertEquals("Ran", new String(got.getColumn().getValue(), "utf-8"));
}
示例4: main
import org.apache.cassandra.thrift.ColumnPath; //导入方法依赖的package包/类
public static void main(String[] args) throws UnsupportedEncodingException,
InvalidRequestException, UnavailableException, TimedOutException,
TException, NotFoundException {
TTransport tr = new TSocket(HOST, PORT);
//new default in 0.7 is framed transport
TFramedTransport tf = new TFramedTransport(tr);
TProtocol proto = new TBinaryProtocol(tf);
Cassandra.Client client = new Cassandra.Client(proto);
tf.open();
client.set_keyspace("Keyspace1");
String cfName = "Standard1";
ByteBuffer userIDKey = ByteBuffer.wrap("1".getBytes()); //this is a row key
// Clock clock = new Clock(System.currentTimeMillis());
ColumnParent cp = new ColumnParent(cfName);
//insert the name column
log.debug("Inserting row for key {}" , userIDKey.toString());
Column nameCol = new Column(ByteBuffer.wrap("name".getBytes(UTF8)));
nameCol.setValue(ByteBuffer.wrap("George Clinton".getBytes()));
client.insert(userIDKey, cp, nameCol, CL);
//insert the Age column
Column ageCol = new Column(ByteBuffer.wrap("name".getBytes(UTF8)));
ageCol.setValue(ByteBuffer.wrap("69".getBytes()));
client.insert(userIDKey, cp, ageCol, CL);
log.debug("Row insert done.");
// read just the Name column
log.debug("Reading Name Column:");
//create a representation of the Name column
ColumnPath colPathName = new ColumnPath(cfName);
colPathName.setColumn("name".getBytes(UTF8));
Column col = client.get(userIDKey, colPathName,
CL).getColumn();
/*LOG.debug("Column name: " + new String(col.name, UTF8));
LOG.debug("Column value: " + new String(col.value, UTF8));
LOG.debug("Column timestamp: " + col.clock.timestamp);*/
//create a slice predicate representing the columns to read
//start and finish are the range of columns--here, all
SlicePredicate predicate = new SlicePredicate();
SliceRange sliceRange = new SliceRange();
sliceRange.setStart(new byte[0]);
sliceRange.setFinish(new byte[0]);
predicate.setSlice_range(sliceRange);
log.debug("Complete Row:");
// read all columns in the row
ColumnParent parent = new ColumnParent(cfName);
List<ColumnOrSuperColumn> results =
client.get_slice(userIDKey,
parent, predicate, CL);
//loop over columns, outputting values
for (ColumnOrSuperColumn result : results) {
Column column = result.column;
log.info("Column: {}, Value: {}", new String(column.getName(), UTF8), new String(column.getValue(), UTF8));
}
tf.close();
log.debug("All done.");
}
示例5: insertByCityIndex
import org.apache.cassandra.thrift.ColumnPath; //导入方法依赖的package包/类
private void insertByCityIndex(String rowKey, String hotelName) throws Exception {
long timestamp = System.nanoTime();
Column nameCol = new Column(bytes(hotelName));
ColumnOrSuperColumn nameCosc = new ColumnOrSuperColumn();
nameCosc.column = nameCol;
Mutation nameMut = new Mutation();
nameMut.column_or_supercolumn = nameCosc;
// set up the batch
Map<String, Map<String, List<Mutation>>> mutationMap = new HashMap<String, Map<String, List<Mutation>>>();
Map<String, List<Mutation>> muts = new HashMap<String, List<Mutation>>();
List<Mutation> cols = new ArrayList<Mutation>();
cols.add(nameMut);
String columnFamily = "HotelByCity";
muts.put(columnFamily, cols);
// outer map key is a row key
// inner map key is the column family name
mutationMap.put(rowKey, muts);
// create representation of the column
ColumnPath cp = new ColumnPath(columnFamily);
cp.setColumn(hotelName.getBytes(UTF8));
ColumnParent parent = new ColumnParent(columnFamily);
// here, the column name IS the value (there's no value)
Column col = new Column(bytes(hotelName));
client.insert(bytes(rowKey), parent, col, CL);
LOG.debug("Inserted HotelByCity index for " + hotelName);
}