On Sat, Aug 6, 2011 at 8:30 PM, Eranda Sooriyabandara <0704...@gmail.com> wrote: > Hi Jean-Sebastian, > I was bit confused on how am I going to maintain the relationship between > Session, Database and Group. With all these methods I am kind of lost in the > middle in choosing one. If you can call one for me I can work on it. > First I was thought of keep some status for the component but later I > realized that constructor injection will be more applicable since I have > constructors with Complex datatypes. What do you think? > In the middle of implementing I got the following problems, > Can we parse a complex datatype as a constructor parameter. > When we going to initialize the class (call the constructor). > Can we access the Objects of Session, Database and Group in the client and > access its method. >
If the usage pattern you're thinking about is: s = new SessionFactory().getSession(); d = s.getDatabase("db"); g = d.getGroup("group"); e = g.getEntry("key"); Then you're going to have to maintain some state (group + database + session), which won't work well in a distributed environment, as (1) you can't assume that the client program will behave and release that state, and (2) one million clients could create one million sessions which would overload and take your system down :). Instead I'd suggest the following approaches: a) One component representing the collection of entries. Use the following service interface (c is your datastore component) e = c.getEntry("db", "group", "key") and obtain the database, group and session, and release them, in the getEntry method. or b) Three components representing the collection of entries, group and database (or perhaps one more with a component providing sessions). Use the following service interface (c is your datastore component) e = c.getEntry("key") then wire c to a component g, providing a getGroup() operation returning group "group", "group" being configured as a property of g; and wire g to a component d providing a getDatabase() operation returning database "db", "db" being configured as a property of d. Does that help? -- Jean-Sebastien