簡體   English   中英

如何從Oracle NoSQL表獲取所有行?

[英]How to get all rows from Oracle NoSQL table?

如何使用Java中的TableAPI從Oracle NoSQL表中獲取所有行? 我可以通過主鍵值獲取記錄。 例:

    TableAPI tableH = kvstore.getTableAPI();
    Table myTable = tableH.getTable("myTable");
    PrimaryKey key = myTable.createPrimaryKey();
    key.put("item", "Hat");

    List<Row> myRows = null;
    try {
        myRows = tableH.multiGet(key, null, null);
    } catch (ConsistencyException ce) {
    } catch (RequestTimeoutException re) {
    }
    for (Row theRow: myRows) {
        String itemType = theRow.get("item").asString().get();
    }
    System.out.println(itemType);

但是我無法獲得主鍵值。

要修改您的示例,您可以通過為表使用空的PrimaryKey並使用TableAPI.tableIterator()方法之一來獲取所有行。 關於示例的注釋TableAPI.getTable()將執行遠程調用,因此應該隱藏並重用Table句柄。

TableAPI tableH = kvstore.getTableAPI();
/* 
 * get the Table, but be careful about doing this frequently,
 * as it performs a remote call.
 */
Table myTable = tableH.getTable("myTable");
PrimaryKey key = myTable.createPrimaryKey();

try {

    /* create and use an iterator on the Row value */
    TableIterator<Row> rowIter = tableH.tableIterator(key, null, null);
    while (rowIter.hasNext()) {
        Row row = rowIter.next();
        /* do something */
    }

    /* 
     * Or...
     * create and use an iterator on the PrimaryKey values.
     * This is much faster than fetching the data as well if
     * you only need fields in the primary key.
     */
    TableIterator<PrimaryKey> keyIter =
              tableH.tableKeysIterator(key, null, null);
    while (keyIter.hasNext()) {
        PrimaryKey key = rowIter.next();
        /* do something */
    }
} catch (FaultException fe) {
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM