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

Re: HOW TO: storing inherited objects



Hello,

On Wed, 19 Jan 2000, Lars Bergmann wrote:
> Hello,
> 
> I need to store objects that inherit from classes other than OzoneObject.
> 
> Is there a tutorial on how to implement OzoneCompatible instead of
> inheriting from OzoneObject?

I had the same problem, but i have found out a way...
I have a super class IObject:

public class IObject extends org.ozoneDB.OzoneObject 
				implements IObjectInterface
{
  protected String Information;

  public IObject(){}

  public String getAuthorInformation() {return Information}
  public void setAuthorInformation(String inf){Information = inf;}
}

The interface for this super class and the proxy class too:

public interface IObjectInterface extends OzoneRemote
{
  public String getAuthorInformation();  /*update*/
  public void setAuthorInformation(String inf); /*update*/
}

public class IObject_Proxy 
       extends OzoneProxy
       implements IObjectInterface 
{/* the generated code */}

Then i have wrote a class for my data without any methods for the
database:

public class Chemical extends IObject
{
  protected int ID;
  protected String Name;

  public Chemical(){this(0,"");}

  public Chemical(int _id, String _bez)
  {
      ID = _id;
      Name = _bez;
  }

  public int getID() {return ID;}
  public String getName() {return Name;}
  
  public void setID(int _id) {ID = _id;}
  public void setName(String _name) {Name = _name;}
}

And the interface for this class:

public interface ChemicalInterface extends
de.uni_leipzig.imise.misc.IObjectInterface
{
  public int getID();/*update*/
  public String getName();     /*update*/

  public void setID(int _id);  /*update*/
  public void setName(String _name);  /*update*/
}

Then i have wrote another class to merge the class for the data and the
interface 
for the database:

public class ChemicalImpl extends Chemical implements ChemicalInterface
{
    public ChemicalImpl(){}
}

In the last i've made the proxy class with the opp and the class
ChemicalImpl:
public class ChemicalImpl_Proxy 
       extends OzoneProxy
       implements ChemicalInterface
{/* the generated code */}

Now i can create the persistent objects with 
db.createObject(ChemicalImpl.class.getName(),0, "my_chemical")
and set the members with the member methods.

This way is not really easy, but it works. ;)

Bye,
Michael Krueger