|
|
|
|
Re: Migration from Dali 2.0 to 2.1 [message #435037 is a reply to message #435024] |
Tue, 02 December 2008 21:24 |
Karen Butzke Messages: 220 Registered: July 2009 |
Senior Member |
|
|
> 3. I have a bunch of errors around setting and getting Temporal types.
> It sounds like I need to use these new ConvertibleMapping objects.
> Currently my code looks like this:
> ((ColumnMapping)mapping).setTemporal(TemporalType.DATE);
> and
> TemporalType temporalType = ((ColumnMapping)mapping).getTemporal();
> I found a few example in your plugins showing how to get TemporalTypes:
> if (this.javaIdMapping.getConverter().getType() ==
> Converter.TEMPORAL_CONVERTER) {
> org.eclipse.jpt.core.context.TemporalType javaTemporalType =
> ((TemporalConverter) this.javaIdMapping.getConverter()).getTemporalType();
> }
> Is this the best way to go about finding the TemporalType? I assume if
> the mapping has no Temporal_Converter then that means no TemporalType
> has been set on the mapping?
Yes, you have found the correct replacement code. Your assumption is
correct except for the invalid case where you have multiple converters
defined on the mapping. Say the user had entered both @Lob and @Temporal,
this is not valid in JPA, and should give a validation error (though we do
not have one defined at the moment). If you look in
GenericJavaBasicMapping.specifiedConverterType(JavaResourceP ersistentAttribute)
you'll see which converter "wins" in this invalid case. I do not remember
the reasoning behind that order, it is probably the order that the
EclipseLink JPA implementation uses, since the JPA spec doesn't define
this.
> I wasn't able to find a good example of setting a Temporal type. Would I
> just add a new TemporalConverter to my mapping and then set the value? I
> wasn't sure if I could just add a new one because the javadoc in
> ConvertibleMapping says calling setSpecifiedConverter(String) will
> remove any old converters. Is it safe to do that?
((ConvertibleMapping)mapping).setSpecifiedConverter(Converte r.TEMPORAL_CONVERTER);
((TemporalConverter)convertibleMapping.getSpecifiedConverter ()).setTemporalType(TemporalType.Date)
This is the correct replacement for this code. Temporal, Lob, Enumerated
are all mutually exclusive in the JPA spec so if you call
setSpecifiedConverter all it is doing is removing the Lob or Enumerated,
if they exist. If your source code was originally in a valid state, only
one converter annotation, it will leave it in that valid state by removing
the old converter annotation and adding the new. If it was already in an
invalid state, then it will still be in an invalid state since only 1 of
the converter annotations will be removed and the new one will be added.
|
|
|
|
|
|
|
|
|
Re: Migration from Dali 2.0 to 2.1 - OrmResourceModel [message #435049 is a reply to message #435048] |
Fri, 05 December 2008 22:04 |
Paul Fullbright Messages: 201 Registered: July 2009 |
Senior Member |
|
|
Leonard Theivendra wrote:
> Hi Paul, given a JpaFile instance for persistence.xml or orm.xml, what is
> the recommended way to get a PersistenceResource or OrmResource model in
> 2.1 please?
> I see PersistenceResourceModelProvider.getModelProvider(IFile) and
> OrmResourceModelProvider.getModelProvider(IFile) but they seem to be in an
> internal package?
> Thanks,
> Len.
Hi Len,
Can you give me a better idea of what it is you're trying to do? Are you
needing to get here from a JpaFile, or is that the only convenient handle
you have at the moment?
The resource model providers were intended to replace the artifact edits,
and I was pretty sure I put them in the same package, but I could be
mistaken. At any rate, while not officially (or provisionally) API, they
should be safe to use in that they'll do what you want them to, but they
may not be promoted to actual API in the next release. We're still
looking at what kind of API people need at this level, so any information
you can give us will help us provide what's needed.
Thanks,
- Paul
|
|
|
|
|
|
|
|
Re: Migration from Dali 2.0 to 2.1 [message #613113 is a reply to message #435024] |
Tue, 02 December 2008 21:24 |
Karen Butzke Messages: 220 Registered: July 2009 |
Senior Member |
|
|
> 3. I have a bunch of errors around setting and getting Temporal types.
> It sounds like I need to use these new ConvertibleMapping objects.
> Currently my code looks like this:
> ((ColumnMapping)mapping).setTemporal(TemporalType.DATE);
> and
> TemporalType temporalType = ((ColumnMapping)mapping).getTemporal();
> I found a few example in your plugins showing how to get TemporalTypes:
> if (this.javaIdMapping.getConverter().getType() ==
> Converter.TEMPORAL_CONVERTER) {
> org.eclipse.jpt.core.context.TemporalType javaTemporalType =
> ((TemporalConverter) this.javaIdMapping.getConverter()).getTemporalType();
> }
> Is this the best way to go about finding the TemporalType? I assume if
> the mapping has no Temporal_Converter then that means no TemporalType
> has been set on the mapping?
Yes, you have found the correct replacement code. Your assumption is
correct except for the invalid case where you have multiple converters
defined on the mapping. Say the user had entered both @Lob and @Temporal,
this is not valid in JPA, and should give a validation error (though we do
not have one defined at the moment). If you look in
GenericJavaBasicMapping.specifiedConverterType(JavaResourceP ersistentAttribute)
you'll see which converter "wins" in this invalid case. I do not remember
the reasoning behind that order, it is probably the order that the
EclipseLink JPA implementation uses, since the JPA spec doesn't define
this.
> I wasn't able to find a good example of setting a Temporal type. Would I
> just add a new TemporalConverter to my mapping and then set the value? I
> wasn't sure if I could just add a new one because the javadoc in
> ConvertibleMapping says calling setSpecifiedConverter(String) will
> remove any old converters. Is it safe to do that?
((ConvertibleMapping)mapping).setSpecifiedConverter(Converte r.TEMPORAL_CONVERTER);
((TemporalConverter)convertibleMapping.getSpecifiedConverter ()).setTemporalType(TemporalType.Date)
This is the correct replacement for this code. Temporal, Lob, Enumerated
are all mutually exclusive in the JPA spec so if you call
setSpecifiedConverter all it is doing is removing the Lob or Enumerated,
if they exist. If your source code was originally in a valid state, only
one converter annotation, it will leave it in that valid state by removing
the old converter annotation and adding the new. If it was already in an
invalid state, then it will still be in an invalid state since only 1 of
the converter annotations will be removed and the new one will be added.
|
|
|
|
|
|
|
|
|
Re: Migration from Dali 2.0 to 2.1 - OrmResourceModel [message #613129 is a reply to message #435048] |
Fri, 05 December 2008 22:04 |
Paul Fullbright Messages: 201 Registered: July 2009 |
Senior Member |
|
|
Leonard Theivendra wrote:
> Hi Paul, given a JpaFile instance for persistence.xml or orm.xml, what is
> the recommended way to get a PersistenceResource or OrmResource model in
> 2.1 please?
> I see PersistenceResourceModelProvider.getModelProvider(IFile) and
> OrmResourceModelProvider.getModelProvider(IFile) but they seem to be in an
> internal package?
> Thanks,
> Len.
Hi Len,
Can you give me a better idea of what it is you're trying to do? Are you
needing to get here from a JpaFile, or is that the only convenient handle
you have at the moment?
The resource model providers were intended to replace the artifact edits,
and I was pretty sure I put them in the same package, but I could be
mistaken. At any rate, while not officially (or provisionally) API, they
should be safe to use in that they'll do what you want them to, but they
may not be promoted to actual API in the next release. We're still
looking at what kind of API people need at this level, so any information
you can give us will help us provide what's needed.
Thanks,
- Paul
|
|
|
|
|