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)
(Dynamic Persistence)
Line 1: Line 1:
 
<css>.source-xml {padding:4px;border:1px solid black;}</css><css>.source-java5 {padding:4px;border:1px solid black;}</css>
 
<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 <i>a-priori</i> the Java class existing (no <tt>.java</tt> or <tt>.class</tt> files).
+
Dynamic Persistence is defined as the ability to create a persistent entity class and use it within an application without <i>a-priori</i> the Java class existing (no <tt>.class</tt> file on the classpath or in the relevant <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 Java code:
+
===== Mechanism in Java5/Java6 =====
<source lang="java5">
+
In order to create a Java class at runtime without the use of the <tt>javac</tt> compiler, the use of a custom ClassLoaderer is required,
RelationalDescriptor addressDescriptor = new RelationalDescriptor();
+
along with a bytecode manipulation library (such as [http://asm.objectweb.org ASM] or some other [http://www.java-source.net/open-source/bytecode-libraries framework]).
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: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 <b>&lt;class&gt;</b>-tag (within the limits of Java naming conventions), there is the possibility that the class cannot be found. The <i>trick</i> then is to provide a custom ClassLoader that upon detecting that <tt>com.foo.bar.Address</tt> does not exist, uses a bytecode manipulation library (such as [http://asm.objectweb.org ASM] or some other [http://www.java-source.net/open-source/bytecode-libraries framework]) to <b>create</b> a class that agrees with the meta-data - in terms of the number of Mappings, their types, etc.
+

Revision as of 14:47, 31 August 2009

Dynamic Persistence

Dynamic Persistence is defined as the ability to create a persistent entity class and use it within an application without a-priori the Java class existing (no .class file on the classpath or in the relevant .jar/.war archive).

Mechanism in Java5/Java6

In order to create a Java class at runtime without the use of the javac compiler, the use of a custom ClassLoaderer is required, along with a bytecode manipulation library (such as ASM or some other framework).

Back to the top