Some 'more, in-depth' information on Oracle BPEL PM, ESB and other SOA, day2day things

Wednesday, March 31, 2004

BC4J: TimeStamp with Timezone ?! How to get it to work ...

Ever had to use timeStamps with timezone in a bc4j App?
- Recently we had to implement this @ another customer, so big question rised up, what domain to use, as there's no suitable right now.

So quickly a small work/around was discovered .. to solve this issue without building the domain for yourself :-)

Probably one of the greatest things in Oracle Database (just seen from the sql-view) is the implicit conversion .. meaning inserting a String with a given format eg. into a date (or in our case TimeStamp with TimeZone column).

And this is the trick around that:
  • When creating bc4j components - you will notice that the mapping that has been done by the wizard
    maps the timestamp column to an oracle.jbo.domain.Date type (both on EO / and VO level).

  • After successfull generation, change the mappingtype (Date) on both levels to String

  • Now create some kind of type-class .. that knows two public constructors, one with a java.util.Calendar, and the other one with a String as parameter

  • The Calendar constructor is used (within your client) when you want to write to DB, while the String constructor formats the value from DB into a human-readable format & into a calendar, for further usage in the app

  • Just put in two 'more' methods - that do exactly the same - as our two constructors, named getAsCalendar:java.util.Calendar, and the other one named getAsString:String - to have it working the other way round ... These will be used to fill up the Row with a String (getAsString:String) or in the app (Type.getAsCalendar:Calendar)

  • hint: use SimpleDateFormatter, saves you lots of time when converting around :)

  • The last step is overwriting the afterConnect-method (which fires immediatly after the DB-connection has been assigned to your AM) in your AppModuleImpl.java and execute a short statement, specifying the session-format for NLS_TIMESTAMP_TZ_FORMAT parameter


  • 0 Comments:

    Post a Comment

    << Home