getvaluesfromatwodimensionalvalueobjectscripts
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| getvaluesfromatwodimensionalvalueobjectscripts [2024/07/25 12:54] – created amyw | getvaluesfromatwodimensionalvalueobjectscripts [2024/07/25 13:01] (current) – amyw | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| TwoDimensionalValueObject (2DVO) is a object that can hold a two dimensional array of ValueObjects. This makes it convenient to store values from a database table. The data is stored in column format with each column being represented by a vector. There are n of these where n is the number of rows. All these are stored in a single vector " | TwoDimensionalValueObject (2DVO) is a object that can hold a two dimensional array of ValueObjects. This makes it convenient to store values from a database table. The data is stored in column format with each column being represented by a vector. There are n of these where n is the number of rows. All these are stored in a single vector " | ||
| + | That is, the size of the Vector is the number of rows of the data. The organization is: Vector ' | ||
| - | That is, the size of the Vector is the number of rows of the data. That is, the organization is: Vector ' | + | getColumnCount() returns values.size(); |
| Overall, The core idea of 2DVO is to represent each column as a vector and then store these vectors in a main vector. This structure allows for efficient access to rows and columns. | Overall, The core idea of 2DVO is to represent each column as a vector and then store these vectors in a main vector. This structure allows for efficient access to rows and columns. | ||
| + | The following code snippet demonstrates how to extract data from a TwoDimensionalValueObject and populate a java.util.ArrayList with the objects in an object called " | ||
| + | |||
| + | < | ||
| + | //1. Create a variable to store the 2DVO object values in a java.util.ArrayList | ||
| + | |||
| + | var dataArrayList = new java.util.ArrayList(); | ||
| + | |||
| + | //2. Get all data from the database by using Database Raw Table Lookup, the output is in a 2D value object with rows and columns. Asssigne the output to a variable " | ||
| + | |||
| + | var dataResult = 2DVO table output; | ||
| + | |||
| + | // Count the rows of the table using vector.getRowCount() method | ||
| + | |||
| + | rowCount = dataResult.getRowCount(); | ||
| + | |||
| + | for (var i = 0; i < rowCount; i++) { | ||
| + | // If want to get all the objects, each row is one object | ||
| + | var rowData = dataResult.getRow(i); | ||
| + | |||
| + | // below codes use vector.getValueAt(i, | ||
| + | |||
| + | // Create a new object (replace with your actual object type) | ||
| + | var dataObject = new SomeDataObject(); | ||
| + | |||
| + | | ||
| + | // To access properties and populate dataObject | ||
| + | |||
| + | dataObject.property1 =dataResult.getValueAt (i, 0); | ||
| + | dataObject.property2=dataResult.getValueAt(i, | ||
| + | dataObject.property3 =dataResult.getValueAt(i, | ||
| + | ... | ||
| + | dataObject.property6 = dataResult.getValueAt(i, | ||
| + | dataObject.property7 = dataResult.getValueAt(i, | ||
| + | .... | ||
| + | |||
| + | |||
| + | // Add each data object to the dataArrayList | ||
| + | dataArrayList.add(dataObject); | ||
| + | } | ||
| + | |||
| + | </ | ||
| - | The folowing code snippet demonstrates how to extract data from a | ||
| - | TwoDimensionalValueObject and populate a java.util.ArrayList with the objects in an object called " | ||
getvaluesfromatwodimensionalvalueobjectscripts.1721926449.txt.gz · Last modified: by amyw
