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/Dynamic/def1"

(Dynamic Persistence)
 
(43 intermediate revisions by the same user not shown)
Line 1: Line 1:
<css>.source-xml {padding:4px;border:1px solid black;}</css><css>.source-java5 {padding:4px;border:1px solid black;}</css>
 
 
===== Dynamic Persistence =====
 
===== Dynamic Persistence =====
Dynamic Persistence is defined as the ability to create a persistent entity class and use it within an application without the Java class existing (no .java or .class files). This is typically accomplished by creating a class on-the-fly with a custom ClassLoader that uses a bytecode manipulation library (such as [[ASM|http://asm.objectweb.org], or [[others|http://www.java-source.net/open-source/bytecode-libraries[]).
+
<onlyinclude>
 +
Dynamic Persistence is defined as the ability to create a dynamic persistent entity and use it within an application without <i>a-priori</i> the entity's Java <tt>.class</tt> being present on the classpath (or in some <tt>.jar/.war</tt> archive).
  
Dynamic Persistence is - in essence - a <i>trick</i> with ClassLoaders. EclipseLink's meta-data describes a persistent entity in terms of a <b>Descriptor</b> which owns (one or more) <b>Mappings</b> that represent a class' member fields. The class' info is string-based - for instance in code:
+
The purpose of Dynamic Persistence is to enable simplified data access where only mapping information is required and no concrete Java model is required. This allows applications with dynamic storage requirements to avoid coupling to static classes or require specialized handling of new types. The application uses standard EclipseLink APIs to read, create, modify, and remove dynamic persistent entities from their data stores based on types that are either defined in XML mapping files or are constructed within the running application.
<source lang="java5">
+
</onlyinclude>
RelationalDescriptor addressDescriptor = new RelationalDescriptor();
+
addressDescriptor.setAlias("address");
+
addressDescriptor.setJavaClassName("com.foo.bar.Address");
+
</source>
+
or XML:
+
<source lang="xml">
+
<?xml version="1.0" encoding="UTF-8"?>
+
<object-persistence version="Eclipse Persistence Services - {some version}"
+
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
  xmlns:eclipselink="http://www.eclipse.org/eclipselink/xsds/persistence"
+
  >
+
  <name>relationships</name>
+
  <class-mapping-descriptors>
+
    <class-mapping-descriptor xsi:type="xml-class-mapping-descriptor">
+
      <class>com.foo.bar.Address</class>
+
      <alias>address</alias>
+
</source>
+
Because almost any value can be specified for the &lt;class&gt; (within the limits of Java naming requirements), there is the possibility that at runtime the class cannot be found. The trick is to provide a custom ClassLoader that upon detecting that <tt>com.foo.bar.Address</tt> does not exist, uses a bytecode manipulation library to <b>create</b> a class that agrees with the meta-data - in terms of the Mappings, their types, etc.
+

Latest revision as of 10:50, 17 September 2009

Dynamic Persistence

Dynamic Persistence is defined as the ability to create a dynamic persistent entity and use it within an application without a-priori the entity's Java .class being present on the classpath (or in some .jar/.war archive).

The purpose of Dynamic Persistence is to enable simplified data access where only mapping information is required and no concrete Java model is required. This allows applications with dynamic storage requirements to avoid coupling to static classes or require specialized handling of new types. The application uses standard EclipseLink APIs to read, create, modify, and remove dynamic persistent entities from their data stores based on types that are either defined in XML mapping files or are constructed within the running application.

Back to the top