Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be 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/DesignDocs/214519"

m
 
(4 intermediate revisions by 2 users not shown)
Line 13: Line 13:
 
! Version Description & Notes
 
! Version Description & Notes
 
|-  
 
|-  
| 2010-09-30
+
| 2010-10-19| Chris Delahunt
| Chris Delahunt
+
| 0.2 Draft
| 0.1 Draft
+
 
|-  
 
|-  
 
|}
 
|}
Line 23: Line 22:
  
 
= Requirements =
 
= Requirements =
Support specifying strings through persistence unit/session properties that apply to all tables, as well as strings on individual tables.  At the persistence unit/session level, this allows appending strings such as "engine=InnoDB" that would apply to every table and still have strings defined in annotations and eclipselink-orm.xml that apply to individual tables.
+
Support specifying strings through persistence unit/session properties that apply to all tables, as well as strings on individual tables.  At the persistence unit/session level, this allows appending strings such as "engine=InnoDB" that would apply to every table and still have strings defined in eclipselink-orm.xml that apply to individual tables.
  
 
Feature is only for DDL generation purposes and affects no other runtime behavior.
 
Feature is only for DDL generation purposes and affects no other runtime behavior.
  
 
= Design =
 
= Design =
API changes:
 
org.eclipse.persistence.sessions.Project will have a public set/getDefaultTableCreationSuffix accessors to allow setting a default in native EclipseLink projects.  SchemaManager will append the value from the project on the passed in session when creating all tables.
 
org.eclipse.persistence.tools.schemaframework.TableDefinition and org.eclipse.persistence.internal.helper.DatabaseTable both will have set/getCreationSuffix methods to allow specifying a string to be appended to the create table statement.  Creation suffix strings on the TableDefinition/DatabaseTable will be applied before the default string at the project level.
 
  
JPA accessibility:
+
=== Native API ===
 +
* org.eclipse.persistence.sessions.Project will have a public set/getDefaultTableCreationSuffix accessors to allow setting a default in native EclipseLink projects. 
 +
* SchemaManager will append the value from the project on the passed in session when creating all tables.
 +
* org.eclipse.persistence.tools.schemaframework.TableDefinition and org.eclipse.persistence.internal.helper.DatabaseTable both will have set/getCreationSuffix methods to allow specifying a string to be appended to the create table statement. 
 +
* Creation suffix strings on the TableDefinition/DatabaseTable will be applied before the default string at the project level.
 +
 
 +
=== JPA PU Property ===
 +
 
 
eclipselink.ddl.default-table-suffix property added for persistence unit properties corresponding to the project's DefaultTableCreationSuffix
 
eclipselink.ddl.default-table-suffix property added for persistence unit properties corresponding to the project's DefaultTableCreationSuffix
  
in EclipseLink-orm.xml, everywhere a table can be specified, the table definition will be expanded to include a create-suffix attribute that will be applied to resulting table's CreationSuffix
+
<pre>
In annotations, because annotations cannot be overriden, a new ELTable annotation will be added with a name and creationSuffix.  This new annotation can be added to anywhere that an annotation exists, and will be used to merge into the created table data.  This allows it to be expanded upon in the future (suchas if a deletion suffix or other type properties need to be added)
+
<property name="eclipselink.ddl-generation.table-creation-suffix" value="engine=InnoDB" />
Annotation/XML processing rules will remain the same, such that the same mapping defined in both xml and through annotations, the values specified in XML trump the annotation values. 
+
</pre>
  
XML tags that need to be expanded upon to include creation-suffix consist of table, secondary-table, JoinTable join-table, collection-table and table-generator.  Annotation processing that currently allows for similar tags will need to be expanded to also factor in the ELTable annotation and merge into the table. For instance:
+
=== XML (eclipselink-orm.xml) ===
  
<source lang="java">
+
In EclipseLink-orm.xml, everywhere a table can be specified, the table definition will be expanded to include a creation-suffix attribute that will be applied to resulting table's CreationSuffix
@Entity
+
XML tags that need to be expanded upon to include creation-suffix consist of table, secondary-table, JoinTable join-table, collection-table and table-generator.
@Table(name="DDL_EMPLOYEE")
+
 
@ELTable(name="DDL_EMPLOYEE" creationSuffix=" engine=InnoDB")
+
=== Annotations ===
public class Employee {
+
 
    @Id
+
There will be no support for adding strings to DDL table creation statements through custom annotations.  Users should find setting at the context level through a persistence property or if required at the table level, using an eclipselink-orm.xml sufficient.
    private int id;
+
This can be revisited if there is demand in the future, but does not seem to warrant adding an additional table annotation at this time.
}
+
 
</source>
+
===Example===
 +
An EclipseLink-orm.xml file with the following tag (assuming it has an id annotated):
 +
<pre><entity class="Comment">
 +
  <table name="DDL_COMMENT" creation-suffix="COMMENT='User Comment Table'"/>
 +
</entity></pre>
  
 
will result in the creation statement:
 
will result in the creation statement:
 +
<pre>
 +
  CREATE TABLE DDL_COMMENT (ID INTEGER) COMMENT='User Comment Table'
 +
</pre>
  
 +
Coupled with persistence property:
 +
 +
<pre><property name="eclipselink.ddl.default-table-suffix" value="engine=InnoDB"/></pre>
 +
 +
will result in the creation statement:
 
<pre>
 
<pre>
   CREATE TABLE DDL_EMPLOYEE (ID INTEGER) engine=InnoDB
+
   CREATE TABLE DDL_COMMENT (ID INTEGER) COMMENT='User Comment Table' engine=InnoDB
 
</pre>
 
</pre>
  
Line 64: Line 79:
  
 
== Open Issues ==
 
== Open Issues ==
*Naming
 
*Testing and where it should go
 

Latest revision as of 15:56, 17 November 2010

Design Specification: Appending strings to CREATE TABLE statements

Enhancement Request bug 214519

Feedback

Document History

Date Author Version Description & Notes
Chris Delahunt 0.2 Draft

Summary

Allow appending strings to CREATE TABLE statements for DDL generation

Requirements

Support specifying strings through persistence unit/session properties that apply to all tables, as well as strings on individual tables. At the persistence unit/session level, this allows appending strings such as "engine=InnoDB" that would apply to every table and still have strings defined in eclipselink-orm.xml that apply to individual tables.

Feature is only for DDL generation purposes and affects no other runtime behavior.

Design

Native API

  • org.eclipse.persistence.sessions.Project will have a public set/getDefaultTableCreationSuffix accessors to allow setting a default in native EclipseLink projects.
  • SchemaManager will append the value from the project on the passed in session when creating all tables.
  • org.eclipse.persistence.tools.schemaframework.TableDefinition and org.eclipse.persistence.internal.helper.DatabaseTable both will have set/getCreationSuffix methods to allow specifying a string to be appended to the create table statement.
  • Creation suffix strings on the TableDefinition/DatabaseTable will be applied before the default string at the project level.

JPA PU Property

eclipselink.ddl.default-table-suffix property added for persistence unit properties corresponding to the project's DefaultTableCreationSuffix

<property name="eclipselink.ddl-generation.table-creation-suffix" value="engine=InnoDB" />

XML (eclipselink-orm.xml)

In EclipseLink-orm.xml, everywhere a table can be specified, the table definition will be expanded to include a creation-suffix attribute that will be applied to resulting table's CreationSuffix XML tags that need to be expanded upon to include creation-suffix consist of table, secondary-table, JoinTable join-table, collection-table and table-generator.

Annotations

There will be no support for adding strings to DDL table creation statements through custom annotations. Users should find setting at the context level through a persistence property or if required at the table level, using an eclipselink-orm.xml sufficient. This can be revisited if there is demand in the future, but does not seem to warrant adding an additional table annotation at this time.

Example

An EclipseLink-orm.xml file with the following tag (assuming it has an id annotated):

<entity class="Comment">
  <table name="DDL_COMMENT" creation-suffix="COMMENT='User Comment Table'"/>
</entity>

will result in the creation statement:

  CREATE TABLE DDL_COMMENT (ID INTEGER) COMMENT='User Comment Table'

Coupled with persistence property:

<property name="eclipselink.ddl.default-table-suffix" value="engine=InnoDB"/>

will result in the creation statement:

  CREATE TABLE DDL_COMMENT (ID INTEGER) COMMENT='User Comment Table' engine=InnoDB

Testing

A new persistence unit will be need to be added as well as classes to test the new annotation processing, defaults and extended xml tags. Because the ddl generation is very database specific, testing will involve generating the DDL creation file and reading it in to verify create table strings have suffixes appended appropriately.

Documentation

Should be documented under extended annotations, and schema generation.

Open Issues

Back to the top