Get Rows
You can retrieve single row or multiple rows of data from a table in the Catalyst Data Store. You can fetch the rows by passing the unique Table ID of table to the getTable() method as shown in the sample code below.
Get a Single Row
You can fetch a single row of data from a table using the getRow() method. You must pass the unique Row ID of the row that you require to be fetched to this method as shown below.
You must first fetch a base object instance using getInstance(). Using the base object instance, you must fetch a table instance that can be used to fetch the row.
Ensure the following packages are imported:
copyimport com.zc.component.object.ZCObject; import com.zc.component.object.ZCRowObject; import com.zc.component.object.ZCTable;
copy//Create a base object instance ZCObject ZCObject obj = ZCObject.getInstance(); //Get a table instance referring to the table ID using the base object ZCTable tab = obj.getTable(1510000000110121L); //Fetch a single row from the table by passing the Row ID ZCRowObject row = tab.getRow(1510000000108103L);
Get All Rows Through Pagination
You can retrieve all the rows from a table in the Data Store by incorporating pagination in your code using the ZCRowPagedResponse class. Pagination allows you to fetch the rows of a table in batches or pages through iterations.
For example, if you require the rows to be fetched in batches of 100 as individual pages, you can define a variable for the maximum rows to be fetched in each page and specify the count. The sample code below assigns maxRows as 100.
Additionally, after each execution of the loop, you will receive a token string in the response that authorizes the subsequent fetching of data. You can fetch this token through the getNextToken() method, and pass it as the value for nextToken during the subsequent iteration, as shown in the code below. During the first execution of the loop, the value for the nextToken string is assigned as null.
This iteration is executed until all the rows fetched, which is validated by the moreRecordsAvailable() method.
You can specify the table name and the names of the columns to be fetched as shown in the sample code.
Ensure the following packages are imported:
copyimport com.zc.component.object.ZCObject; import com.zc.component.object.ZCRowObject; import com.zc.component.object.ZCRowPagedResponse;
copyString nextToken = null; //Declare the value for nextToken as null for the first iteration ZCRowPagedResponse pagedResp; //Define the paged response object Long maxRows = 100; //Define the maximum rows to be fetched in a single page do { pagedResp = ZCObject.getInstance().getTable(empDetails).getPagedRows(nextToken, maxRows); //Specify the table name and fetch the paged response by passing nextToken and maxRows //Fetch the columns from the table by passing the column names for(ZCRowObject row : pagedResp.getRows()) { basicIO.write("Employee ID: " +row.get("empID") + ","); basicIO.write("Name: " +row.get("empName") + ","); basicIO.write("Department: " +row.get("empDept") + ","); } //Validate the iteration and pass the token string obtained in the response for the next iteration if(pagedResp.moreRecordsAvailable()) { nextToken = pagedResp.getNextToken(); } } while(pagedResp.moreRecordsAvailable());
Last Updated 2023-09-03 01:06:41 +0530 +0530
Yes
No
Send your feedback to us