You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Heather Sterling <hs...@us.ibm.com> on 2009/03/10 16:09:32 UTC

FieldMetaData questions


Hi,

I was wondering how to retrieve the possible enum values from a
FieldMetaData structure.

I also wanted to know if there's a way to get other information, such as
the length of a field. (specified with @Column annotation).  I assume there
is, but I could not find it.

Lastly, is there a way to extend the metadata, such that I could tag a
field with a custom-defined property-value pair and retrieve it?  I saw
that there are some extension APIs on FieldMetaData, but I'm not sure what
the purpose of those are.  For example, in our current legacy code, we have
the idea of a "hidden" property.  I would like to be able to retrieve this
when looping through the fields in order to correctly transform the data to
our existing legacy structures.

Thanks,

Heather Sterling
Systems Management Development
Phone:  919-254-7163 T/L: 444-7163
Cell: 919-423-3143
Email: hsterl@us.ibm.com

Re: FieldMetaData questions

Posted by Pinaki Poddar <pp...@apache.org>.
Hi,
 > such that I could tag a field with a custom-defined property-value pair
and retrieve it? 

  Yes you can. At meta-level, you can mark a Field carrying implementation
specific data. See FieldMetaData.usesImplData();
  At an instance level every element can be attached with a 'user object'
which is opaque  to OpenJPA runtime.

> For example, in our current legacy code, we have the idea of a "hidden"
> property.  I would like to be 
> able to retrieve this when looping through the fields in order to
> correctly transform the data to
> our existing legacy structures.

  The other option (which is simpler) is to use Externalizer support that
annotates a field with a pair of conversion functions to translate between
in-memory and data store representation.
  A more involved approach in to write custom value handlers. 
  
  Both of them (externalizer and custom value) are adequately documented in
OpenJPA documentation. 

  Regards --

Pinaki


Heather Sterling wrote:
> 
> 
> 
> Hi,
> 
> I was wondering how to retrieve the possible enum values from a
> FieldMetaData structure.
> 
> I also wanted to know if there's a way to get other information, such as
> the length of a field. (specified with @Column annotation).  I assume
> there
> is, but I could not find it.
> 
> Lastly, is there a way to extend the metadata, such that I could tag a
> field with a custom-defined property-value pair and retrieve it?  I saw
> that there are some extension APIs on FieldMetaData, but I'm not sure what
> the purpose of those are.  For example, in our current legacy code, we
> have
> the idea of a "hidden" property.  I would like to be able to retrieve this
> when looping through the fields in order to correctly transform the data
> to
> our existing legacy structures.
> 
> Thanks,
> 
> Heather Sterling
> Systems Management Development
> Phone:  919-254-7163 T/L: 444-7163
> Cell: 919-423-3143
> Email: hsterl@us.ibm.com
> 

-- 
View this message in context: http://n2.nabble.com/FieldMetaData-questions-tp2455854p2456113.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: FieldMetaData questions

Posted by Michael Dick <mi...@gmail.com>.
Hi Heather.

Most of the info you want is already there in the FieldMapping /
FieldMetaData. It's just a matter of digging :-).

On Tue, Mar 10, 2009 at 10:09 AM, Heather Sterling <hs...@us.ibm.com>wrote:

>
>
> Hi,
>
> I was wondering how to retrieve the possible enum values from a
> FieldMetaData structure.
>

Something like this should work :

        ClassMetaData meta = JPAFacadeHelper.getMetaData(emf,
TestEntity.class);
        FieldMetaData fmd = meta.getField("myEnum");

        assertNotNull(fmd);
        Object [] enums = fmd.getType().getEnumConstants();
        for(Object o : enums ) {
            // do whatever you need to with the constants.
            System.out.format("%s%n", o);
        }

I also wanted to know if there's a way to get other information, such as
> the length of a field. (specified with @Column annotation).  I assume there
> is, but I could not find it.
>

Here you need the FieldMapping, not the metadata. From the mapping you can
get the columns, and from there the size.

        ClassMetaData meta = JPAFacadeHelper.getMetaData(emf,
TestEntity.class);
        FieldMetaData fmd = meta.getField("name");

        assertNotNull(fmd);

        FieldMapping fm = (FieldMapping) fmd;
        Column[] cols = fm.getColumns(); //
org.apache.openjpa.jdbc.schema.Column
        // @Column(length=32). Happens to be a string, but this should work
for other types.
        assertEquals(32, cols[0].getSize());

Lastly, is there a way to extend the metadata, such that I could tag a
> field with a custom-defined property-value pair and retrieve it?  I saw
> that there are some extension APIs on FieldMetaData, but I'm not sure what
> the purpose of those are.  For example, in our current legacy code, we have
> the idea of a "hidden" property.  I would like to be able to retrieve this
> when looping through the fields in order to correctly transform the data to
> our existing legacy structures.
>

I'm not sure. I'd need to look at it more. Maybe someone else on the list
has a quick answer, or more experience in this area.

Hope this helps
-mike


>
> Thanks,
>
> Heather Sterling
> Systems Management Development
> Phone:  919-254-7163 T/L: 444-7163
> Cell: 919-423-3143
> Email: hsterl@us.ibm.com