Datasource Data Connection
datasourcedataconnection
Properties
Name | Type | Required | Description |
|---|---|---|---|
datasource | yes | reference to the data source that this data definition should use to generate its data | |
table | string | yes | The name of the table that provides the data |
key | string | no | If this data definition is generating data relating to an entity then this is the column name that contains the entities id |
prefix | string | no | The prefix value will be inserted into the generated SQL statement immediately after the SELECT, for example DISTINCT |
trim | boolean | no | If |
keytable | string | no | An optional database table that will be used to store entity keys temporarily when performing the required SQL to generate the data for this data connection. If this option isn't set then the SQL used to generate the data will create the data in batches, which can cause issues with sorting, optionally you can create a simple two column table, with an index on the userid column, and set this value to the name of this table, then Weave will insert the entity id's into this table temporarily and use this table in a SQL join when generating the data. This will resolve any sorting issues, and is more important if caching is also disabled for the data connection. |
keycolumn | string | no | The column in |
usercolumn | string | no | The column in |
generateParameters | boolean | false | Added at 2.6.11. When set to true it indicates that Weave should generate the parameter configuration from the database table columns and that the Prior to 2.6.11 if you did not include any If a parameter tag has the same Note that the generated parameter |
Sub-tags
Name | Type | Cardinality |
|---|---|---|
parameter | 0..n | |
cache | 0..1 | |
from | 0..n | |
where | 0..n | |
sort | 0..n | |
join | 0..n | |
options | 0..1 |
Content
None
Notes
The cache settings are only used for data source data connections that have a key specified, since it's the key that's used as the cache index
If no
cachetag is specified then the data will still be cached, but it will use the default cache configuration, to disable caching you need to setdisabletotrueinside the cache definition (see example below).You can completely disable the caching (for all data definitions that don't have cache setting explicitly set) by setting the startup parameter
weave.cache.defaulttotrue(in startup.cmd, startup.sh and/or weave-service.conf).If no parameters are specified then the server will generate parameters based on the columns in the underlying table, in this case you should also not include any
fromtags since joins are not currently supported,wheretags are ok though.
parameter
Properties
Name | Type | Required | Default | Description |
|---|---|---|---|---|
column | string | yes | The name of the column within the table that this parameter references (can be an sql function also) | |
type | 'string', 'numeric', 'date' or 'url' | no | 'string' | An indicator of how the data should be displayed on the client |
name | string | no | lowercase value of column | A unique identifier for the parameter |
label | string | no | "pretty" value of column | A user displayable label for the column |
text | string | no | Only when type is 'url'. Specifies text to be displayed to the user instead of the actual url contents | |
textcolumn | string | no | Only when type is 'url'. Specifies the column that contains text to be displayed to the user instead of the actual url contents | |
format | string | no | "date", "time" or "datetime" | When the |
remove | boolean | no | false | Added at 2.6.11. Used when modifying parameter information generated by Weave and indicates that Weave should remove this particular parameter from the list of parameters generated by Weave. |
Sub-tags
Name | Type | Cardinality |
|---|---|---|
from | 0..n | |
where | 0..n |
Content
None
Notes
If no
labelis specified then it will be generated by formatting thename, unless nonameis supplied, then it will be generated by formatting thecolumnFormatting involves converting any _'s to spaces, converting the first letter and any letter after a space to upper case and converting every other letter to lower case, e.g. "BOMB_DISPOSAL_METHOD" becomes "Bomb Disposal Method"
Only one of
textortextcolumnshould be specified when type is 'url'
from
Properties
Name | Type | Required | Description |
|---|---|---|---|
table | string | yes | An additional table to include in the generated SQL |
Sub-tags
None
Content
None
where
Properties
Name | Type | Required | Description |
|---|---|---|---|
clause | string | yes | An additional clause to include in the generated SQL |
uppercase | boolean | no | If the clause uses parameter substitution should the value be converted to upper-case before being substituted |
Sub-tags
None
Content
None
sort
Properties
Name | Type | Required | Description |
|---|---|---|---|
parameter | string | yes | Name of parameter to sort on |
direction | string | no | ASC or DESC, ASC is default |
Sub-tags
None
Content
None
join
Only available in 2.5.11 or later
properties
Name | Type | Required | Description |
|---|---|---|---|
table | string | yes | The table to join to |
on | string | yes | The clause used to join the table |
type | string | no | The type of join to use |
clause | string | no | Additional clauses that can be added to the join |
options
Properties
Name | Type | Required | Description |
|---|---|---|---|
rpad | number | no | If the key value needs to be padded with spaces on the right to make it match the database, this specifies the total length of the final padded value. For example rpad = 10 would change a key value from "value" to "value....." (where each . is a space). |
lpad | number | no | If the key value needs to be padded with spaces on the left to make it match the database, this specifies the total length of the final padded value. For example lpad = 10 would change a key value from "value" to ".....value" (where each . is a space). |
trim | boolean | no | If a key value needs to be trimmed of spaces before being used setting this to |
maxrows | number | no | Limit the number of rows that will be extracted from the database when generating the data. |
failOnSubstitutionError | boolean | no | If set to If this is set to The default value for this flag if it is not set is |
timeout | number | no | The number of milliseconds before the SQL should be cancelled. Default 120000, can be disabled by setting to 0, can be changed globally by setting the system property |
Sub-tags
None
Content
None
Examples
Basic data definition where output is based on columns in the underlying table
<data:datadefinition id="roadDetails">
<datasourcedataconnection datasource="datasource.main" table="ROADS" key="RD_NAME" prefix="DISTINCT"/>
</data:datadefinition>Modifying parameters generated by Weave
Note this example requires Weave 2.6.11 or later
<data:datadefinition id="roadDetails">
<datasourcedataconnection datasource="datasource.main" table="ROADS" key="RD_NAME" prefix="DISTINCT">
<!-- note the generated parameter name is always the lower case version of the column name -->
<parameter name="rd_name" label="Road Name" column="propercase(RD_NAME)"/> <!-- replace the parameter generated from the RD_NAME column -->
<parameter name="name" label="Name" column="RD_NAME || ' ' || RD_TYPE"/> <!-- add a new parameter -->
<parameter name="uuid" remove="true"/> <!-- remove the parameter generated from the UUID column -->
</datasourcedataconnection>
</data:datadefinition>
In the following examples the || operator is used to concatenate strings, this operator is Oracle specific, and my require using a different operator for other databases, for example +
Alternatively you can use the JDBC concat function, which will be translated by the JDBC driver to the appropriate format for the database, e.g.
{fn concat('http://hostname/path?parameter=', COLUMN_NAME)}
Sample data definition with caching parameters explicitly set
<data:datadefinition id="roadDetails">
<datasourcedataconnection datasource="datasource.main" table="ROADS" key="RD_NAME" prefix="DISTINCT">
<from table="PLANS"/>
<where clause="PLANS.ID=ROADS.PLAN_ID"/>
<parameter name="name" label="Name" column="RD_NAME"/>
<parameter name="suffix" label="Suffix" column="RD_SUFFIX"/>
<parameter name="type" label="Type" column="RD_TYPE"/>
<parameter name="altname" label="Alt. Name" column="ALT_NAME"/>
<parameter name="altsuffix" label="Alt. Suffix" column="ALT_SUFFIX"/>
<parameter name="alttype" label="Alt. Type" column="ALT_TYPE"/>
<parameter type="integer" name="class" label="Class" column="CLASS_CODE"/>
<parameter type="url" name="plan" label="Plan" column="'http://imgsvr:8080/gis/documents/plan_'||PLANS.PLAN_CODE||'.pdf'" text="Open"/>
<cache>
<maxElementsInMemory>500</maxElementsInMemory>
<eternal>false</eternal>
<timeToIdleSeconds>60</timeToIdleSeconds>
<timeToLiveSeconds>300</timeToLiveSeconds>
<overflowToDisk>true</overflowToDisk>
<maxElementsOnDisk>20000</maxElementsOnDisk>
<diskPersistent>false</diskPersistent>
<diskExpiryThreadIntervalSeconds>120</diskExpiryThreadIntervalSeconds>
<memoryStoreEvictionPolicy>LRU</memoryStoreEvictionPolicy>
</cache>
</datasourcedataconnection>
</data:datadefinition>
Sample data definition with caching disabled
<data:datadefinition id="roadDetails">
<datasourcedataconnection datasource="datasource.main" table="ROADS" key="RD_NAME" prefix="DISTINCT">
<from table="PLANS"/>
<where clause="PLANS.ID=ROADS.PLAN_ID"/>
<parameter name="name" label="Name" column="RD_NAME"/>
<parameter name="suffix" label="Suffix" column="RD_SUFFIX"/>
<parameter name="type" label="Type" column="RD_TYPE"/>
<parameter name="altname" label="Alt. Name" column="ALT_NAME"/>
<parameter name="altsuffix" label="Alt. Suffix" column="ALT_SUFFIX"/>
<parameter name="alttype" label="Alt. Type" column="ALT_TYPE"/>
<parameter type="integer" name="class" label="Class" column="CLASS_CODE"/>
<parameter type="url" name="plan" label="Plan" column="'http://imgsvr:8080/gis/documents/plan_'||PLANS.PLAN_CODE||'.pdf'" text="Open"/>
<cache disable="true"/>
</datasourcedataconnection>
</data:datadefinition>
Sample data definition with caching parameters supplied by a cache configuration (so the cache definition can be reused)
<data:cache id="test.cache">
<maxElementsInMemory>500</maxElementsInMemory>
<eternal>false</eternal>
<timeToIdleSeconds>60</timeToIdleSeconds>
<timeToLiveSeconds>300</timeToLiveSeconds>
<overflowToDisk>true</overflowToDisk>
<maxElementsOnDisk>20000</maxElementsOnDisk>
<diskPersistent>false</diskPersistent>
<diskExpiryThreadIntervalSeconds>120</diskExpiryThreadIntervalSeconds>
<memoryStoreEvictionPolicy>LRU</memoryStoreEvictionPolicy>
</data:cache>
<data:datadefinition id="roadDetails">
<datasourcedataconnection datasource="datasource.main" table="ROADS" key="RD_NAME" prefix="DISTINCT">
<from table="PLANS"/>
<where clause="PLANS.ID=ROADS.PLAN_ID"/>
<parameter name="name" label="Name" column="RD_NAME"/>
<parameter name="suffix" label="Suffix" column="RD_SUFFIX"/>
<parameter name="type" label="Type" column="RD_TYPE"/>
<parameter name="altname" label="Alt. Name" column="ALT_NAME"/>
<parameter name="altsuffix" label="Alt. Suffix" column="ALT_SUFFIX"/>
<parameter name="alttype" label="Alt. Type" column="ALT_TYPE"/>
<parameter type="integer" name="class" label="Class" column="CLASS_CODE"/>
<parameter type="url" name="plan" label="Plan" column="'http://imgsvr:8080/gis/documents/plan_'||PLANS.PLAN_CODE||'.pdf'" text="Open"/>
<cache id="test.cache"/>
</datasourcedataconnection>
</data:datadefinition>
A data definition for supplying a list of values (no key is defined), probably for a cascading input parameter for a search
<data:datadefinition id="suburbRoads">
<datasourcedataconnection datasource="datasource.main" table="PROPERTY" prefix="DISTINCT">
<parameter name="suburb" label="Suburb" column="PRSUB_NAME"/>
<parameter name="roadname" label="Road Name" column="PRROD_NAME"/>
</datasourcedataconnection>
</data:datadefinition>
Another data definition for supplying a list of values, probably for a triple field cascading input parameter for a search
<data:datadefinition id="suburbRoadType">
<datasourcedataconnection datasource="datasource.main" table="PROPERTY" prefix="DISTINCT">
<parameter name="suburb" label="Suburb" column="PRSUB_NAME"/>
<parameter name="roadname" label="Road Name" column="PRROD_NAME"/>
<parameter name="roadtype" label="Road Type" column="PRROD_TYPE"/>
</datasourcedataconnection>
</data:datadefinition>
Set a timeout for a data definition
<data:datadefinition id="suburbRoadType">
<datasourcedataconnection datasource="datasource.main" table="PROPERTY" prefix="DISTINCT">
<parameter name="suburb" label="Suburb" column="PRSUB_NAME"/>
<parameter name="roadname" label="Road Name" column="PRROD_NAME"/>
<parameter name="roadtype" label="Road Type" column="PRROD_TYPE"/>
<options>
<timeout>15000</timeout>
</options>
</datasourcedataconnection>
</data:datadefinition>
More on Caching
To disable the caching all together you'd do the following
<data:datadefinition id="...">
<datasourcedataconnection ...>
...
<cache disable="true"/>
</datasourcedataconnection>
</data:datadefinition>
To modify the default caching options
<data:datadefinition id="...">
<datasourcedataconnection ...>
...
<cache>
<setting>value</setting>
<setting>value</setting>
<setting>value</setting>
</cache>
</datasourcedataconnection>
</data:datadefinition>
Where the <settings> you can change are identified at caching
You can set the default cache settings with
<data:cache>
<setting>value</setting>
<setting>value</setting>
<setting>value</setting>
</data:cache>
and create a cache definition that can be re-used
<data:cache id="test">
<setting>value</setting>
<setting>value</setting>
<setting>value</setting>
</data:cache>
<data:datadefinition id="...">
<datasourcedataconnection ...>
...
<cache id="test"/>
</datasourcedataconnection>
</data:datadefinition>
Note that prior to Weave 2.5.18 the default cache setting for a datasource data connection was to cache the information forever, as of 2.5.18 the data will only be cached for 5 minutes by default.
Using a temporary table
Using a temporary table
<data:datadefinition id="roadDetails">
<datasourcedataconnection datasource="datasource.main" table="ROADS" key="RD_NAME" prefix="DISTINCT" keytable="ROADS_SELECTION" keycolumn="RD_NAME" usercolumn="UID">
<from table="PLANS"/>
<where clause="PLANS.ID=ROADS.PLAN_ID"/>
<parameter name="name" label="Name" column="RD_NAME"/>
<parameter name="suffix" label="Suffix" column="RD_SUFFIX"/>
<parameter name="type" label="Type" column="RD_TYPE"/>
<parameter name="altname" label="Alt. Name" column="ALT_NAME"/>
<parameter name="altsuffix" label="Alt. Suffix" column="ALT_SUFFIX"/>
<parameter name="alttype" label="Alt. Type" column="ALT_TYPE"/>
<parameter type="integer" name="class" label="Class" column="CLASS_CODE"/>
<parameter type="url" name="plan" label="Plan" column="'http://imgsvr:8080/gis/documents/plan_'||PLANS.PLAN_CODE||'.pdf'" text="Open"/>
<cache disable="true"/>
</datasourcedataconnection>
</data:datadefinition>This example will utilise a temporary table called ROADS_SELECTION which contains two columns RD_NAME who's data type matches the RD_NAME column in the ROADS table, and UID which is a varchar column long enough to contain 32 random characters, and there should be an non-unique index on the UID column.
Note: that "userid" and "key" are the default names for the columns in the temporary table, they can be called anything but if they're not "userid" and/or "key" then you'd need to set the keycolumn and usercolumn values in the data defintiion to match the names of the columns in the temporary table, as has been done above since the column names are actually "RD_NAME" and "UID" rather than "userid" and "key". You always need to provide the keytable parameter so there's no default for that.
Sorting data
You can add <sort> tags to specify what column(s) to sort by by default, e.g.
<data:datadefinition id="roadDetails">
<datasourcedataconnection datasource="datasource.main" table="ROADS" key="RD_NAME" prefix="DISTINCT">
<from table="PLANS"/>
<where clause="PLANS.ID=ROADS.PLAN_ID"/>
<parameter name="name" label="Name" column="RD_NAME"/>
<parameter name="suffix" label="Suffix" column="RD_SUFFIX"/>
<parameter name="type" label="Type" column="RD_TYPE"/>
<parameter name="altname" label="Alt. Name" column="ALT_NAME"/>
<parameter name="altsuffix" label="Alt. Suffix" column="ALT_SUFFIX"/>
<parameter name="alttype" label="Alt. Type" column="ALT_TYPE"/>
<sort parameter="type"/>
<sort parameter="name"/>
</datasourcedataconnection>
</data:datadefinition>New Join Syntax
As of Weave 2.5.11 it's possible to specify a table join using join specific tag (rather than having to use from and where tags).
This is done with the join tag, which takes 3 parameters, table which is required and is the name of the table to join on, on which is also required and is the join clause, and finally type which isn't required and will specify the join type to use (will default to an inner join).