openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Evan Ireland" <eirel...@sybase.com>
Subject RE: Preliminary design for supporting OpenJPA annotations in XML metadata.
Date Wed, 25 Jul 2007 00:18:53 GMT
Patrick,

I did something similar (but not quite the same) 
for some JPA prototyping some months back.

I wrote a tool that would introspect the JPA annotation
classes, and for each one (e.g. "interface Xyz"), would spit
out an 'equivalent' class XyzMetaData. For example:

package com.sybase.jpa.metadata;

public class ColumnResultMetaData
{
    // Generated by class com.sybase.jpa.metadata.MetaDataMaker
    // Please do not edit this file.

    private java.lang.String _name;

    public static com.sybase.jpa.metadata.ColumnResultMetaData
fromAnnotation(javax.persistence.ColumnResult annotation)
    {
        com.sybase.jpa.metadata.ColumnResultMetaData $md_1 = new
com.sybase.jpa.metadata.ColumnResultMetaData();
        $md_1._name = annotation.name();
        return $md_1;
    }

    public java.lang.String name()
    {
        return _name;
    }

    public void setName(java.lang.String value)
    {
        _name = value;
    }

    public static com.sybase.jpa.metadata.ColumnResultMetaData[]
fromAnnotations(javax.persistence.ColumnResult[] annotations)
    {
        int $length_1 = annotations.length;
        com.sybase.jpa.metadata.ColumnResultMetaData[] $array_2 = new
com.sybase.jpa.metadata.ColumnResultMetaData[$length_1];
        int $index_3;
        for ($index_3 = 0; $index_3 < $length_1; $index_3++)
        {
            $array_2[$index_3] = fromAnnotation(annotations[$index_3]);
        }
        return $array_2;
    }
}

Now it is easy to construct MetaData objects from annotations
(due to the generated class constructors) and one can imagine
easily constructing MetaData objects from XML descriptors.
Then the actual processing of meta data can be based on the
classes.

I have attached the source code for the tool. Please feel free
to adapt this for use in OpenJPA.

> -----Original Message-----
> From: Patrick Linskey [mailto:plinskey@gmail.com] 
> Sent: Wednesday, 25 July 2007 12:04 p.m.
> To: dev@openjpa.apache.org
> Subject: Re: Preliminary design for supporting OpenJPA 
> annotations in XML metadata.
> 
> I haven't read David and Marc's most recent emails, but 
> here's an idea that I've been toying with in terms of 
> unifying annotation and XML
> parsing: annotations are interfaces, so presumably we can 
> create new instances of types that implement them somehow. 
> (Maybe the JVM prevents this; I haven't tested.) If so, then 
> we could just have a single annotation parser, and have the 
> XML parser generate annotations to pipe into the annotation parser.
> 
> I'm not sure if that gets us anything, but it might be an 
> interesting direction to explore.
> 
> -Patrick
> 
> On 7/20/07, David Ezzio (asmtp) <dezzio@bea.com> wrote:
> > Hi,
> >
> > I'm starting to design support of XML metadata for OpenJPA 
> annotations 
> > in order to address OpenJPA-125 and OpenJPA-87.
> >
> > I've attached a zip containing a preliminary design 
> document, a sample 
> > openjpa_orm_1_0.xsd file and a sample OpenJPA ORM instance.
> >
> > It took quite a while to create the text document and it is best 
> > viewed as the tracks of a design process.  The design that 
> I worked on 
> > the most (the one with the most documentation) is not 
> necessarily the 
> > best design.  There are two alternatives suggested, and 
> there may be 
> > others that I haven't thought of.
> >
> > I think the fundamental choices facing us are these:
> >
> > 1. Do we construct an OpenJPA ORM schema that extends the JPA ORM 
> > schema?  Doing so, allows the user to use one metadata file 
> instead of 
> > two, and will enhance maintainability for our users' 
> applications.  Or 
> > do we construct a standalone OpenJPA ORM schema?  I've chosen the 
> > first option in the preliminary design, and I think it is 
> the best choice.
> >
> > 2. Do we use a syntactically loose "extension" element 
> format or do we 
> > construct new elements for each supported annotation?  Choosing the 
> > first makes it easy (I think) to support newly added annotations.
> > Choosing the second allows the schema validator to do most of the 
> > validation work.  I've chosen the first option in the preliminary 
> > design, but I'm not at all sure of the choice.
> >
> > 3. Do we envision support in XML for all OpenJPA annotations or for 
> > only a subset?  If a subset, how do we draw a bright line 
> that will be 
> > consistent and easily documented and followed over time?  
> I've chosen 
> > the first option in the preliminary design simply because 
> that is the 
> > brightest line that I can think of and because it gave me a 
> chance to 
> > look over the field of OpenJPA annotations.
> >
> > I'll be off on vacation for a week with very limited Internet 
> > connections, so please, take as much time as necessary to 
> consider the 
> > design, and carry on some discussions without me if the 
> spirit moves you.
> >
> > Thanks,
> >
> > David Ezzio
> >
> >
> 
> 
> --
> Patrick Linskey
> 202 669 5907
> 

Mime
View raw message