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

Re: Object creation questions



Thanks for fast response.
These points would be good for documentation.
I'll reappear once I have this whipped into shape. (Not tonight!)
C

Falko Braeutigam wrote:

> On Tue, 04 Jul 2000, Charles Benett wrote:
> > Falko, Lars, or someone,
> >
> > Can you explain about object creation with ozone in more detail? I'm
> > spending ages going round in circles.
> >
> > Particular questions are:
> > 1) Do all persistent classes need a constructor with no parameter and no
> > body?
> No. The compiler generates an default ctor if needed.
>
> > 1b) If so, why doesn't the default constructor work?
> see 1)
>
> > 2) Do all persistent objects need to be created by calling the
> > no-parameter, no-body constructor? or can you call another constructor?
> There is a createObject method that calls other then the default ctors. But it
> needs some more work because it needs the signature of the ctor as string.
> Maybe someone can help and write some lines of code to generate the signature
> out of the parameter objects.
>
> > If you call another constructor does it have to call the ( ) {} one?
>
> > 3) What is the difference between creating objects from outside the db
> > server and creating them within the db server?
> There is no difference.
>
> ...except that creating a database object from another database object is much
> faster than from the client. And, if you are creating more than one objects at
> the same time, doing this inside a database method encloses all the create
> operations inside a transaction which is most likely wanted.
>
> > 3b) I seem to be able to create db objects within other db objects with
> > calls to new, rather than to .createObject() but their behaviour seems
> > erratic (see below). Is this supposed to work or is it inadvisable?
> Calling new does not create a database object. However, not all persistent
> classes have to be database classes. A Car class may have a string member:
> name. This name object is persistent and will be stored in the database but it
> is not a database object because no other than the Car object can access it.
>
> > 4) Am I right in thinking that if you create an object with
> > database().createObject(myObject), the constructor of myObject can't
> > create other objects - I get an "object is not yet associated to a
> > database container" exception.
> Yes. Therefore, although it doesn't look that nice, an initialization method is
> always a good idea.
>
> > 5) Can you explain about named objects, e.g. do names have to be unique
> > within DB or only unique within a class of objects?
> Names are unique within a database. Named objects are the entry points to your
> data that allows you to access the stored data from a newly started client.
>
> > Sorry for so many questions!
> no problem.
>
> > Thanks,
> > Charles
> >
> > Here's an outline of what I want to do:
> >
> > Client: rootThingy = db.createObject(root_object_name);
> > Client: rootThingy.addSomething_update(param);
> >
> > rootThingy.addSomething_update(param) {
> > Something anObj = new Something(param);
> > }
> >
> > where Something is an object I want to be persistent, with a constructor
> > like:
> >
> > Something ( ) {
> > myField = param;
> > }
> >
> > Now, this seems to create the objects OK (from debug messages). Also, if
> > I want to read myField later, I can navigate from root_object_name and
> > get it OK.
> > However, if I want to call a method of Something, it doesn't work.
> >
> > PS An example with more than two layers of db objects (ie more than
> > garage and car), where objects at all layers are manipulated would be
> > handy.
> The DOM (XML) code is recursive. So you can have as many layers as you want.
> But this doesn't change anything. Things are exactly the same between object of
> level 4 and 5 and objects of level 1 and 2. In fact, there is no such thing
> like the object level. Objects are database object or they are not. That's it.
>
> Falko
> --
> ______________________________________________________________________
> Falko Braeutigam                         mailto:falko@softwarebuero.de
> softwarebuero m&b (SMB)                    http://www.softwarebuero.de