Custom array column types in EO model
Custom array column types in EO model
- Subject: Custom array column types in EO model
- From: Paul Hoadley via Webobjects-dev <email@hidden>
- Date: Wed, 2 Nov 2022 16:13:18 +1030
- Feedback-id: i671c40f3:Fastmail
Hello,
I'm trying to get this to work for PostgreSQL, though I suspect it would be
similar for any RDBMS that offered a type like "text[]":
https://www.postgresql.org/docs/current/arrays.html
Ideally, I'd like to map an NSArray<String> attribute on the model side to a
text[] column in Postgres, though any variation on this would be a good start.
I can't quite get there, even with the smarts added by ERAttributeExtension.
This is as close as I can get:
{
adaptorValueConversionClassName =
"net.logicsquad.woextensions.eof.LSValueConversion";
adaptorValueConversionMethodName =
stringArrayToPostgreSQLTextArray;
allowsNull = Y;
columnName = "metadata_key_list";
externalType = anyarray;
name = metadataKeyList;
valueClassName = "com.webobjects.foundation.NSArray";
valueFactoryClassName =
"net.logicsquad.woextensions.eof.LSValueConversion";
valueFactoryMethodName = arrayToStringArray;
},
I'm only working on the output side for the minute. LSValueConversion.
stringArrayToPostgreSQLTextArray(NSArray<String>) returns a subclass of
java.sql.Array, which I assume is what the Postgres JDBC driver wants. However,
when I try to save an object, it's EOAttribute that complains:
[2022-11-2 5:31:59 UTC] <main>
com.webobjects.eoaccess.EOGeneralAdaptorException: EOAttribute
adaptorValueByConvertingAttributeValue(Object): Unable to convert value of
class net.logicsquad.woextensions.eof.PostgresqlTextArray for attribute
'metadataKeyList' in entity 'DocumentVersion' to adaptor type
EOAttribute.AdaptorBytesType. Check the signature of the conversion method
com.webobjects.foundation.NSArray.stringArrayToPostgreSQLTextArray().
To my eye, that's suggesting that the conversion method is not producing an
object of type "bytes", which is true enough—it's a subclass of java.sql.Array.
It doesn't help to comment out the part of EOAttribute that's throwing that
exception, either:
2022-11-02 05:40:58.728 WARN NSLog - A fatal exception occurred: Unable to
create a byte representation for class
"net.logicsquad.woextensions.eof.PostgresqlTextArray"
At this point I'm out of ideas. Has anyone done this or anything like it?
--
Paul Hoadley
https://logicsquad.net/
https://www.linkedin.com/company/logic-squad/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden