[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Object Creation in ozone
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...'.
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?
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