12)//插入一个superColumn元素
//不含有内容的superColumn不能同过该方法被创建,会抛出异常
public void test_batch_insert_super_t()
{
try {
tableName = "Table1";
keyName = "superkeytest";
superColumnFamilyName = "Super1";
//产生1个superColumn元素
//首先产生1个column_t的list
List Clist = new ArrayList();
//当两个名字一样的时候,先前的会被覆盖
Clist.add(newcolumn_t("stardcolumninsuper1","stardcolumn1".getBytes(),.currentTimeMillis()));
Clist.add(newcolumn_t("stardcolumninsuper2","stardcolumn2".getBytes(),.currentTimeMillis()));
//产生一个superColumn元素
superColumnName = "superColumn3";
superColumn_t sct = new superColumn_t(superColumnName , Clist);
//将这个元素装入到一个superColumn_t的List中
List SClist = new ArrayList();
SClist.add(sct);
//将这个super_column 的list连同对应的superColumnFamily的名字一起放入一个hashmap中
Map> cfmap = new HashMap>();
cfmap.put(superColumnFamilyName, SClist);
//区别于一般的,这里要求的column元素是superColumn元素
//将整理好的信息关联一个key后生成一个mutation
batch_mutation_super_t bmst = newbatch_mutation_super_t(tableName,keyName,cfmap);
boolean block = true;
//执行这个mutation的插入操作
cli.batch_insert_superColumn(bmst, block);
} catch (InvalidRequestException e) {
e.printStackTrace();
} catch (UnavailableException e) {
e.printStackTrace();
} catch (TException e) {
e.printStackTrace();
}
}
13)//获取一个SuperColumn中的信息
public void test_get_superColumn()
{
tableName = "Table1";
keyName = "superkeytest";
superColumnFamilyName = "Super1";
superColumnName = "superColumn3";
path = superColumnFamilyName+":"+superColumnName;
try {
superColumn_t sct = cli.get_superColumn(tableName, keyName, path);
if(sct != null){
.out.println("Super Name : "+sct.getName());
.out.println("Size : "+sct.getColumnsSize());
List clist = sct.getColumns();
}else{
.out.println("super column is empty");
}
} catch (InvalidRequestException e) {
e.printStackTrace();
} catch (NotFoundException e) {
e.printStackTrace();
} catch (TException e) {
e.printStackTrace();
} catch ( e) {
e.printStackTrace();
}
}
14)//尝试向一个superColumn中添加column元素(就是column_t对象)
//注意:想superColumnFamily中添加一般的column元素是不被允许的,所以superColumnFamliy中只能有superColumn,而superColumn中只能有一般的column
//而一般的columnFamily中也只能有一般的column
public void test_insert_standard_to_super()
{
tableName = "Table1";
keyName = "superkeytest";
superColumnFamily = "Super1";
superColumnName = "superColumn1";
columnName = "normal_column";
value = "normal_column_value_add";
path = superColumnFamily+":"+superColumnName+":"+columnName;
try {
cli.insert(tableName, keyName, path, value.getBytes(),.currentTimeMillis(), true);
//尝试取出这个元素并显示这个元素
column_t cmt = cli.get_column(tableName, keyName, path);
if(cmt != null){
.out.println("column name : "+cmt.getColumnName());
.out.println("column value: "+new(cmt.getValue(),"UTF-8"));
.out.println("column time : "+cmt.getTimestamp()+"\n");
}else{
.out.println("column is empty");
}
} catch (InvalidRequestException e) {
e.printStackTrace();
} catch (UnavailableException e) {
e.printStackTrace();
} catch (TException e) {
e.printStackTrace();
} catch (NotFoundException e) {
e.printStackTrace();
} catch ( e) {
e.printStackTrace();
}
}
15)//术语解释:每个key都对应一个Row的信息这个Row的信息又按照columnFamliy 或superColumnFamily分成了很多slice
//同针对一般的columnFamliy类似,这个方法是获取给定key的某个superColumnFamily的slice,这个slice中的元素都是superColumn
public void test_get_slice_super()
{
tableName = "Table1";
keyName = "superkeytest";
superColumnFamily = "Super1";
try {
List sct = cli.get_slice_super(tableName, keyName, superColumnFamily, 0, 10);
} catch (InvalidRequestException e) {
e.printStackTrace();
} catch (TException e) {
e.printStackTrace();
} catch ( e) {
e.printStackTrace();
}
}
阅读(698) | 评论(0) | 转发(0) |