You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by idan <id...@gmail.com> on 2010/10/13 16:50:28 UTC

Custom Annotations

Heya,

I'd like to add my own custom annotations to OpenJPA (field annotations).

So far I understood i'll probably have to replace
AnnotationPersistenceMetaDataParser with my own
implementation which will take care of my custom annotations and somehow add
them to the existing or my own derived FieldMetaData implementations.

My final (for now) goal is to add extra SQL syntax to the create table
statement for the custom annotated fields.

What would be the best way to eventually pass this information to
DBDictionary's getCreateTableSQL method?

Thanks,
Idan

-- 
View this message in context: http://openjpa.208410.n2.nabble.com/Custom-Annotations-tp5631231p5631231.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.

Re: Custom Annotations

Posted by idan <id...@gmail.com>.
Thanks Jeremy.

I still don't understand how can i get access to FieldMetaData/FieldMapping
instances when i only have a Table instance and the SchemaGroup instance..


Thanks,
Idan

-- 
View this message in context: http://openjpa.208410.n2.nabble.com/Custom-Annotations-tp5631231p5652510.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.

Re: Custom Annotations

Posted by Jeremy Bauer <te...@gmail.com>.
Hi Idan,

Field level information is stored in OpenJPA's FieldMetaData or FieldMapping
(a subclass of FieldMetaData) objects.  FieldMetaData extends an abstract
class org.apache.openjpa.meta.Extentions.  While I've never used Extensions,
it looks like you could parse out your specific annotation in the annotation
parser and set a value in the FieldMetaData as an extension.  Then,
depending on the method you are overriding, you may be able to get access to
the FieldMetaData/FieldMapping and its extension(s) within your custom
dictionary.

-Jeremy

On Tue, Oct 19, 2010 at 10:41 AM, idan <id...@gmail.com> wrote:

>
> Hey,
>
> I'm still struggling with the code understanding how exactly to get my new
> annotation pass all the way to the create table statement in DBDictionary
> (I
> implemented my own custom dictionary).
>
> I started by identifying the annotation in
> AnnotationPersistenceMappingParser/AnnotationPersistenceMetaDataParser but
> i
> still cant manage to actually pass this information onwards.
>
> Currently i'm only trying to add a boolean flag which states if my
> annotation exists on a certain field or not.
>
> Note that I don't want to change OpenJPA's code but to inject my own
> implementations where needed.
>
> Any clues here?
>
> Thanks,
> Idan
>
>
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/Custom-Annotations-tp5631231p5651345.html
> Sent from the OpenJPA Developers mailing list archive at Nabble.com.
>

Re: Custom Annotations

Posted by idan <id...@gmail.com>.
Hey,

I'm still struggling with the code understanding how exactly to get my new
annotation pass all the way to the create table statement in DBDictionary (I
implemented my own custom dictionary).

I started by identifying the annotation in
AnnotationPersistenceMappingParser/AnnotationPersistenceMetaDataParser but i
still cant manage to actually pass this information onwards.

Currently i'm only trying to add a boolean flag which states if my
annotation exists on a certain field or not.

Note that I don't want to change OpenJPA's code but to inject my own
implementations where needed.

Any clues here?

Thanks,
Idan



-- 
View this message in context: http://openjpa.208410.n2.nabble.com/Custom-Annotations-tp5631231p5651345.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.

Re: Custom Annotations

Posted by idan <id...@gmail.com>.
Thanks for your reply.

My custom annotations are very specific to the system i'm working on which
has its own JDBC driver which accepts additional parameters in the CREATE
TABLE statement.

So I guess i'm not going to contribute these annotations to OpenJPA since
they're not usable with other systems.
I am willing to write a documentation page regarding how to add custom
annotations to OpenJPA once i figure out everything and maybe in the future
provide a simple solution for custom annotations if thats accepted.

Regarding the dictionary, i'm using my own custom dictionary.

Once I have the relevant information in the class/field metadata.. how do i
pass it to the dictionary?
Do I need to add this information to the relevant Table/Column classes?
If so, where exactly do they get filled with the meta data information?

Thanks,
Idan
-- 
View this message in context: http://openjpa.208410.n2.nabble.com/Custom-Annotations-tp5631231p5631452.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.

Re: Custom Annotations

Posted by Rick Curtis <cu...@gmail.com>.
Idan -

 First off, can I ask what are the custom annotations are that you want to
add? Do you plan on contributing them back to OpenJPA? I'll try my best to
answer your questions here...

> So far I understood i'll probably have to replace
AnnotationPersistenceMetaDataParser with my own implementation which will
take care of my custom annotations and somehow add
You'll probably need to extend AnnotationPersistenceMappingParser to parse
out the new annotation and the information should be stored in field/class
metadata.

> My final (for now) goal is to add extra SQL syntax to the create table
statement for the custom annotated fields. What would be the best way to
eventually pass this information to DBDictionary's getCreateTableSQL method?
What DBs support the additional SQL that you want to issue? If it is generic
and all DBs *should* support it, yes the DBDictionary is the proper place.
If it isn't supported by all DBs you'll need to put it in the proper
dictionary. ie:MySQLDictionary


Thanks,
Rick

On Wed, Oct 13, 2010 at 9:50 AM, idan <id...@gmail.com> wrote:

>
> Heya,
>
> I'd like to add my own custom annotations to OpenJPA (field annotations).
>
> So far I understood i'll probably have to replace
> AnnotationPersistenceMetaDataParser with my own
> implementation which will take care of my custom annotations and somehow
> add
> them to the existing or my own derived FieldMetaData implementations.
>
> My final (for now) goal is to add extra SQL syntax to the create table
> statement for the custom annotated fields.
>
> What would be the best way to eventually pass this information to
> DBDictionary's getCreateTableSQL method?
>
> Thanks,
> Idan
>
>