[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Curious Problem, Any Suggestions
On Thu, 11 May 2000, Brian Weaver wrote:
> Hi All,
>
> I wrote some code to use the ozone database for testing, and potentially
> long term use. When I ran the code I got an interesting error:
> "java.lang.RuntimeException: Object is not (yet) associated to a database
> container"
>
> Needless to say, I was a bit puzzled.... Although I probably would have
> wasted less time if I had paid attention the to the error the first time. I
> ended up getting the same error regardless of which database class I used:
> LocalDatabase or RemoteDatabase.
>
> I think I know what the problem is, but how do I fix it.
>
> Let me give everyone a little background so we'll all be on the same page.
> I have developed four interfaces and the respective classes:
>
> Interface Implementation class
> ------------------- ---------------------
> SnmpConfigData SnmpConfigDataImpl
> IPSpecificSnmpData IPSpecificSnmpDataImpl
> IPRangeSnmpData IPRangeSnmpDataImpl
> SnmpConfDB SnmpConfDBImpl
>
> The IP* interfaces and classes inheriet from SnmpConfigData &
> SnmpConfigDataImpl respectively. The trick I'm trying to accomplish is that
> the SnmpConfDBImpl is an object class that hold a single SnmpConfigData
> reference, and a two vectors, one each that contains a list of
> IPRangeSnmpData and IPSpecificSnmpData. The SnmpConfDB interface defines
> methods for looking up SnmpConfigData based on specific IP addresses.
>
> To this end, when the SnmpConfDBImpl is being created with the constructor
> in the server it attempts to create the SnmpConfigData object from within
> the server (using this.database().createObject(...)). However, when the
> SnmpConfDBImpl constructor executes it causes the above runtime exception.
> The apparent solution would be to create the single SnmpConfigData first and
> pass that into the constructor. What I would like to know is if it is only
> possible to create database object from within a database object before it's
> finished being constructed, or is that just a limitation of ozone?
Yes, this is a limitation of ozone. Calling the database() method inside
the constructor throws this exception because the object doesn't know it's
container at this point (container() returns null) because the object itself
is just constructed. It's tricky to let the container call the setContainer()
method of the target object before the code of the custom ctor is executed. One
(maybe the only) way is to let the base class ctor (OzoneObject) find out
its corresponding link via thread->transaction->formerly-set-variable - not
very clean. Other ideas?
Brian, the quick and dirty solution for you is to initialize your objects in a
init() method instead the ctor.
Falko
--
______________________________________________________________________
Falko Braeutigam mailto:falko@softwarebuero.de
softwarebuero m&b (SMB) http://www.softwarebuero.de