PostgreSQL array mapping

View: New views
6 Messages — Rating Filter:   Alert me  

PostgreSQL array mapping

by KARASZI Istvan-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi!

I'm new on the list and I've tried to search for this problem without
any luck. So sorry if this was discussed before.


I'm trying to implement a class which uses a PostgreSQL integer[]
field as data for an attribute. I've written a Converter (called
ArrayConverter) which converts the data from the Data value to Object
value and it's working very well, it looks like this:

       public Object convertDataValueToObjectValue(final Object from, final
Session session) {

               if (from instanceof Integer[]) {
                       final Integer[] to = (Integer[]) from;
                       return Arrays.asList(to);
               }

               throw new IllegalArgumentException("Unknown object type!");
       }

But I could not write the Object value to Data value converter because
I could not use any array data there. I've figured out that I cannot
use:

- the psql writing "{ 1, 2, 3, 4 }" format because it'll fail with
'ERROR: column "data" is of type integer[] but expression is of type
character varying' which is true of course because the result of the
convertObjectValueToDataValue method will be a String in this case

- the "ARRAY[1, 2, 3, 4]" for the same reason

- I've tried multiple ways to call a stored function to create an
ARRAY but I could not call any stored function from there. Is there a
way to do it? Or any way to save array from EclipseLink to PostgreSQL?

I've found this thread:
http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg01513.html
but the test mentioned in the CVS unfortunately does not exist in SVN
or I was enough stupid to not found it :(

thanks,
--
.: istvan karaszi :: raszi :: raszi@... :.
_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: PostgreSQL array mapping

by KARASZI Istvan-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Oct 2, 2009 at 1:17 AM, KARASZI Istvan <eclipse@...> wrote:
> I've found this thread:
> http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg01513.html
> but the test mentioned in the CVS unfortunately does not exist in SVN
> or I was enough stupid to not found it :(
I'm correcting myself, I've found it at:

http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/foundation/org.eclipse.persistence.oracle/src/org/eclipse/persistence/platform/database/oracle

and

http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/models/insurance/objectrelational


--
.: istvan karaszi :: raszi :: raszi@... :.
_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: PostgreSQL array mapping

by KARASZI Istvan-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi again,

am I right that EclipseLink does not support StructConverters with
PostgreSQL? :(
--
.: istvan karaszi :: raszi :: raszi@... :.
_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: Re: PostgreSQL array mapping

by tware :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Istvan,

   StructConverters should work regardless of the database.  They simply allow
you to write code that process the Struct at read time and write time.

   At the moment, the only premade struct converter we ship is for Oracle
Spatial types.  You could probably use it as an example of how to write some
other kind of struct converter.

-Tom

KARASZI Istvan wrote:
> hi again,
>
> am I right that EclipseLink does not support StructConverters with
> PostgreSQL? :(
_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: PostgreSQL array mapping

by James Sutherland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

If you use binding and in your converter convert the List back to an Integer[] does it work?  Are you able to write the field directly through JDBC, what do you need to bind in JDBC?

The StructureConverter is for data returned as instances of Struct from the database, but this seems to be different, as you get an Integer[].


KARASZI Istvan-2 wrote:
hi!

I'm new on the list and I've tried to search for this problem without
any luck. So sorry if this was discussed before.


I'm trying to implement a class which uses a PostgreSQL integer[]
field as data for an attribute. I've written a Converter (called
ArrayConverter) which converts the data from the Data value to Object
value and it's working very well, it looks like this:

       public Object convertDataValueToObjectValue(final Object from, final
Session session) {

               if (from instanceof Integer[]) {
                       final Integer[] to = (Integer[]) from;
                       return Arrays.asList(to);
               }

               throw new IllegalArgumentException("Unknown object type!");
       }

But I could not write the Object value to Data value converter because
I could not use any array data there. I've figured out that I cannot
use:

- the psql writing "{ 1, 2, 3, 4 }" format because it'll fail with
'ERROR: column "data" is of type integer[] but expression is of type
character varying' which is true of course because the result of the
convertObjectValueToDataValue method will be a String in this case

- the "ARRAY[1, 2, 3, 4]" for the same reason

- I've tried multiple ways to call a stored function to create an
ARRAY but I could not call any stored function from there. Is there a
way to do it? Or any way to save array from EclipseLink to PostgreSQL?

I've found this thread:
http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg01513.html
but the test mentioned in the CVS unfortunately does not exist in SVN
or I was enough stupid to not found it :(

thanks,
--
.: istvan karaszi :: raszi :: raszi@spam.raszi.hu :.

Re: PostgreSQL array mapping

by KARASZI Istvan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hello!

On Oct 6, 2009, at 3:26 PM, James Sutherland wrote:
> If you use binding and in your converter convert the List back to an
> Integer[] does it work?  Are you able to write the field directly  
> through
> JDBC, what do you need to bind in JDBC?
actually it didn't work.

but I solved the problem with a Converter which was converting from  
the String representation of the array to a List. we didn't need to  
write anything back to the database so this direction was enough.

--
KARASZI Istvan

_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users