PreParser

If it is desirable to manipulate incoming queries prior to being handled by Teiid logic, then a custom pre-parser can be installed.

A PreParser may be set at a global level for all VDBs, or at a per VDB level. If both are specified the global PreParser will be called first, then the per VDB PreParser.

Use the PreParser interface provided in the org.teiid.api jar to plug-in a pre-parser for the Teiid engine. See Setting up the build environment to start development. For Example:

Sample Java Code
import org.teiid.PreParser;
...

package com.something;

public class CustomPreParser implements PreParser {

    @Override
    public String preParse(String command, CommandContext context) {
        //manipulate the command
    }
}

If this is intended to be a global PreParser, then create a file named org.teiid.PreParser in META-INF/services directory with contents:

com.something.CustomPreParser

After the jar has been built, it needs to be deployed in the WildFly as a module under <jboss-as>/modules directory. Follow the below steps to create a module.

  • Create a directory <jboss-as>/modules/com/something/main

  • Under this directory create a module.xml file that looks like

Sample module.xml file
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.something">
    <resources>
        <resource-root path="something.jar" />
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.resource.api"/>
        <module name="org.teiid.common-core"/>
        <module name="org.teiid.teiid-api" />
    </dependencies>
</module>
  • Copy the jar file under this same directory. Make sure you add any additional dependencies if required by your implementation class under dependencies.

  • If this is a global PreParser, then use the cli or modify the configuration to set the preparser-module in the Teiid subsystem configuration to the appropriate module name.

  • If this is a per VDB PreParser, then update the vdb property "preparser-class" to be the class name of your PreParser. The VDB class path also needs to be updated to include the PreParser module, which can be done by adding the module name to the "lib" property.

Sample vdb.xml properties
<vdb name="..." version="...">
   <property name="lib" value="preparser-module-name"/>
   <property name="preparser-class" value="com.something.CustomPreParser"/>
   ...
</vdb>
  • Restart the server for the module to become available.

Development Considerations

  • Changing the incoming query to a different type of statement is not recommended as are any modifications to the number or types of projected symbols.

  • When using Teiid Embedded you just need to include the jar with the PreParser in the application class path - as modules are not used.

results matching ""

    No results matching ""