Hi Alessandro,

looking for the guidlines to write test cases I recognized that some links point to our old bug tracking system bugzilla. Please take care to use the new jira sytem at:

http://jira.codehaus.org

Guidlines on how to submit a bug report and write a test case can be found at:

http://castor.codehaus.org/how-to-submit-a-bug.html

If you need more information please ask.

Ralf


Alessandro Imperio schrieb:
Hi Ralf,

since I'm a newbie of the Castor world, could you provide me some
guideline for writing a test case?

Thank you

Alessandro

2005/7/18, Ralf Joachim <[EMAIL PROTECTED]>:

Hi Alessandro,

I think such a update-or-create-if-not-available method would be a good
addition to current functions.

I suggest to create a new issue in jira. Write a test case so that
others can reproduce the problem and attach that to the new issue. We
also wouldn't mind if you'll start implementing this function and
contribute that to castor ;-) .

Having said that Gregory's idea to retrieve objects from the database at
unmarshalling by using something like a FieldHandler also sounds very
interesting. As I don't know the XML side well, I don't know if XML
offers something like that or how much work it would be to implement.

Regards
Ralf


Alessandro Imperio schrieb:

The ID and all the primary key info are stored in the XML file (I have
to manage through XML the exchange of objects that must share the same
ID, so this information could be retrieved directly from the XML).
I thought a possible solution with autostore set to false:

1. Unmarshall the XML --> create the object tree
2. Starting from the top of the tree, try loading the first object
using the db.load() method
3. If the load succeeds, the object already exists so update all its
properties with the object previously obtained through unmarshall.
4. If the load fails, create the object using the db.create() method.
5. Repeat these steps for each sub-object recursively.

I'm asking why Castor doesn't implement such a mechanism forcing the
user to write the procedure for the update.

2005/7/18, Gregory Block <[EMAIL PROTECTED]>:


On 18 Jul 2005, at 09:25, Alessandro Imperio wrote:



I tried to unmarshall the XML file, create the object tree I need, set
autostore to true and call the db.create() method, but this works only
if the objects didn't already exist in the DB, because Castor tries to
create all the objects with an INSERT sql statement.


... yup.




The question is: which is the shortest path to do this? It seems like
I have to traverse all the object tree manually, creating all the
related objects and doing all the checks, but the tree could be very
complex... Does Castor provide an automatic mechanism for creating an
object in the DB if it doesn't exist or update it if it already exist?


Just thinking out loud:

There's one half of me that says this could be automated; but being
automatic would depend, specifically, on the primary keys on the
table.  If the inbound XML knew the information based on the table's
primary key data, you'd have a way of saying "this object is the same
as this row in the table"; then there'd be some theoretical way of
matching the object against the database representation on the update
call.  You'd still have the problem of requesting a modification to a
row of the database through an object you didn't load via castor, of
course.  Moreover, this is only going to work for a strict subset of
real-world data (the world where id rows don't exist in the XML, and
do exist in the data).

Another option would be to change the way Castor instantiates
objects; you could, at that point, hand it something that was 'aware'
of how to instantiate an object from Castor's db backend, and return
a fresh one when it didn't exist in the DB; finder queries could be
used to locate the correct data.

However, that's then going to run into issues when it comes to the
remainder of the object tree in 1:n/m:n relationships, as the
'instantiator' needs to verify that object isn't already present on
the previous object.


Gut feeling:  working on the way object instantiation works should
provide a solution.  Not sure it will today, however.




-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------




-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

--

Syscon Ingenieurbüro für
Meß- und Datentechnik GmbH
Ralf Joachim
Raiffeisenstraße 11
D-72127 Kusterdingen
Germany

Tel.   +49 7071 3690 52
Mobil: +49 173 9630135
Fax    +49 7071 3690 98

Email: [EMAIL PROTECTED]
Web:   www.syscon-world.de

-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------




-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

--

Syscon Ingenieurbüro für
Meß- und Datentechnik GmbH
Ralf Joachim
Raiffeisenstraße 11
D-72127 Kusterdingen
Germany

Tel.   +49 7071 3690 52
Mobil: +49 173 9630135
Fax    +49 7071 3690 98

Email: [EMAIL PROTECTED]
Web:   www.syscon-world.de

-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

Reply via email to