Multiple Tables
Multiple Tables
The DataSource can join main and standard tables using Archibus schema to detect primary and foreign key mappings. When more than one table is used, you need to specify the table name for fields that do not belong to the main table.
DataSource ds = DataSourceFactory.createDataSource();ds.addTable("wr");
ds.addTable("wr");
ds.addTable("em", ds.ROLE_STANDARD);
ds.addField("wr_id");
ds.addField("status");
ds.addField("requestor");
ds.addField("em", "dp_id");
The DataSource will join the tables using primary/foreign key information as defined in Archibus schema. In the generated join, the main table is always on the "many" side and the standard table(s) is on the "one" side – that is, the result set will contain all rows from the main table and the corresponding lookup values from standard tables.
If the list of fields is long, the code can be simplified using the
createDataSourceForFields()
method:
String[] tables = ["wr", "em"];
String[] fields = ["wr.wr_id", "wr.status', "wr.requestor", "em.dp_id"];
DataSource ds = DataSourceFactory.createDataSourceForFields(tables, fields);