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

Re: Object Creation in ozone



Hi Falko,

Substituting 'database()' for 'Repository.getDB()' in the constructor of 
ObjectOneImpl in the example below results in a runtime exception of 'Object 
is not (yet) associated with a database container. In the example below how 
would one initiate creation of ObjectTwo from within the constructor of 
ObjectOne?

This is not an academic question, there are significant reasons for using 
this construct in my app.

thanks,

don


>From: Falko Braeutigam <falko@smb-tec.com>
>To: "Don Berendsen" <donberendsen@hotmail.com>, ozone-users@ozone-db.org
>Subject: Re: Object Creation in ozone
>Date: Fri, 11 Aug 2000 14:15:43 +0200
>
>On Fri, 11 Aug 2000, Don Berendsen wrote:
> > Hi Falko,
> >
> > Thanks very much for your prompt reply. Your support is very much
> > appreciated.
> >
> > The sample code is below. I don't fully understand the implications of 
>your
> > statement 'Setting a static member of Repository that holds the client's
> > database object will not work because...'.
>
>Your Local class represents/starts/is the client application. In the main()
>method of Local the static member db of the Repository class is 
>initialized. In
>the next lines of the main method this static db member is used to access 
>the
>database. This is okay so far. But, when calling createObject() the
>corresponding object is created inside the server. While creating this 
>object
>its ctor is called. Again, this happens inside the server! The static db 
>member
>of Repository isn't initialized here because it's a different class inside 
>a
>different VM.
>
>In your particular case you are using a LocalDatabase to access the 
>database.
>This means that both, client and server, running inside the same VM. 
>Therefore
>the static db member of Repository in fact is initialized but this member 
>cannot
>be used inside database object however.
>
> >
> > Once a database is opened what are the proper ways to get or pass a
> > reference to it for objects from the client and server sides?
>No way! Never pass database objects to/from the server. You don't need to.
>
>Each database object is derived from OzoneCompatible wich provides the
>database() method. This method returns the proper database object for the
>database object.
>
>
> >
> > Thanks again,
> >
> > don
> >
> > -----------------------------------
> >
> > import java.util.*;
> > import org.ozoneDB.*;
> >
> >
> > public class Repository extends Object {
> >
> >     public static void open ()throws Exception {
> >
> >         db = new LocalDatabase();
> >         try {
> >             db.open ("/tmp/db");
> >             }
> >         catch (Exception e) {
> >             System.out.println ("No DB found, creating...");
> >             db.create ("/tmp/db");
> >             db.open ("/tmp/db");
> >             }
> >
> >         db.reloadClasses();
> >         System.out.println ("connected...");
> >
> >       }
> >
> > 	public static void close() throws Exception {
> > 	  db.close();
> > 	  System.out.println ("deconnected...");
> > 	}
> >
> > 	public static LocalDatabase getDB() {return db;}
> >
> > 	private static LocalDatabase db;
> >
> >     }
> >
> > ------------------------
> >
> >
> > import java.util.*;
> > import org.ozoneDB.*;
> >
> >
> > public class Local extends Object {
> >
> >     public static void main (String [] args)throws Exception {
> >
> >      Repository.open();
> >
> >      LocalDatabase db = Repository.getDB();
> >
> >      System.out.println(db.createObject (ObjectOneImpl.class.getName(), 
>0,
> > null));
> >
> >      Repository.close();
> >
> >   }
> > }
> >
> > ----------------------------
> >
> > import org.ozoneDB.*;
> > import java.util.*;
> >
> >
> > public class ObjectOneImpl extends OzoneObject implements ObjectOne {
> >
> >    public ObjectOneImpl(){
> >      System.out.println("creating ObjectOne");
> >      try {
> >         Repository.getDB().createObject 
>(ObjectTwoImpl.class.getName(),0,
> > null);
> >      } catch (Exception e) {
> >         System.out.println(e);
> >      }
> >    }
> >
> >    public void setName (String aName){name = aName ;}
> >    public String getName(){return name;}
> >    private String name;
> >
> >
> > }
> >
> > -----------------
> >
> > import org.ozoneDB.*;
> > import java.util.*;
> >
> >
> > public interface ObjectOne extends OzoneRemote  {
> >
> >    public void setName (String name) ; /*update*/
> >
> >    public String getName();
> > }
> >
> > --------------------
> >
> > import org.ozoneDB.*;
> > import java.util.*;
> >
> >
> > public interface ObjectTwo extends OzoneRemote  {
> >
> >    public void setName (String name) ; /*update*/
> >
> >    public String getName();
> > }
> >
> > ---------------------
> >
> > import org.ozoneDB.*;
> > import java.util.*;
> >
> >
> > public class ObjectTwoImpl extends OzoneObject implements ObjectTwo {
> >
> >    public ObjectTwoImpl () {System.out.println("Creating ObjectTwo");}
> >
> >    public void setName (String aName){name = aName;}
> >    public String getName(){return name;} ;
> >    private String name;
> >
> >
> > }
> >
> > ----------------------------
> >
> >
> > >From: Falko Braeutigam <falko@smb-tec.com>
> > >To: "Don Berendsen" <donberendsen@hotmail.com>, 
>ozone-users@ozone-db.org
> > >Subject: Re: Object Creation in ozone
> > >Date: Fri, 11 Aug 2000 12:22:52 +0200
> > >
> > >On Fri, 11 Aug 2000, Don Berendsen wrote:
> > > > In my application objects often initialize their state by creating 
>other
> > > > objects in their constructor.
> > > >
> > > > However when creating an OzoneObject ObjectOne whose constructor 
>(see
> > > > example below) initiates the creation an OzoneObject ObjectTwo, 
>calling
> > > > createObject(ObjectOneImpl....) returns an ObjectTwoImpl_Proxy 
>instead
> > >of an
> > > > ObjectOneImpl_Proxy.
> > > >
> > > > Is there a way to get the correct createObject() return value while
> > >doing
> > > > nested object creation such as this?
> > > >
> > > > cheers,
> > > >
> > > > don
> > > >
> > > >
> > > > example ObjectOne constructor:
> > > >
> > > > public ObjectOneImpl(){
> > > >       try {
> > > >         obj2 = (ObjectTwo) Repository.getDatabase().createObject
> > > > (ObjectTwoImpl.class.getName(),0, null);
> > > >       } catch (Exception e) {
> > > >         System.out.println(e);
> > > >       }
> > > >     }
> > >
> > >Hmmm... where does the static getDatabase() of Repository get the 
>database
> > >object from? The implementation of such a method has to check if the 
>class
> > >lives in the server or the client. (there is no documented way to do 
>so)
> > >Setting a static member of Repository that holds the client's database
> > >object
> > >will not work because the ctor of the database object is called on the
> > >server
> > >side. Don, can you send the code of Repository.getDatabase()?
> > >
> > >
> > >Falko
> > >--
> > >______________________________________________________________________
> > >Falko Braeutigam                              mailto:falko@smb-tec.com
> > >SMB GmbH                                        http://www.smb-tec.com
> > >
> >
> > ________________________________________________________________________
> > Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
>--
>______________________________________________________________________
>Falko Braeutigam                              mailto:falko@smb-tec.com
>SMB GmbH                                        http://www.smb-tec.com
>

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com