Custom Conversion [message #1196535] |
Tue, 19 November 2013 08:13  |
Eclipse User |
|
|
|
We are using EclipseLink JPA with an OpenEdge database and we have a problem with a timestamp field which is also used as version:
@Basic()
@Column(name = "mutdatime")
@Version
private Timestamp changedOn = null;
The mutdatime field in the database is defined as DATETIME-TZ which is a timestamp field that includes timezone information. The JDBC driver (by DataDirect) maps the field as a String field and produces timestamps like this:
2013-10-09 11:05:58:528 + 02:00
The default platform of EL works pretty well with these timestamps but we noticed problems as soon as our daylight saving changed in october.
We would like to do the java.sql.Timestamp <--> String conversion ourselves in order to fix issues with the time zone. For this we created a subclass of org.eclipse.persistence.platform.database.DatabasePlatform and have overridden the following methods:
@Override
public Object convertObject(Object sourceObject, Class javaClass)
throws ConversionException {
if (sourceObject instanceof String && javaClass.equals(Timestamp.class)) {
// do our own conversion
}
return super.convertObject(sourceObject, javaClass);
}
@Override
public Object convertToDatabaseType(Object value) {
if (value instanceof Timestamp) {
// do our own conversion
}
return super.convertToDatabaseType(value);
}
@Override
public void setParameterValueInDatabaseCall(Object parameter,
PreparedStatement statement, int index, AbstractSession session)
throws SQLException {
if (parameter instanceof Timestamp) {
String converted = (String) convertToDatabaseType(parameter);
statement.setString(index, converted);
return;
}
super.setParameterValueInDatabaseCall(parameter, statement, index,
session);
}
This works but I'm not sure whether I have gotten the right methods. For instance, overriding setParameterValueInDatabaseCall seems unnecessary because there already is a conversion for this direction in convertToDatabaseType, but it is not used except for the log. Can anyone point me to an example or to documentation for this kind of platform adaption?
Thanks & best regards,
Peter
|
|
|
|
|
|
Re: Custom Conversion [message #1287210 is a reply to message #1196535] |
Mon, 07 April 2014 10:32  |
Eclipse User |
|
|
|
Good morning,
Is there any documentation that explains how to setup an OpenEdge Database
for working with JPA?
I've search in the OpenEdge Documentacion, OpenEdge KBase and couldn't find
any step by step instructions.
Where did you find how to make this connection?
Have a nice day and thanks for your cooperation.
JAE
|
|
|
Powered by
FUDForum. Page generated in 0.58149 seconds