JPA Translator

Page edited by Steven Hawkins


Changes (15)

h1. JPA Translator

Think this one as a reverse to what Hibernate provides. If you have JPA based store and have a supporting object model, this translator can will reverse your object model into relational model, where you can integrate with other relational or non-relational sources.
The JPA translator, known by the type name _jpa2_, can reverse a JPA object model into a relational model, which can then be integrated with other relational or non-relational sources.

*Properties*

The JPA Translator currently has no import or execution properties.

h3. Native Queries

JPA source procedures may be created using the teiid_rel:native-query extension - see [Parameterizable Native Queries|Translators#native]. The procedure will invoke the native-query similar to an native procedure call with the benefits that the query is predetermined and that result column types are known, rather than requiring the use of ARRAYTABLE or similar functionality. See the query syntax below.

h4. *Native Procedure*
h4. *Direct Query Procedure*

{warning}
This feature is turned off by default because of the security risk this exposes to execute any command against the source. To enable this feature, [override the execution property|Translators#Override Execution Properties] called "SupportsNativeQueries" _SupportsDirectQueryProcedure_ to true.
{warning}

The JPA translator provides a procedure with name *native* that gives ability to execute any ad-hoc native JPA-QL queries directly against the source without any Teiid parsing or resolving. Since the metadata of this procedure's results are not known to Teiid, they are returned as object array. User can use [ARRAYTABLE] can be used construct tabular output for consumption by client applications. Teiid exposes this procedure with a simple query structure as below
{info:tip=Name of the Direct Procedure}
By default the name of the procedure that executes the queries directly is *native*. [Override the execution property|Translators#Override Execution Properties] _DirectQueryProcedureName_ to change it to another name.
{info}

The JPA translator provides a procedure to execute any ad-hoc JPA-QL query directly against the source without Teiid parsing or resolving. Since the metadata of this procedure's results are not known to Teiid, they are returned as object array. User can use [ARRAYTABLE] can be used construct tabular output for consumption by client applications. Teiid exposes this procedure with a simple query structure as below

h5. Select
{code:lang=SQL|title=Select Example}
SELECT x.* FROM (call pm1.native('search;FROM jpa_source.native('search;FROM Account')) w,
ARRAYTABLE(w.tuple COLUMNS "id" string , "type" string, "name" String) AS x
{code}
...
h5. Delete
{code:lang=SQL|title=Delete Example}
SELECT x.* FROM (call pm1.native('delete;<jpa-ql>')) jpa_source.native('delete;<jpa-ql>')) w,
ARRAYTABLE(w.tuple COLUMNS "updatecount" integer) AS x
{code}
...
{code:lang=SQL|title=Create Example}
SELECT x.* FROM
(call pm1.native('update;<jpa-ql>')) jpa_source.native('update;<jpa-ql>')) w,
ARRAYTABLE(w.tuple COLUMNS "update_count" integer) AS x
{code}
...
{code:lang=SQL|title=Update Example}
SELECT x.* FROM
(call pm1.native('create;', jpa_source.native('create;', <entity>)) w,
ARRAYTABLE(w.tuple COLUMNS "update_count" integer) AS x
{code}

Create operation needs to send "create" word as marker and send the entity as a the first parameter.

{info:tip=Name of the Native Procedure}
By default the name of the procedure that executes the queries directly is called *native*, however user can set [Override Execution Properties|Translators#Override Execution Properties] property on _NativeQueryProcedureName_ in vdb.xml file to change it to any other procedure name.
{info}

Full Content

JPA Translator

The JPA translator, known by the type name jpa2, can reverse a JPA object model into a relational model, which can then be integrated with other relational or non-relational sources.

Properties

The JPA Translator currently has no import or execution properties.

Native Queries

JPA source procedures may be created using the teiid_rel:native-query extension - see Parameterizable Native Queries. The procedure will invoke the native-query similar to an native procedure call with the benefits that the query is predetermined and that result column types are known, rather than requiring the use of ARRAYTABLE or similar functionality. See the query syntax below.

Direct Query Procedure

This feature is turned off by default because of the security risk this exposes to execute any command against the source. To enable this feature, override the execution property called SupportsDirectQueryProcedure to true.
By default the name of the procedure that executes the queries directly is native. Override the execution property DirectQueryProcedureName to change it to another name.

The JPA translator provides a procedure to execute any ad-hoc JPA-QL query directly against the source without Teiid parsing or resolving. Since the metadata of this procedure's results are not known to Teiid, they are returned as object array. User can use ARRAYTABLE can be used construct tabular output for consumption by client applications. Teiid exposes this procedure with a simple query structure as below

Select
Select Example
SELECT x.* FROM (call jpa_source.native('search;FROM Account')) w,
 ARRAYTABLE(w.tuple COLUMNS "id" string , "type" string, "name" String) AS x

from the above code, the "search" keyword followed by a query statement - see Parameterizable Native Queries to substitute parameter values.

Delete
Delete Example
SELECT x.* FROM (call jpa_source.native('delete;<jpa-ql>')) w,
 ARRAYTABLE(w.tuple COLUMNS "updatecount" integer) AS x

form the above code, the "delete" keyword followed by JPA-QL for delete operation.

Update
Create Example
SELECT x.* FROM
 (call jpa_source.native('update;<jpa-ql>')) w,
 ARRAYTABLE(w.tuple COLUMNS "update_count" integer) AS x

form the above code, the "update" keyword must be followed by JPA-QL for the update statement.

Create
Update Example
SELECT x.* FROM
 (call jpa_source.native('create;', <entity>)) w,
 ARRAYTABLE(w.tuple COLUMNS "update_count" integer) AS x

Create operation needs to send "create" word as marker and send the entity as a the first parameter.

Stop watching space | Change email notification preferences
View Online | View Changes | Add Comment