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/Examples/JPA/TemporalEntity"

Line 12: Line 12:
 
* Support defining a new entity that does not yet exist but may exist in the future
 
* Support defining a new entity that does not yet exist but may exist in the future
  
== Relational Structure ==
+
== Software ==
 +
 
 +
This example is being built using EclipseLink 2.3.1. To access the source of the example check it out of SVN at:
 +
 
 +
/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.futures
 +
 
 +
== How it Works ==
 +
 
 +
Coming Soon...
 +
 
 +
== Examples ==
 +
 
 +
The following examples are from test cases.
 +
 
 +
=== Create Current Person ===
 +
 
 +
<source lang="java">
 +
Person p = new Person();
 +
p.setFirstName("Doug");
 +
p.setLastName("Clarke");
 +
 
 +
Address a = new Address();
 +
a.setStreet("45 O'Connor Street");
 +
a.setCity("Ottawa");
 +
a.setState("Ontario");
 +
 
 +
p.setAddress(a);
 +
em.persist(a);
 +
em.persist(p);
 +
</source>
 +
 
 +
Resulting SQL:
 +
<source lang="sql">
 +
[EL Fine]: INSERT INTO TADDRESS (OID, CITY, END_TS, START_TS, STATE, STREET, CID) VALUES (?, ?, ?, ?, ?, ?, ?)
 +
bind => [1, Ottawa, 9223372036854775807, 0, Ontario, 45 OConnor Street, null]
 +
[EL Fine]: UPDATE TADDRESS SET STATE = ?, STREET = ?, CID = ?, CITY = ? WHERE (OID = ?)
 +
bind => [Ontario, 45 OConnor Street, 1, Ottawa, 1]
 +
[EL Fine]: INSERT INTO TPERSON (OID, END_TS, F_NAME, L_NAME, START_TS, CID, ADDRESS_OID) VALUES (?, ?, ?, ?, ?, ?, ?)
 +
bind => [2, 9223372036854775807, Doug, Clarke, 0, null, null]
 +
[EL Fine]: UPDATE TPERSON SET CID = ?, ADDRESS_OID = ?, F_NAME = ?, L_NAME = ? WHERE (OID = ?)
 +
bind => [2, 1, Doug, Clarke, 2]
 +
</source>
 +
 
 +
'Note: The INSERT followed by the UPDATE statement are to populate the self-referencing FK values. Optimized solution being investigated'
 +
 
 +
=== Create Future Person ===
 +
<source lang="java">
 +
Person p = new Person();
 +
p.setFirstName("John");
 +
p.setLastName("Doe");
 +
p.setStart(T3);
 +
em.persist(p);
 +
</source>
 +
 
 +
SQL:
 +
<source lang="sql">
 +
[EL Fine]: INSERT INTO TPERSON (OID, END_TS, F_NAME, L_NAME, START_TS, CID, ADDRESS_OID) VALUES (?, ?, ?, ?, ?, ?, ?)
 +
bind => [1, 9223372036854775807, John, Doe, 3, null, null]
 +
[EL Fine]: UPDATE TPERSON SET CID = ?, START_TS = ?, F_NAME = ?, L_NAME = ? WHERE (OID = ?)
 +
bind => [1, 3, John, Doe, 1]
 +
</source>

Revision as of 15:37, 20 October 2011

bug 361016

EclipseLink JPA Futures Example

This example is intended to illustrate how entity versions can be stored and queried in a database. Unlike the history functionality of EclipseLink this example is focused on creating versions of an entity that may take effect in the future.

Requirements

  • Optimize queries against current version. Queries against future versions
  • Allow versions for the future to be created with a time they are expected to become the current
  • When a future version is promoted to current its temporal storage is not required (no history remains)
  • Allow multiple future versions and support changing when a future version takes effect
  • Support defining a new entity that does not yet exist but may exist in the future

Software

This example is being built using EclipseLink 2.3.1. To access the source of the example check it out of SVN at:

/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.futures

How it Works

Coming Soon...

Examples

The following examples are from test cases.

Create Current Person

Person p = new Person();
p.setFirstName("Doug");
p.setLastName("Clarke");
 
Address a = new Address();
a.setStreet("45 O'Connor Street");
a.setCity("Ottawa");
a.setState("Ontario");
 
p.setAddress(a);
em.persist(a);
em.persist(p);

Resulting SQL:

[EL Fine]: INSERT INTO TADDRESS (OID, CITY, END_TS, START_TS, STATE, STREET, CID) VALUES (?, ?, ?, ?, ?, ?, ?)
	bind => [1, Ottawa, 9223372036854775807, 0, Ontario, 45 OConnor Street, NULL]
[EL Fine]: UPDATE TADDRESS SET STATE = ?, STREET = ?, CID = ?, CITY = ? WHERE (OID = ?)
	bind => [Ontario, 45 OConnor Street, 1, Ottawa, 1]
[EL Fine]: INSERT INTO TPERSON (OID, END_TS, F_NAME, L_NAME, START_TS, CID, ADDRESS_OID) VALUES (?, ?, ?, ?, ?, ?, ?)
	bind => [2, 9223372036854775807, Doug, Clarke, 0, NULL, NULL]
[EL Fine]: UPDATE TPERSON SET CID = ?, ADDRESS_OID = ?, F_NAME = ?, L_NAME = ? WHERE (OID = ?)
	bind => [2, 1, Doug, Clarke, 2]

'Note: The INSERT followed by the UPDATE statement are to populate the self-referencing FK values. Optimized solution being investigated'

Create Future Person

Person p = new Person();
p.setFirstName("John");
p.setLastName("Doe");
p.setStart(T3);
em.persist(p);

SQL:

[EL Fine]: INSERT INTO TPERSON (OID, END_TS, F_NAME, L_NAME, START_TS, CID, ADDRESS_OID) VALUES (?, ?, ?, ?, ?, ?, ?)
	bind => [1, 9223372036854775807, John, Doe, 3, NULL, NULL]
[EL Fine]: UPDATE TPERSON SET CID = ?, START_TS = ?, F_NAME = ?, L_NAME = ? WHERE (OID = ?)
	bind => [1, 3, John, Doe, 1]

Back to the top