A data table contains relational data that can be referenced as follows:
from other tables within OpenL Tablets
from Java code through wrappers as Java arrays
through OpenL Tablets run-time API as a field of the Rules
class instance
Data tables can contain Java classes, OpenL Tablets data types, or types loaded in OpenL Tablets from other sources, for example, using the Vocabulary mechanism. For information on data types, see Data Type Table.
The following topics are included in this section:
The following is an example of a data table containing a simple array of numbers:
The first row is the header containing text in the following format:
Data <data table type> <data table name>
In simple data tables, the keyword 'this' must be used for the following types:
all primitive Java types
class java.lang.String
class java.util.Date
all Java classes with a public constructor with a single String parameter
In the example above, information in the data table can be accessed from Java code as shown in the following code example:
int[] num = tableWrapper.getNumbers();
for (int i = 0; i < num.length; i++) {
System.out.println(num[i]);
}
where tableWrapper
is an instance of the wrapper class of the Excel or Word file. For
information on wrappers, see
Wrappers.
Advanced data tables are used for storing information for complex constructions, such as Java beans and data types. For information on data types, see Data Type Table.
The first row of an advanced data table contains text in the following format:
Data <Java bean or data type> <data table name>
Each cell in the second row contains an attribute name of the data type or Java bean. Normally, the second row is hidden to business users.
The third row contains attribute display names. Each row starting with the fourth one contains values for specific data type instances.
The following diagram shows a data type table and a corresponding data table with concrete values below it:
Data tables can use Java beans instead of data types. For example, instead of using a data type table Person, a developer can use the following Java bean:
public class Person {
String name;
String ssn;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSsn() {
return ssn;
}
public void setSsn(String ssn) {
this.ssn = ssn;
}
}
If a Java bean is used, to avoid compilation error, the package where the Java bean is located must be imported using a configuration table as described in Configuration Table.
In Java code, the data table p1
can be accessed as follows:
Person[] persArr = tableWrapper.getP1();
for (int i = 0; i < persArr.length; i++) {
System.out.println(persArr[i].getName() + ' ' + persArr[i].getSsn());
}
where tableWrapper
is an instance of the Excel or Word file wrapper. For information on
wrappers, see
Wrappers.
If a data table contains values defined in another data table, it is important to specify this relationship so that OpenL Tablets can check data integrity during compilation. The relationship between two data tables is defined using foreign keys, a concept that is used in database management systems. Reference to another data table must be specified in an additional row below the row where attribute names are entered. The following format must be used:
> <referenced data table name> <column name of the
referenced data
table>
In the following diagram, the data table cities contains values from the table states. To ensure users enter correct values, a reference to the code column in the states table is defined.
In case user enters invalid state abbreviation in the table cities, OpenL Tablets reports an error.
The target column does not have to be specified if it is the first column in the referenced data table. For example, if a reference was made to the column name in the table states, the following simplified reference could be used:
>states
Note: To ensure users enter correct values, cell data validation lists can be used in Excel limiting the range of values users can type in.
Data tables can be used to specify attributes of referenced objects. An object referenced by a data table is called an aggregated object. To specify an attribute of an aggregated object, the following format must be used in the row containing data table attribute names:
<name of reference to the aggregated object>.<object
attribute>
To illustrate this approach, assume there are two Java classes ZipCode
and Address
defined:
public class ZipCode {
String zip1; // 5-digit part - mandatory
String zip2; // 4-digit part - optional
public String getZip1() {
return zip1;
}
public void setZip1(String zip1) {
this.zip1 = zip1;
}
public String getZip2() {
return zip2;
}
public void setZip2(String zip2) {
this.zip2 = zip2;
}
}
public class Address {
String street;
String city;
ZipCode zip;
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public ZipCode getZip() {
return zip;
}
public void setZip(ZipCode zip) {
this.zip = zip;
}
}
As can be seen from the code, the Address
class contains a reference to the ZipCode
class. A data table can be created that specifies values for both
classes at the same time, for
example:
In the preceding example, columns Zip1 and Zip2 contain values for class ZipCode
referenced by class Address
.
All Java classes referenced in a data table must be imported using a configuration table as described in Configuration Table.
Note: The reference path can be of any arbitrary depth, for example account.person.address.street
.