Tomasz,
it looks like I found a possible solution. To proceed, can you please file a bug
report (flagged as enhancement request) at http://bugzilla.exolab.org.
Once done, I'll attach a possible patch for review, and we'll take it from there.
Regards
Werner
On Thu, 08 Apr 2004 13:21:39 +0200, Tomasz Piontek wrote:
>Hi,
>
>I attached your response to my mail manually (didn't do replay-to), because I didn't
>get it directly.
>I send several times "subscribe" request, but didn't get any response and any
>messages coming from castor-dev mailing list.
>I found your response in archive, but unfortunately didn't get it.
>
>
>... but returning to the issue:
>
>I modified sources of castor-0.9.5.3.
>
>I added two convertors Long <-> castor.types.Duration in SQLTypes.java file:
>
> new TypeConvertorInfo( new SQLTypeConvertor(
> org.exolab.castor.types.Duration.class, java.lang.Long.class ) {
> public Object convert( Object obj, String param ) {
> return new Long( ( (org.exolab.castor.types.Duration) obj
> ).toLong() );
> }
> } ),
> new TypeConvertorInfo( new SQLTypeConvertor( java.lang.Long.class,
> org.exolab.castor.types.Duration.class ) {
> public Object convert( Object obj, String param ) {
> return new org.exolab.castor.types.Duration( ( ( Long ) obj
> ).longValue() );
> }
> } )
>
>and for following mapping file:
>
><mapping xmlns="http://castor.exolab.org/" xmlns:cst="http://castor.exolab.org/">
> <description>Castor generated mapping file</description>
> <class cst:name="grms.castorgen.Dates_time" identity="dbId"
> key-generator="MAX">
> <description>Default mapping for class
> grms.castorgen.Dates_time</description>
> <map-to cst:xml="dates_time" table="date_time"/>
> <field name="dbId" type="int" direct="true">
> <bind-xml name="db-id" node="attribute"/>
> <sql name="date_id" type="integer"/>
> </field>
>
> <field cst:name="date_with_time" cst:type="java.util.Date"
> cst:required="true">
> <bind-xml name="date_with_time" node="element"/>
> <sql name="date_time" type="bigint"/>
> </field>
>
> <field cst:name="interval"
> cst:type="org.exolab.castor.types.Duration" cst:required="true">
> <bind-xml name="interval" node="element"/>
> <sql name="interval" type="bigint"/>
> </field>
>
> </class>
></mapping>
>
>
>got following exception:
>
>[test] org.exolab.castor.jdo.DatabaseNotFoundException: Field element,
>"org.exolab.castor.types.Duration" not found!
>[test] org.exolab.castor.mapping.MappingException: Field element,
>"org.exolab.castor.types.Duration" not found!
>[test] at org.exolab.castor.persist.DatingService.close(DatingService.java:127)
>[test] at org.exolab.castor.persist.ClassMolder.resolve(ClassMolder.java:525)
>[test] at org.exolab.castor.persist.LockEngine.<init>(LockEngine.java:164)
>[test] at
>org.exolab.castor.persist.PersistenceEngineFactory.createEngine(PersistenceEngineFactory.java:82)
>[test] at
>org.exolab.castor.jdo.engine.DatabaseRegistry.<init>(DatabaseRegistry.java:194)
>[test] at
>org.exolab.castor.jdo.engine.DatabaseRegistry.<init>(DatabaseRegistry.java:157)
>[test] at
>org.exolab.castor.jdo.engine.DatabaseRegistry.loadDatabase(DatabaseRegistry.java:283)
>[test] at org.exolab.castor.jdo.JDO.getDatabase(JDO.java:603)
>[test] at Test.run(Test.java:92)
>[test] at Test.main(Test.java:62)
>
>Any help or hint what to do is welcome.
>Which files have to be also modified?
>
>If it is not a problem please add my emial-address directly in TO: section, as I
>wrote I don't get mails from castor-dev.
>Werner, sorry that I sent this mail also directly to you, but I did so many attempts
>to subscribe and unsubscibe, than I'm not sure if this mail will arrive to
castor-dev.
>
>All the best,
>Tomek
>
>
>
>
>
>#######################################################################
>Previous mails in this thread
>
>Tomek,
>
>please see inline ...
>
>Werner
>
>On Tue, 06 Apr 2004 09:39:25 +0200, Tomasz Piontek wrote:
>
>>
>>Hi,
>>
>>The main question is: Does Castor-JDO support the castor.types.Duration
>>type?
>>
>>If the answer is YES:
>>What should be the SQL type in mapping file?
>>What type should be the field in database? The "interval" one (postgres) ?
>
>Whilst I cannot answer any of these questions top of my head (.iow, without
>consulting
>code first), I can point you to the right places of code to either
>investigate yourself.
>
>>If the answer is NOT:
>>Do you plan to add such support? When ...?
>>Is there any simple way to add it, assuming that I'm a newbie ?
>Afaik, yes. Read on ...
>
>>I analysed the code and found that (in my opinion) the simplest way to
>>workaround the lack of support is to write the convertor Long <->
>>Duration and store the duration in the database as integer. I have to
>>thing over what type will be the best( long, integer, bigint).
>>Any suggestions, opinions about this "solution"?
>>Is there any guide/set of hints how to write convertors?
>No, there is not ... as it wasn't originally conceived that convertors should be
>configurable by users, I'd say.
>
>>Is it enought to add couple of new TypeConvertorInfo( new
>>SQLTypeConvertor( Long, Duration) in SQLType file ?
>Imho, yes. As I am playing around with these myself (thinking about an exception
>mechanism for cases where a single database (e.g. mySQL) does not
>support a feature generally available otherwise, I can confirm that this would be the
>right place to add such support. Just make sure when doing so that
>your newly added convertor is getting called by creating test cases that demonstrate
>this.
>
>If you happen to have a solution, please post an enhancement request via
>http://bugzilla.exolab.org and attach a unified patch, and one of us will take
>care of this.
>
>>
>>All the best,
>>Tomek
>>
>>--
>>***********************************************************
>>* Tomasz Piontek [EMAIL PROTECTED] *
>>* Research Programmer - GridLab Project *
>>* Poznan Supercomputing and Networking Center *
>>* tel.(+48 61) 858-21-72 fax.(+48 61) 858-21-51 *
>>***********************************************************
>>
>>-----------------------------------------------------------
>>If you wish to unsubscribe from this mailing, send mail to
>>[EMAIL PROTECTED] with a subject of:
>> unsubscribe castor-dev
>>
>
>-----------------------------------------------------------
>If you wish to unsubscribe from this mailing, send mail to
>[EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
>
>--
>***********************************************************
>* Tomasz Piontek [EMAIL PROTECTED] *
>* Research Programmer - GridLab Project *
>* Poznan Supercomputing and Networking Center *
>* tel.(+48 61) 858-21-72 fax.(+48 61) 858-21-51 *
>***********************************************************
>
>
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev