Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/Development/JPA 2.0/undelimited identifiers"

(Open Issues)
Line 12: Line 12:
  
 
====Under Construction====
 
====Under Construction====
 +
 +
==== ORM.xml Parsing ====
 +
 +
A new attribute called useDelimitedIdentifiers will be added to our XMLPersistenceUnit defaults class and we will add parsing code to populate it from orm.xml.  useDelimitedIdentifiers will default to false and be accessible through a getter method.
 +
 +
==== Delimiters ====
 +
 +
The default delimiter will be the double quote since this is the most common delimiters.  It will be avaiable from the Helper class through a getter and setter method.  Additionally, the getter method will check a system variable called: eclipselink.jdbc.delimiter and set use the value of that variable as the delimiter if it is supplied.
 +
 +
==== DatabaseField and DatabaseTable ====
 +
 +
The use of delimited identifiers will be represented on the DatabaseTable and DatabaseField with a boolean instance variable.  The following modifications will be made to the classes
 +
 +
DatabaseField
 +
* add setUseDelimiters(boolean) method to set the instance variable
 +
* add getNameDelimited() method that returns the name with delimiters
 +
* alter getQualifiedName() method to return a delimited version of the qualified name
 +
* change code that initializes the name instance variable to check for delimiters remove them from the name and set the flag
 +
 +
DatabaseTable
 +
* add setUseDelimiters(boolean) method to set the instance variable
 +
* add getNameDelimited() method that returns the name with delimiters
 +
* add getQualifiedNameDelimited() method to return a delimited version of the qualified name
 +
* alter getTableQualifier() to return the delimited version of the table qualifier
 +
* change code that initializes the name instance variable to check for delimiters remove them from the name and set the flag
 +
 +
The reason we have chose to manage delimiters with a flag rather than simply storing the quoted values as the name in DatabaseField and DatabaseTable is as follows:
 +
 +
* It makes it easier for metadata processing code to avoid adding delimiters twice
 +
* Result sets from database reads never come back with delimiters.  As a result, in order to be able to look up fields in rows from the database, we need to be able to do a lookup without the delimiters
 +
 +
In the case where the delimited-identifiers flag is set as a persistence unit default and a field is delimited in the column definition (annotation or xml) we will delimit the field only once.
 +
 +
==== Metadata processing ====
 +
  
 
At the moment, we already handle delimiters when they are specified in quoted field names.  We simply need to update to handle when delimited-identifiers is specified in orm.xml.
 
At the moment, we already handle delimiters when they are specified in quoted field names.  We simply need to update to handle when delimited-identifiers is specified in orm.xml.

Revision as of 09:27, 10 July 2009

Undelimited Identifiers

JPA 2.0 Root | Enhancement Request

Issue Summary

The specification has added support to always treat meta data identifiers as if they are "quoted" preserving case and allowing reserved words to be used.


See JPA 2.0 ED section 2.13 for details.

General Solution

Under Construction

ORM.xml Parsing

A new attribute called useDelimitedIdentifiers will be added to our XMLPersistenceUnit defaults class and we will add parsing code to populate it from orm.xml. useDelimitedIdentifiers will default to false and be accessible through a getter method.

Delimiters

The default delimiter will be the double quote since this is the most common delimiters. It will be avaiable from the Helper class through a getter and setter method. Additionally, the getter method will check a system variable called: eclipselink.jdbc.delimiter and set use the value of that variable as the delimiter if it is supplied.

DatabaseField and DatabaseTable

The use of delimited identifiers will be represented on the DatabaseTable and DatabaseField with a boolean instance variable. The following modifications will be made to the classes

DatabaseField

  • add setUseDelimiters(boolean) method to set the instance variable
  • add getNameDelimited() method that returns the name with delimiters
  • alter getQualifiedName() method to return a delimited version of the qualified name
  • change code that initializes the name instance variable to check for delimiters remove them from the name and set the flag

DatabaseTable

  • add setUseDelimiters(boolean) method to set the instance variable
  • add getNameDelimited() method that returns the name with delimiters
  • add getQualifiedNameDelimited() method to return a delimited version of the qualified name
  • alter getTableQualifier() to return the delimited version of the table qualifier
  • change code that initializes the name instance variable to check for delimiters remove them from the name and set the flag

The reason we have chose to manage delimiters with a flag rather than simply storing the quoted values as the name in DatabaseField and DatabaseTable is as follows:

  • It makes it easier for metadata processing code to avoid adding delimiters twice
  • Result sets from database reads never come back with delimiters. As a result, in order to be able to look up fields in rows from the database, we need to be able to do a lookup without the delimiters

In the case where the delimited-identifiers flag is set as a persistence unit default and a field is delimited in the column definition (annotation or xml) we will delimit the field only once.

Metadata processing

At the moment, we already handle delimiters when they are specified in quoted field names. We simply need to update to handle when delimited-identifiers is specified in orm.xml.

The first step is to add parsing logic to our orm.xml parser to get the data.

When the parsing is done, we will update our Field and Column name construction code to use the data.

Work Required

  1. Develop tests
    approx 1 day
  2. Implement API
    approx 3 days

Open Issues

  • Although double quote is usable in most cases, there are some cases where other delimiters would be useful. (e.g. In the default mode, MySQL requires a single quote be used for delimiters and will throw an error is a double quote is used as a delimiter for a table name)
    • DatabasePlatform is not available at processing time, so we may need to provide a eclipselink.sql.delimiter property
  • Do we want any special handling if delimited-identifiers is specified in the orm.xml and also in an identifier
  • When we use Delimited Identifiers, rowsets returned from the database to not include the delimiters. This will cause issues anywhere we try to look up values by Name (Native Queries, Max Results)

Back to the top