----- Forwarded message from Juho M?kinen -----

Return-path: <juho>
Received: (from [EMAIL PROTECTED])
        by lysosomi.webcell.fi (8.9.3/8.9.3/Debian 8.9.3-21) id BAA25625;
        Sat, 1 Mar 2003 01:46:04 +0200
From: Juho M?kinen <juho>
Message-ID: <[EMAIL PROTECTED]>
Subject: Linked list (self references)
To: [EMAIL PROTECTED]
Date: Sat, 1 Mar 2003 01:46:04 +0200 (EET)
X-Mailer: ELM [version 2.4ME+ PL94 (25)]


I'm wondering if a following would work.

A Linked list in a collection like this:

create table list_node (
 id int primary key,
 prev references list_node,
 holder references holder,
 ...
);

create table holder (
 id int primary key,
 ...
);

And JDO classes:

public class list_node {
  int _id;
  list_node prev;
  holder Holder;
};

public class holder (
  int _id;
  ...
};

Now at the castor mapping I have:

<class name="list_node" identity="id" depends="holder">
 <map-to table="list_node"/>

 <field name="id"..... />

 <field name="prev" type="list_node">
   <sql name="prev"/>
 </field>

 <field name="holder" type="holder">
   <sql name="holder"/>
 </field>
</class>

<class name="holder" identity="id">
  <map-to table="holder"/>

  <field name="id"..... />

  <field name="list" type="list_node" collection="arraylist">
    <sql many-key="holder"/>
  </field>
</class>


The first list_node at the "linked list" has it's prev value set to null.
The next will have it's prev value set tho the previous list_node and so on.


The sql tables, classes and mapping file are just examples from my real application
(they aren't valid java/sql/xml code but you should get the idea)

So at the java code I'd just like to add new list_node classes into the
holder's ArrayList and the castor should add/remove corresponding sql
records to the database at the commit.

The question is that will this work? I have tried and it works
in some point but in other it won't: Adding a new list_node
to the collection like this:


holder list_holder = (from database using a OQL query)

list_node newNode = new list_node();
newNode.setHolder(list_holder);

list_node first_node_in_the_list = (from some search from the list_holder's collection)
first_node_in_the_list.setPrev(newNode);
newNode.setPrev(null);

db.commit();

For some reason this set's "first_node_in_the_list"'s prev value to null.

If I add a new node in the middle of the list it works just good.

Please respond and give me some ideas how to implement this.

 - jtm




 
 

----- End of forwarded message from Juho M?kinen -----


Reply via email to