Home » Modeling » EMF » [Resolved] [CDO] - HowTo customise the (de)serialization ?
[Resolved] [CDO] - HowTo customise the (de)serialization ? [message #890007] |
Wed, 20 June 2012 14:39 |
Bernard Sarter Messages: 88 Registered: August 2011 Location: Paris, France |
Member |
|
|
Hello,
I've a EMF model with a custom type (EDateTime = org.joda.time.DateTime, marked as serializable).
I have a class 'c' with a field 'f' of type EDateTime, that needs to contain a DateTime in UTC reference.
If I do not use CDO (just EMF), it works fine, I have eg. 2011-03-04T04:30:00.000Z.
If I use CDO (server with underlying mySql db), I get in the mySql db the field 'f' serialized as a "longtext latin1_swedish_ci" and it contains the string "2011-03-04T04:30:00.000Z" wich is Ok (so the serialization is fine), but a remote client will get "2011-03-04T05:30:00.000+01:00" which is basically the same time, but expressed in LocalTime (I'm in Paris, France, in March, LocalTime = GMT+1).
My understanding is that the 'deserialisation' does not know that it has to use UTC, so it uses the LocalTime per default.
How/where can I influence that ?
Thanks for any explanations ...
Regards,
Bernard.
[Updated on: Thu, 21 June 2012 07:27] Report message to a moderator
|
|
|
Re: [CDO] - HowTo customise the (de)serialization ? [message #890083 is a reply to message #890007] |
Thu, 21 June 2012 02:14 |
|
Am 20.06.2012 16:39, schrieb Bernard SARTER:
> Hello,
>
> I've a EMF model with a custom type (EDateTime = org.joda.time.DateTime, marked as serializable).
>
> I have a class 'c' with a field 'f' of type EDateTime, that needs to contain a DateTime in UTC reference.
>
> If I do not use CDO (just EMF), it works fine, I have eg. 2011-03-04T04:30:00.000Z.
>
> If I use CDO (server with underlying mySql db), I get in the mySql db the field 'f' serialized as a "longtext
> latin1_swedish_ci" and it contains the string "2011-03-04T04:30:00.000Z" wich is Ok (so the serialization is fine),
> but a remote client will get "2011-03-04T05:30:00.000+01:00" which is basically the same time, but expressed in
> LocalTime (I'm in Paris, France, in March, LocalTime = GMT+1).
>
> My understanding is that the 'deserialisation' does not know that it has to use UTC, so it uses the LocalTime per
> default.
>
> How/where can I influence that ?
Are you asking how you can influence the column data types in the database schema? There are two ways to do so:
1) Per EStructuralFeature via EAnnotations. See DBAnnotation.java:
public enum DBAnnotation
{
TABLE_MAPPING("tableMapping"), //
TABLE_NAME("tableName"), //
COLUMN_NAME("columnName"), //
COLUMN_TYPE("columnType"), //
COLUMN_LENGTH("columnLength"), //
TYPE_MAPPING("typeMapping");
public final static String SOURCE_URI = "http://www.eclipse.org/CDO/DBStore";
[...]
2) Or you can subclass org.eclipse.net4j.db.mysql.MYSQLAdapter and override the method getTypeName(IDBField).
When dealing with custom types there's also the possibility to add additional ITypeMappings to the DBStore by
registering instances of org.eclipse.emf.cdo.server.db.mapping.ITypeMapping.Factory with the IPluginContainer.INSTANCE,
possibly through the org.eclipse.net4j.util.factories extension point. Stefan, do we have examples for this scenario?
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
Re: [CDO] - HowTo customise the (de)serialization ? [message #890096 is a reply to message #890083] |
Thu, 21 June 2012 05:36 |
Bernard Sarter Messages: 88 Registered: August 2011 Location: Paris, France |
Member |
|
|
Hi,
Thank for your reply, but it seems that I wasn't clear in my problem description.
Let me start again:
Basically, I would just like to know how I can override the default "deserializer" used for my custom datatype "DateTime"...
(In my case, the deserialisation should be done like that:
DateTimeFormatter formatter = ISODateTimeFormat.dateTimeNoMillis().withZoneUTC();
c.setF(formatter.parseDateTime( rawSerializedStringCommingFromTheDb)); )
To be honest, I even don't know where this deserialization takes place (in net4j, in CDO, in EMF ?)
I guess I need to use some Annotations, but all I read so far about that sounds very complex and somehow cryptic, where my need looks simple and basic to me, so I'm probably missing something.
Regards,
Bernard.
|
|
|
Re: [CDO] - HowTo customise the (de)serialization ? [message #890101 is a reply to message #890096] |
Thu, 21 June 2012 06:12 |
|
Am 21.06.2012 07:36, schrieb Bernard SARTER:
> Hi,
>
> Thank for your reply, but it seems that I wasn't clear in my problem description.
>
> Let me start again:
>
> Basically, I would just like to know how I can override the default "deserializer" used for my custom datatype
> "DateTime"...
> (In my case, the deserialisation should be done like that:
>
> DateTimeFormatter formatter = ISODateTimeFormat.dateTimeNoMillis().withZoneUTC();
> c.setF(formatter.parseDateTime( rawSerializedStringCommingFromTheDb));)
>
> To be honest, I even don't know where this deserialization takes place (in net4j, in CDO, in EMF ?)
>
> I guess I need to use some Annotations, but all I read so far about that sounds very complex and somehow cryptic,
> where my need looks simple and basic to me, so I'm probably missing something.
Sorry that I'm still not exactly sure *where* you want to customize. Perhaps it's a pure EMF question and you're looking
for these methods that the EMF generator created in your XyzFactoryImpl class:
createAbcFromString(EDataType, String)
convertAbcToString(EDataType, Object)
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
Re: [CDO] - HowTo customise the (de)serialization ? [message #890107 is a reply to message #890096] |
Thu, 21 June 2012 07:08 |
Stefan Winkler Messages: 307 Registered: July 2009 Location: Germany |
Senior Member |
|
|
Hi Bernard,
have a look at org.eclipse.emf.cdo.tests.db.DBStoreTest.testStoreCustom()
in the project org.eclipse.emf.cdo.tests.db.
There is an example on how to map an object of class Custom (which is a
pair of integers) to a string "<integer1>!<integer2>" and back.
If you provide these two ways (the toString()-method and
valueOf()-factory), EMF will automatically use this serialization. (As
Eike said, if you don't have control over your implementation class, you
can also modify the createFromString and convertToString methods in the
generated FactoryImpl).
CDO will per default map all custom types to a string datatype in the
database (LONGTEXT obviously, if your observation is right, I'd need to
check for clarification) and use the EMF to/from-string serialization.
As Eike said, you can influence the target DB type using an EAnnotation.
As long as the target type conforms to a string (VARCHAR, TEXT etc.),
the mapping can be done transparently using the above methods.
It is also possible to map a custom datatype to an arbitrary data type.
In this case you have to provide an annotation for your feature pointing
out the desired DB type and also provide a custom type mapper which
translates you type to the correct SQL calls. (Eike pointed this out in
his first answer)
Cheers,
Stefan
Am 21.06.12 07:36, schrieb Bernard SARTER:
> Hi,
>
> Thank for your reply, but it seems that I wasn't clear in my problem
> description.
>
> Let me start again:
>
> Basically, I would just like to know how I can override the default
> "deserializer" used for my custom datatype "DateTime"...
> (In my case, the deserialisation should be done like that:
>
> DateTimeFormatter formatter =
> ISODateTimeFormat.dateTimeNoMillis().withZoneUTC();
> c.setF(formatter.parseDateTime( rawSerializedStringCommingFromTheDb));)
>
> To be honest, I even don't know where this deserialization takes place
> (in net4j, in CDO, in EMF ?)
>
> I guess I need to use some Annotations, but all I read so far about that
> sounds very complex and somehow cryptic, where my need looks simple and
> basic to me, so I'm probably missing something.
>
> Regards,
> Bernard.
>
>
|
|
| |
Goto Forum:
Current Time: Fri Apr 19 23:59:02 GMT 2024
Powered by FUDForum. Page generated in 0.03598 seconds
|