[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how data is stored ?



On Wed, 31 May 2000, alain Bedu wrote:
> >%_A question concerning reference and real data stored.
> 
> Suppose I have the following objects :
> 
> class A ....
> {
>     B myB;
>     .......
>     public void setB(B b); /*update*/
> }
> 
> class B ....
> {
>     A myA;
>     .......
>     public void setA(A a); /*update*/
> }
> 
> In my program, I've got the following code 
> 
> A objectA;
> B objectB;
> 
> objectA.setB(objectB);
> objectB.setA(objectA);
> 
> /*insertion of these objects in my database....*/
> 
> Here is my question : do I have two copies of objectA and two copies of objectB in my database, 
> or are the attributes only reference to the existing objects ?
> I want to make multiple reference, but not multiple insertion !

There is only one object of class A and B in the database. The objects only
hold references.

I complete your code to make things clear:

	A objectA = (A)db.createObject (...);
	B objectB = (B)db.createObject (...);

	objectA.setB(objectB);
	objectB.setA(objectA);

The only way to create a database object are the createObject and copyObject
methods. Both return a proxy (a persistent reference) of the newly crated
object. The client code only deals with these proxies. The client may copy
or clone these proxies but they still referencing one database object.


Falko
-- 
______________________________________________________________________
Falko Braeutigam                         mailto:falko@softwarebuero.de
softwarebuero m&b (SMB)                    http://www.softwarebuero.de