Additional Table Details

It’s not uncommon for a running Adapter to need to know more about a source table or target table than just its name. Maybe the URL to call can’t be derived from the table name, or perhaps you need to know whether it should be HTTP POST or HTTP PATCH when writing to that table. Or maybe you need to remember which database the table is from.

There is typically a timing problem here: your Adapter knows all about the table when it is doing schema work to return a value from getTables(), but at runtime all you have to go on is the table name passed to you as part of the LinkContext.

Regardless of what pieces of information your Adapter needs, you can use the “table details” field to track them. Much like the way scopes behave during record fetching, table details are basically a mailbox your adapter can put things into for later retrieval at runtime.

Putting Values In

You store additional details about a table as part of building your response to getTables() (from SchemaAdapter). What you put into the field is up to you. Leave it empty, use a single value, or put some kind of data structure in.

Table.create('Company').withLabel('Company').withDescription('Definitions of businesses').withTableDetails('/url/to/this/resource').build();

Here’s a more complex example:

class TableInfo {
        String database;
        String format;
}
TableInfo info = TableInfo();
info.database = 'marketing';
info.format = 'XML';
Table.create('Company').withLabel('Company').withDescription('Definitions of businesses').withTableDetails(JSON.serialize(info)).build();

Taking Values Out

You retrieve the value or values at runtime by inspecting either the linkSourceTableDetails or the linkTargetTableDetails properties on your LinkContext.

String urlToCall = linkContext.linkSourceTableDetails; // expecting the details to hold the URL

And our more complex example:

class TableInfo {
        String database;
        String format;
}
TableInfo info = (TableInfo)JSON.deserialize(linkContext.linkTargetTableDetails, TableInfo.class);