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

Re: Accessing Ozone Objects



On Tue, 16 May 2000, Kenny Go wrote:
> Hi!
> 
> Thanks for your mail. I do agree with you about writing
> database and non-database objects in Java and access
> them in Java. This is why I need ozone to store
> Java objects so that I can use Java to access them.
> 
> Now, for example, I have a Person Java class that contains
> attributes/methods that store name, age, etc. I can use
> createObject method to create each Person object using
> their name as the root object. I can use the same method
> to store all people in my list like James, Tommy, Falko,
> etc. Next step (where the question I asked), I need to
> extract this people out so that I can show/load them
> in a grid/treeview. So, how do I do it when ozone
> didnt provide me a method to access these objects?

Don't give all the Person objects a name. Your list or whatever collection you
use provides methods to access your objects. And this list is probably a member
of another object. This object, say of class PersonManager, is a good candidate
for a root (named) object. Something like:

class PersonImpl extends OzoneObject {
	String name;
	int id;

	...
}

class PersonManagerImpl extends OzoneObject {
	Hashtable nameTable;
	Hashtable idTabel;

	public Person addPerson (Person person) {
		nameTable.put (person.name(), person);
		idTable.put (person.id(), person);
	}

	public Person personForName (String name) {
		return nameTable.get (name);
	}
	
	public Person personForID (int id) {
		return idTable.get (id);
	}

	// other access methods if needed


If there are many Persons and you have to show them all at once in your
treeview then it's a good idea to have methods that reflect the special needs
of your app. In other words: instead of iterating over all Person of the
PersonManager in the client code you should consider something like:

	public String[] stringList () {
		String[] list = new String [nameTable.length()];
		for (Enumeration e ...) {
			list[i] = (Person)e.object();
		}
	}

This will speed things up and gives 'natural' transaction security, because an
other transaction may change the PersonManager while your transaction is
iterating but you probably want to display an consistent stage of the
PersonManager.


Falko
-- 
______________________________________________________________________
Falko Braeutigam                         mailto:falko@softwarebuero.de
softwarebuero m&b (SMB)                    http://www.softwarebuero.de