Changes between Version 1 and Version 2 of NCHCCloudCourse100929_4_HBEX2


Ignore:
Timestamp:
Sep 28, 2010, 6:51:43 PM (14 years ago)
Author:
waue
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • NCHCCloudCourse100929_4_HBEX2

    v1 v2  
    1414{{{
    1515#!java
     16
    1617package org.nchc.hbase;
    1718
     
    2627
    2728public class PutData {
    28         public PutData(String tablename, String row, String family, String column,
    29                         String value) {
    30                 try {
    31                         putData(tablename, row, family, column, value);
    32                 } catch (IOException e) {
    33                         e.printStackTrace();
    34                 }
    35         }
     29  public PutData(String tablename, String row, String family, String column,
     30      String value) {
     31    try {
     32      putData(tablename, row, family, column, value);
     33    } catch (IOException e) {
     34      e.printStackTrace();
     35    }
     36  }
    3637
    37         static public void putData(String tablename, String row, String family,
    38                         String column, String value) throws IOException {
    39                 // HBaseConfiguration 能接收 hbase-site.xml 的設定值
    40                 HBaseConfiguration config = new HBaseConfiguration();
    41                 // 檔案的操作則使用 HBaseAdmin
    42                 HTable table = new HTable(config, tablename);
     38  static public void putData(String tablename, String row, String family,
     39      String column, String value) throws IOException {
     40    // HBaseConfiguration 能接收 hbase-site.xml 的設定值
     41    HBaseConfiguration config = new HBaseConfiguration();
     42    // 檔案的操作則使用 HBaseAdmin
     43    HTable table = new HTable(config, tablename);
    4344
    44                 byte[] brow = Bytes.toBytes(row);
    45                 byte[] bfamily = Bytes.toBytes(family);
    46                 byte[] bcolumn = Bytes.toBytes(column);
    47                 byte[] bvalue = Bytes.toBytes(value);
     45    byte[] brow = Bytes.toBytes(row);
     46    byte[] bfamily = Bytes.toBytes(family);
     47    byte[] bcolumn = Bytes.toBytes(column);
     48    byte[] bvalue = Bytes.toBytes(value);
    4849
    49                 Put p = new Put(brow);
    50                 p.add(bfamily, bcolumn, bvalue);
     50    Put p = new Put(brow);
     51    p.add(bfamily, bcolumn, bvalue);
    5152
    52                 table.put(p);
    53                 System.out.println("Put data :\"" + value + "\" to Table: " + tablename
    54                                 + "'s " + family + ":" + column);
     53    table.put(p);
     54    System.out.println("Put data :\"" + value + "\" to Table: " + tablename
     55        + "'s " + family + ":" + column);
    5556
    56                 table.close();
    57         }
     57    table.close();
     58  }
    5859
    59         static public void main(String argv[]) throws IOException {
    60                
    61                 String[] args = new GenericOptionsParser(new Configuration(), argv)
    62                                 .getRemainingArgs();
    63                 if (args.length < 5) {
    64                         System.out.println("PutData <TableName> <Row> <Family> <Qualifier> <Value>");
    65                         return;
    66                 }
    67                 putData(args[0],args[1],args[2],args[3],args[4]);
    68         }
     60  static public void main(String argv[]) throws IOException {
     61            // eclipse only
     62          String[] argt = {"ex1Table", "row221", "Detail", "c1", "my value good"};
     63          argv = argt;
     64         
     65    String[] args = new GenericOptionsParser(new Configuration(), argv)
     66        .getRemainingArgs();
     67    if (args.length < 5) {
     68      System.out.println("PutData <TableName> <Row> <Family> <Qualifier> <Value>");
     69      return;
     70    }
     71    putData(args[0],args[1],args[2],args[3],args[4]);
     72  }
    6973}
    7074