コード例 #1
0
  public static void main(String[] args)
      throws IOException, ConfigParser.NoSectionException, ConfigParser.NoOptionException,
          ConfigParser.InterpolationException {
    if (args.length != 1) {
      System.out.println("usage: java -jar CreateOtsTable.jar config.ini");
    }
    ConfigParser configParser = new ConfigParser();
    configParser.read(new File(args[0]));

    OTS ots =
        new OTSClient(
            configParser.get("ots", "endpoint"),
            configParser.get("ots", "accessid"),
            configParser.get("ots", "accesskey"),
            configParser.get("ots", "instance_name"));

    String otsTableName = configParser.get("ots", "table_name");

    TableMeta tableMeta = new TableMeta(otsTableName);
    tableMeta.addPrimaryKeyColumn("PK", PrimaryKeyType.STRING);
    CreateTableRequest createTableRequest = new CreateTableRequest(tableMeta);
    createTableRequest.setReservedThroughput(
        new CapacityUnit(
            configParser.getInt("ots", "read_cu"), configParser.getInt("ots", "write_cu")));
    ots.createTable(createTableRequest);
    ots.shutdown();
  }
コード例 #2
0
  @Override
  public RowPrimaryKey call() throws Exception {
    RowPrimaryKey ret = new RowPrimaryKey();
    GetRangeRequest request = new GetRangeRequest();
    request.setRangeRowQueryCriteria(criteria);
    GetRangeResult result = ots.getRange(request);
    List<Row> rows = result.getRows();
    if (rows.isEmpty()) {
      return null; // no data
    }
    Row row = rows.get(0);

    Map<String, PrimaryKeyType> pk = meta.getPrimaryKey();
    for (String key : pk.keySet()) {
      ColumnValue v = row.getColumns().get(key);
      if (v.getType() == ColumnType.INTEGER) {
        ret.addPrimaryKeyColumn(key, PrimaryKeyValue.fromLong(v.asLong()));
      } else {
        ret.addPrimaryKeyColumn(key, PrimaryKeyValue.fromString(v.asString()));
      }
    }
    return ret;
  }