本文整理汇总了Java中org.apache.cassandra.thrift.ColumnPath类的典型用法代码示例。如果您正苦于以下问题:Java ColumnPath类的具体用法?Java ColumnPath怎么用?Java ColumnPath使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ColumnPath类属于org.apache.cassandra.thrift包,在下文中一共展示了ColumnPath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getColumnValue
import org.apache.cassandra.thrift.ColumnPath; //导入依赖的package包/类
private String getColumnValue(String ks, String cf, String colName, String key, String validator)
throws AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, IOException
{
Cassandra.Client client = getClient();
client.set_keyspace(ks);
ByteBuffer key_user_id = ByteBufferUtil.bytes(key);
long timestamp = System.currentTimeMillis();
ColumnPath cp = new ColumnPath(cf);
ColumnParent par = new ColumnParent(cf);
cp.column = ByteBufferUtil.bytes(colName);
// read
ColumnOrSuperColumn got = client.get(key_user_id, cp, ConsistencyLevel.ONE);
return parseType(validator).getString(got.getColumn().value);
}
示例3: open
import org.apache.cassandra.thrift.ColumnPath; //导入依赖的package包/类
public void open() throws Exception {
TSocket sock = new TSocket(Config.getCassandraIP(), Config.getCassandraPort());
sock.setTimeout(1000000);
transport = new TFramedTransport(sock);
client = new Cassandra.Client(new TBinaryProtocol(transport));
transport.open();
client.set_keyspace(Config.getCassandraKeyspace());
cl = ConsistencyLevel.valueOf(Config.getCassandraConsistencyLevel());
writeColumn = new Column();
writeColumnFamily = new ColumnParent(Config.getCassandraColumnFamily());
columnPath = new ColumnPath(Config.getCassandraColumnFamily());
bytesRead = bytesWritten = readLatency = writeLatency = 0;
}
示例4: getColumnValue
import org.apache.cassandra.thrift.ColumnPath; //导入依赖的package包/类
private String getColumnValue(String ks, String cf, String colName, String key, String validator)
throws AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, IOException
{
Cassandra.Client client = getClient();
client.set_keyspace(ks);
ByteBuffer key_user_id = ByteBufferUtil.bytes(key);
ColumnPath cp = new ColumnPath(cf);
cp.column = ByteBufferUtil.bytes(colName);
// read
ColumnOrSuperColumn got = client.get(key_user_id, cp, ConsistencyLevel.ONE);
return parseType(validator).getString(got.getColumn().value);
}
示例5: remove
import org.apache.cassandra.thrift.ColumnPath; //导入依赖的package包/类
/**
* remove
*
* 當remove後,key還會存在,所以再insert會無法新增
*
* @throws Exception
*/
@Test
public void remove() throws Exception {
String KEYSPACE = "mock";
client.set_keyspace(KEYSPACE);
//
String COLUMN_FAMILY = "student";
ColumnPath columnPath = new ColumnPath(COLUMN_FAMILY);
//
String ROW_KEY = "Jack";
// key, column_path, timestamp, consistency_level
client.remove(ByteBufferHelper.toByteBuffer(ROW_KEY), columnPath,
System.nanoTime(), ConsistencyLevel.ONE);
}
示例6: insertPOISpringTraining
import org.apache.cassandra.thrift.ColumnPath; //导入依赖的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.");
}
示例7: insertPOICentralPark
import org.apache.cassandra.thrift.ColumnPath; //导入依赖的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.");
}
示例8: commitDeletes
import org.apache.cassandra.thrift.ColumnPath; //导入依赖的package包/类
private void commitDeletes(DBTransaction dbTran, long timestamp) {
Map<String, Set<ByteBuffer>> rowDeleteMap = CassandraTransaction.getRowDeletionMap(dbTran);
if (rowDeleteMap.size() == 0) {
return;
}
// Iterate through all ColumnFamilies
for (String colFamName : rowDeleteMap.keySet()) {
// Delete each row in this key set.
Set<ByteBuffer> rowKeySet = rowDeleteMap.get(colFamName);
for (ByteBuffer rowKey : rowKeySet) {
removeRow(timestamp, rowKey, new ColumnPath(colFamName));
}
}
}
示例9: 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;
}
示例10: 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"));
}
示例11: QueryIpUser
import org.apache.cassandra.thrift.ColumnPath; //导入依赖的package包/类
/**
* Query and Check item is exist or not
*
* return times of item
*/
public int QueryIpUser(String ip, String name){
String IP_KEY = ip;
String NAME_SUPER_KEY = name;
String COLUMN_NAME = "times";
String COLUMN_FAMILY = "IpUser";
try{
ColumnPath columnPath = new ColumnPath();
columnPath.column_family = COLUMN_FAMILY;
columnPath.super_column = this.cassandraUtil.toByteBuffer(NAME_SUPER_KEY);
ColumnOrSuperColumn columnOrSuperColumn = client.get(this.cassandraUtil.toByteBuffer(IP_KEY), columnPath, ConsistencyLevel.ONE);
SuperColumn superColumn = columnOrSuperColumn.getSuper_column();
List<Column> columns = superColumn.getColumns();
for(Column col : columns) {
String title = new String(col.getName(), "UTF-8") ;
if(title.equals(COLUMN_NAME)){
return Integer.parseInt(new String(col.getValue(), "UTF-8")); // get "times" column and return
}
}
}catch(Exception e){
return 0;
}
return 0;
}
示例12: QueryUserIp
import org.apache.cassandra.thrift.ColumnPath; //导入依赖的package包/类
/**
* Query and Check item is exist or not
*
* return times of item
*/
public int QueryUserIp(String ip, String name){
String NAME_KEY = name;
String IP_SUPER_KEY = ip;
String COLUMN_NAME = "times";
String COLUMN_FAMILY = "UserIp";
try{
ColumnPath columnPath = new ColumnPath();
columnPath.column_family = COLUMN_FAMILY;
columnPath.super_column = this.cassandraUtil.toByteBuffer(IP_SUPER_KEY);
ColumnOrSuperColumn columnOrSuperColumn = client.get(this.cassandraUtil.toByteBuffer(NAME_KEY), columnPath, ConsistencyLevel.ONE);
SuperColumn superColumn = columnOrSuperColumn.getSuper_column();
List<Column> columns = superColumn.getColumns();
for(Column col : columns) {
String title = new String(col.getName(), "UTF-8") ;
if(title.equals(COLUMN_NAME)){
return Integer.parseInt(new String(col.getValue(), "UTF-8")); // get "times" column and return
}
}
}catch(Exception e){
return 0;
}
return 0;
}
示例13: QueryBookIp
import org.apache.cassandra.thrift.ColumnPath; //导入依赖的package包/类
/**
* Query and Check BookIp
*
* return times of column is exist, 0 or not
*/
public int QueryBookIp(String bookid, String ip) {
String BOOKID_KEY = bookid;
String IP_SUPER_KEY = ip;
String COLUMN_NAME = "times";
String COLUMN_FAMILY = "BookIp";
try {
ColumnPath columnPath = new ColumnPath();
columnPath.column_family = COLUMN_FAMILY;
columnPath.super_column = this.cassandraUtil.toByteBuffer(IP_SUPER_KEY);
ColumnOrSuperColumn columnOrSuperColumn = client.get(this.cassandraUtil.toByteBuffer(BOOKID_KEY), columnPath,ConsistencyLevel.ONE);
SuperColumn superColumn = columnOrSuperColumn.getSuper_column();
List<Column> columns = superColumn.getColumns();
for (Column col : columns) {
String title = new String(col.getName(), "UTF-8");
if (title.equals(COLUMN_NAME)) {
return Integer.parseInt(new String(col.getValue(), "UTF-8"));
}
}
} catch (Exception e) {
return 0;
}
return 0;
}
示例14: QueryBookUser
import org.apache.cassandra.thrift.ColumnPath; //导入依赖的package包/类
/**
* Query and Check BookUser
*
* return times of column is exist, 0 or not
*/
public int QueryBookUser(String bookid, String user) {
String BOOKID_KEY = bookid;
String USER_SUPER_KEY = user;
String COLUMN_NAME = "times";
String COLUMN_FAMILY = "BookUser";
try{
ColumnPath columnPath = new ColumnPath();
columnPath.column_family = COLUMN_FAMILY;
columnPath.super_column = this.cassandraUtil.toByteBuffer(USER_SUPER_KEY);
ColumnOrSuperColumn columnOrSuperColumn = client.get(this.cassandraUtil.toByteBuffer(BOOKID_KEY), columnPath, ConsistencyLevel.ONE);
SuperColumn superColumn = columnOrSuperColumn.getSuper_column();
List<Column> columns = superColumn.getColumns();
for(Column col : columns) {
String title = new String(col.getName(), "UTF-8");
if(title.equals(COLUMN_NAME)) {
return Integer.parseInt(new String(col.getValue(), "UTF-8"));
}
}
}catch(Exception e) {
return 0;
}
return 0;
}
示例15: QueryIpBookPage
import org.apache.cassandra.thrift.ColumnPath; //导入依赖的package包/类
/**
* Query and Check IpBookPage
*
* return times of column is exist, 0 or not
*/
public int QueryIpBookPage(String ip, String book) {
String IP_KEY = ip;
String BOOKID_SUPER_KEY = book;
String COLUMN_FAMILY = "IpBookPage";
String COLUMN_NAME = "times";
try{
ColumnPath columnPath = new ColumnPath();
columnPath.column_family = COLUMN_FAMILY;
columnPath.super_column = this.cassandraUtil.toByteBuffer(BOOKID_SUPER_KEY);
ColumnOrSuperColumn columnOrSuperColumn = client.get(this.cassandraUtil.toByteBuffer(IP_KEY), columnPath, ConsistencyLevel.ONE);
SuperColumn superColumn = columnOrSuperColumn.getSuper_column();
List<Column> columns = superColumn.getColumns();
for(Column col : columns) {
String title = new String(col.getName(), "UTF-8");
if(title.equals(COLUMN_NAME)) {
return Integer.parseInt(new String(col.getValue(), "UTF-8"));
}
}
}catch(Exception e){
return 0;
}
return 0;
}