Chinaunix首页 | 论坛 | 博客
  • 博客访问: 133587
  • 博文数量: 69
  • 博客积分: 2895
  • 博客等级: 少校
  • 技术积分: 710
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-03 18:05
文章分类

全部博文(69)

文章存档

2010年(69)

我的朋友

分类:

2010-09-11 16:12:58

12)//插入一个superColumn元素
    //不含有内容的superColumn不能同过该方法被创建,会抛出异常

  1.  
  2.     public void test_batch_insert_super_t()
  3.     {
  4.         try {
  5.              tableName    = "Table1";
  6.              keyName        = "superkeytest";
  7.              superColumnFamilyName = "Super1";
  8.             //产生1个superColumn元素
  9.             //首先产生1个column_t的list
  10.             List Clist = new ArrayList();
  11.             //当两个名字一样的时候,先前的会被覆盖
  12.             Clist.add(newcolumn_t("stardcolumninsuper1","stardcolumn1".getBytes(),.currentTimeMillis()));
  13.             Clist.add(newcolumn_t("stardcolumninsuper2","stardcolumn2".getBytes(),.currentTimeMillis()));
  14.             //产生一个superColumn元素
  15.              superColumnName = "superColumn3";
  16.             superColumn_t sct = new superColumn_t(superColumnName , Clist);
  17.             //将这个元素装入到一个superColumn_t的List中
  18.             List SClist = new ArrayList();
  19.             SClist.add(sct);
  20.             //将这个super_column 的list连同对应的superColumnFamily的名字一起放入一个hashmap中
  21.             Map> cfmap = new HashMap>();
  22.             cfmap.put(superColumnFamilyName, SClist);
  23.             //区别于一般的,这里要求的column元素是superColumn元素
  24.             //将整理好的信息关联一个key后生成一个mutation
  25.             batch_mutation_super_t bmst = newbatch_mutation_super_t(tableName,keyName,cfmap);
  26.             boolean block = true;
  27.             //执行这个mutation的插入操作
  28.             cli.batch_insert_superColumn(bmst, block);
  29.         } catch (InvalidRequestException e) {
  30.             e.printStackTrace();
  31.         } catch (UnavailableException e) {
  32.             e.printStackTrace();
  33.         } catch (TException e) {
  34.             e.printStackTrace();
  35.         }
  36.     }
  37.  

13)//获取一个SuperColumn中的信息

  1.  
  2.     public void test_get_superColumn()
  3.     {
  4.          tableName = "Table1";
  5.          keyName = "superkeytest";
  6.          superColumnFamilyName = "Super1";
  7.          superColumnName = "superColumn3";
  8.          path = superColumnFamilyName+":"+superColumnName;
  9.         try {
  10.             superColumn_t sct = cli.get_superColumn(tableName, keyName, path);
  11.             if(sct != null){
  12.                 .out.println("Super Name : "+sct.getName());
  13.                 .out.println("Size : "+sct.getColumnsSize());
  14.                 List clist = sct.getColumns();
  15.             }else{
  16.                 .out.println("super column is empty");
  17.             }
  18.         } catch (InvalidRequestException e) {
  19.             e.printStackTrace();
  20.         } catch (NotFoundException e) {
  21.             e.printStackTrace();
  22.         } catch (TException e) {
  23.             e.printStackTrace();
  24.         } catch ( e) {
  25.             e.printStackTrace();
  26.         }
  27.     }
  28.  

14)//尝试向一个superColumn中添加column元素(就是column_t对象)
   //注意:想superColumnFamily中添加一般的column元素是不被允许的,所以superColumnFamliy中只能有superColumn,而superColumn中只能有一般的column
   //而一般的columnFamily中也只能有一般的column

  1.  
  2.     public void test_insert_standard_to_super()
  3.     {
  4.          tableName = "Table1";
  5.          keyName = "superkeytest";
  6.          superColumnFamily = "Super1";
  7.          superColumnName = "superColumn1";
  8.          columnName = "normal_column";
  9.          value = "normal_column_value_add";
  10.          path = superColumnFamily+":"+superColumnName+":"+columnName;
  11.         try {
  12.             cli.insert(tableName, keyName, path, value.getBytes(),.currentTimeMillis()true);
  13.             //尝试取出这个元素并显示这个元素
  14.             column_t cmt = cli.get_column(tableName, keyName, path);
  15.             if(cmt != null){
  16.                 .out.println("column name : "+cmt.getColumnName());
  17.                 .out.println("column value: "+new(cmt.getValue(),"UTF-8"));
  18.                 .out.println("column time : "+cmt.getTimestamp()+"\n");
  19.             }else{
  20.                 .out.println("column is empty");
  21.             }
  22.         } catch (InvalidRequestException e) {
  23.             e.printStackTrace();
  24.         } catch (UnavailableException e) {
  25.             e.printStackTrace();
  26.         } catch (TException e) {
  27.             e.printStackTrace();
  28.         } catch (NotFoundException e) {
  29.             e.printStackTrace();
  30.         } catch ( e) {
  31.             e.printStackTrace();
  32.         }
  33.     }
  34.  

15)//术语解释:每个key都对应一个Row的信息这个Row的信息又按照columnFamliy 或superColumnFamily分成了很多slice
    //同针对一般的columnFamliy类似,这个方法是获取给定key的某个superColumnFamily的slice,这个slice中的元素都是superColumn

  1.  
  2.     public void test_get_slice_super()
  3.     {
  4.          tableName = "Table1";
  5.          keyName = "superkeytest";
  6.          superColumnFamily = "Super1";
  7.         try {
  8.             List sct = cli.get_slice_super(tableName, keyName, superColumnFamily, 010);
  9.         } catch (InvalidRequestException e) {
  10.             e.printStackTrace();
  11.         } catch (TException e) {
  12.             e.printStackTrace();
  13.         } catch ( e) {
  14.             e.printStackTrace();
  15.         }
  16.     }
  17.  


阅读(698) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~