12.2. Relational View Modeling
12.2.1. Create Materialized Views

Figure 12.11. Materialized Table Properties
- The materialization process is undertaken one view at a time. Select the view to be materialized then right-click the view tables in the Model Explorer View and select the Modeling > Create Materialized Views action. (Note that you should select two or more tables otherwise you will see a different context menu and wizard.)
Figure 12.12.
- In the Create Materialized View Model dialog specify or select a target relational model for your generated relational tables.
Figure 12.13.
- Selecting the Browse ... button displays the Relational Model Selector dialog where you select an existing relational model or specify a unique name for a new model.
Figure 12.14.
- Click OK to create relational tables corresponding to your selected view tables and automatically set the Materialized property to TRUE and the Materialized Table reference value to your newly generated table.

Figure 12.15. Materialized Table Properties
12.2.2. Red Hat JBoss Data Grid Materialization
12.2.2.1. JBoss Data Grid 6 Materialization
- Minimum, JDG 6.2 - this requires you provide a protobuf definition file and pojo marshaller(s) for the pojo to configure the JDG schema
- Minimum, JDG 6.6 - this can be used when the pojo has defined protobuf annotations which are used to configure the JDG schema.
Property Name | Property Template | Description |
---|---|---|
CacheTypeMap | cacheName:className[;pkFieldName[:cacheKeyJavaType]] | For the indicated cacheName, map the root Java Object (pojo) class name. Optionally, but required for updates, identify which class attribute is the primary key to the cache. Optionally, identify primary key java type when different than class attribute type. |
Property Name | Required? | Property Template | Description |
---|---|---|---|
ProtobufDefinitionFile | Yes | Path to the Google Protobuf file that’s packaged in a jar (ex: /quickstart/addressbook.proto) | NA |
MessageMarshallers | Yes | marshaller \[,marshaller,..\] | Contains Class names mapped its respective message marshaller, (class:marshaller,\[class:marshaller,..\]), that are to be registered for serialization |
MessageDescriptor | Yes | NA | Message descriptor class name for the root object in cache |
public class Person { @ProtoField(number = 2, required = true) public String name; @ProtoField(number = 1, required = true) public int id; @ProtoField(number = 3) public String email; private List<PhoneNumber> phones; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public List<PhoneNumber> getPhones() { return phones; } public void setPhones(List<PhoneNumber> phones) { this.phones = phones; } }
Property Name | Required? | Property Template | Description |
---|---|---|---|
CacheTypeMap | Yes | cacheName:className[;pkFieldName[:cacheKeyJavaType]] | For the indicated cache, map the root Java Object class name. Optionally, but required for updates, identify which class attribute is the primary key to the cache. Identify primary key java type when different than class attribute type |
ProtobinFile | Yes | NA | Path to the Google Protobin file that's packaged in a jar (ex: /quickstart/addressbook.protobin) |
MessageMarshallers | Yes | marshaller [,marshaller,..] | Contains Class names mapped its respective message marshaller, (class:marshaller,[class:marshaller,..]), that are to be registered for serialization |
MessageDescriptor | Yes | NA | Message descriptor class name for the root object in cache |
module | No | NA | Specify the JBoss EAP module that contains the cache classes that need to be loaded |
CacheJndiName | No | NA | JNDI name to find the CacheContainer |
RemoteServerList | No | host:port[;host:port….] | Specify the host and ports that will be clustered together to access the caches |
HotRodClientPropertiesFile | No | NA | The HotRod properties file for configuring a connection to a remote cache |
Property Name | Required? | Property Template | Description |
---|---|---|---|
module | No | NA | Specify the WildFly module that contains the cache classes that need to be loaded |
Property Name | Required? | Description |
---|---|---|
StagingCacheName | Yes | Cache name for the staging cache used in materialization . |
AliasCacheName | Yes | Cache name for the alias cache used in tracking aliasing of the caches used in materialization. This cache can be shared with other configured materializations. . |
<resource-adapter id="infinispanRemQS"> <module slot="main" id="org.jboss.teiid.resource-adapter.infinispan.hotrod"/> <connection-definitions> <connection-definition class-name="org.teiid.resource.adapter.infinispan.hotrod.InfinispanManagedConnectionFactory" jndi-name="java:/infinispanRemote" enabled="true" use-java-context="true" pool-name="infinispanDS"> <config-property name="CacheTypeMap"> addressbook:org.jboss.as.quickstarts.datagrid.hotrod.query.domain.Person;id </config-property> <config-property name="ProtobufDefinitionFile"> /quickstart/addressbook.proto </config-property> <config-property name="MessageDescriptor"> quickstart.Person </config-property> <config-property name="Module"> com.client.quickstart.pojos </config-property> <config-property name="MessageMarshallers"> org.jboss.as.quickstarts.datagrid.hotrod.query.domain.Person:org.jboss.as.quickstarts.datagrid.hotrod.query.marshallers.PersonMarshaller,org.jboss.as.quickstarts.datagrid.hotrod.query.domain.PhoneNumber:org.jboss.as.quickstarts.datagrid.hotrod.query.marshallers.PhoneNumberMarshaller,org.jboss.as.quickstarts.datagrid.hotrod.query.domain.PhoneType:org.jboss.as.quickstarts.datagrid.hotrod.query.marshallers.PhoneTypeMarshaller </config-property> <config-property name="RemoteServerList"> 127.0.0.1:11322 </config-property> </connection-definition> </connection-definitions> </resource-adapter>
<resource-adapter id="infinispanRemQSDSL"> <module slot="main" id="org.jboss.teiid.resource-adapter.infinispan.dsl"/> <connection-definitions> <connection-definition class-name="org.teiid.resource.adapter.infinispan.dsl.InfinispanManagedConnectionFactory" jndi-name="java:/infinispanRemoteDSL" enabled="true" use-java-context="true" pool-name="infinispanRemoteDSL"> <config-property name="RemoteServerList"> 127.0.0.1:11322 </config-property> <config-property name="CacheTypeMap"> addressbook_indexed:org.jboss.as.quickstarts.datagrid.hotrod.query.domain.Person;id </config-property> </connection-definition> </connection-definitions> </resource-adapter>
<resource-adapter id="infinispanRemQSDSL"> <module slot="main" id="org.jboss.teiid.resource-adapter.infinispan.hotrod"/> <connection-definitions> <connection-definition class-name="org.teiid.resource.adapter.infinispan.hotrod.InfinispanManagedConnectionFactory" jndi-name="java:/infinispanRemoteDSL" enabled="true" use-java-context="true" pool-name="infinispanRemoteDSL"> <config-property name="CacheTypeMap"> addressbook_indexed:org.jboss.as.quickstarts.datagrid.hotrod.query.domain.Person;id </config-property> <config-property name="StagingCacheName"> addressbook_indexed_mat </config-property> <config-property name="AliasCacheName"> aliasCache </config-property> <config-property name="Module"> com.client.quickstart.addressbook.pojos </config-property> <config-property name="RemoteServerList"> 127.0.0.1:11322 </config-property> </connection-definition> </connection-definitions> </resource-adapter>
- Retrieve objects from a cache and transform into rows and columns.
- Supports performing writes to the cache
- Use for external materialization to improve query performance
- Compare Criteria - EQ
- Compare Criteria Ordered - LT, GT, LE, GE - support for SupportsComapareCriteriaOrdered will be controlled by the version of JDG being accessed. Any JDG version 6.5 and prior will have this set to false due to an issue with JDG.
- And/Or Criteria
- In Criteria
- Like Criteria
- Order By
- INSERT, UPDATE, DELETE (non-transactional)
- Not (NE)
- IsNull
- support for 'Not' has been disabled
- boolean data type: JDG will throw an exception if no value is specified on the insert or when no default value is defined in the protobuf definition file.
- char data type: is not a supported type in theProtobuf data types (https://developers.google.com/protocol-buffers/docs/proto#scalar). Would either have to handle conversion in the protobuf marshaller or create a Teiid view with the data type as char.
- 1-to-Many, currently only supports Collection or Array, not Maps
- Write transactions not supported by JDG when using Hot Rod client
<model name="People" type="Physical"> <property name="importer.useFullSchemaName" value="false"/> <source name="infinispan-hotrod-connector" translator-name="ispn-hotrod" connection-jndi-name="java:/infinispanRemoteDSL" /> </model>
Script | Native query | Description |
---|---|---|
teiid_rel:MATVIEW_BEFORE_LOAD_SCRIPT | truncate cache | To truncate the cache identified as the staging cache. |
teiid_rel:MATVIEW_AFTER_LOAD_SCRIPT | swap cache names | To swap the aliases for the caches, so that the primary cache points to the recently loaded cache. |
.. "teiid_rel:MATVIEW_BEFORE_LOAD_SCRIPT" 'execute StockMatCache.native(''truncate cache'');', "teiid_rel:MATVIEW_LOAD_SCRIPT" 'insert into StockMatCache.Stock (productId, symbol, price, companyName) SELECT A.ID, S.symbol, S.price, A.COMPANY_NAME FROM Stocks.StockPrices AS S, Accounts.PRODUCT AS A WHERE S.symbol = A.SYMBOL', "teiid_rel:MATVIEW_AFTER_LOAD_SCRIPT" 'execute StockMatCache.native(''swap cache names'');',
Warning
SET NAMESPACE 'http://www.teiid.org/translator/object/2016' AS n0; CREATE FOREIGN TABLE Trade ( .... CONSTRAINT PK_TRADEID PRIMARY KEY(tradeId) ) OPTIONS (UPDATABLE TRUE); CREATE FOREIGN TABLE ST_Trade ( .... ) OPTIONS (NAMEINSOURCE 'Trade', UPDATABLE TRUE, "n0:primary_table" 'ObjectSchema.Trade');
Note
Important
- Using annotations, the pojo method names are used to configure the JDG schema, by passing the Class to the configuration builder.
- Using protobuf/mashallers, the JDG schema is configured by using the protobuf file.
12.2.2.2. JBoss Data Grid 7 Materialization
Prerequisites
- JBoss Data Virtualization 6.4 and above
- JBoss Data Grid 7.1.2 and above
- Configure the primary and staging cache and the
teiid-alias-naming-cache
cache in JDG. For details, see the External Materialization and Red Hat JBoss Data Grid section in the Development Guide Volume 5: Caching Guide for JBoss Data Virtualization 6. - Configure the translator and the
jdg
module. For details, see the Configure Red Hat JBoss Data Grid Connectors section in the Installation Guide for JBoss Data Virtualization 6.
Important
infinispan-hotrod-translator
extension or Model Extension Registry is not synchronized with the server, an attempt to create the JDG source model fails and the NullPointerException
message appears in the log. To work around this issue, make sure that the Model Extension view includes infinispan-hotrod-translator
. If the view does not include infinispan-hotrod-translator
, ensure that the server contains it and refresh the server in the Teiid Designer Connection view.
Procedure 12.1. Configuring JBoss Data Grid 7 Materialization
- Create a JDG source model. In the Teiid Designer, right-click on the view to materialize and select Modeling > Materialize.Make sure, that the view has a primary key defined because the Red Hat JBoss Data Grid source table requires the key for updates. Otherwise, manually create a primary key on each of the new JDG source tables.
Figure 12.16. Generate Materialized JDG Module
- Enter the primary and staging cache names.
- Optionally, change themodel name and the directory in which the model is saved. Note that Red Hat JBoss Data Grid restricts the name of the source model because the
protobuf
code is based on the Java package naming constraints. The model name becomes the package name in the.proto
file. This is due to a limitation in the way thatprotobuf
is defined. Because Red Hat JBoss Data Grid uses Java, the package name must follow the Java package naming standards. Dashes, for instance, are not allowed. - Click.
- Create a new connection profile.
- In theview click .
- Choose JDG 7.x, set name, and click.
- Set properties. Specify the Java Naming and Directory Interface (JNDI) Name, which is the name of the JDG Source model.For details about other properties to set, see the Red Hat JBoss Data Grid 7.x Configuration section in the Administration and Configuration Guide for JBoss Data Virtualization 6.
Figure 12.17. New connection profile
- Click.
- Add the connection profile to the created JDG Source model. Right-click the JDG Source Model and select Modeling > Set connection profile.
- Create Data Source for the JDG Source model. Right-click JDG Source Model and select Modeling > Create Data Source.
- To control the materialization process, update the materialized view extension properties on the above selected view:
- MATVIEW_TTL - to set the refresh rate, in milliseconds
- If you use the materialization management status table, set the following extension properties:
- ALLOW_MATVIEW_MANAGEMENT = true
- MATVIEW_STATUS_TABLE = {status table name}
- Create the Virtual Database (VDB), using the models needed for materialization.
- For the JDG Source model, be sure the JNDI is mapped to the JDG data source.
- Enable native queries. To do this, create a translator override for the
infinispan-hotrod
translator. Click the property and set the value to .
- Create a VDB XML file. Right-click the VDB and select Modeling > Generate VDB XML.
Important
Due to a bug, the VDB must be deployed to the server as a VDB XML file. - Deploy the VDB XML file. Right-click the VDB XML file and select Modeling > Deploy
12.2.3. Create Relational View Table Wizard

Figure 12.18. New View Table Wizard Action

Figure 12.19. Create Virtual Table Options wizard
12.2.3.1. Build with new table wizard

Figure 12.20. Properties Tab

Figure 12.21. Columns Tab

Figure 12.22. Transformation SQL Tab

Figure 12.23. SQL Templates Dialog
12.2.3.2. Build using columns from source model

Figure 12.24. Select Columns for View dialog
- Source table is table from what you want to build your virtual table.
- Target View Model is your view model to where you want to build your virtual table.
- View Name is name of your new virtual table.