Hi again,

a quick solution could be that with some value in the
Mandragora.propertiesthe user chooses to use always the new
persistence broker, or to use always
the userBroker, and in the last case he is responsible of closing it. In the
same way the user could choose if the job of each method always be in an
atomic transaction or always not , and in the last case the user is
responsible of the commit or rollback.

About the singleton, I have chosen this, because I suppose in the future the
DAO could have hundreds of methods, so allowing just one instance save
memory, but the drawbacks you told could be a serious problem.
But a user can write an implementation of the DAO see

http://mandragora.sourceforge.net/referenceguide/how-to-extend.html#Write%20your%20DAO%20implementation


that just extend OjbPbDAO, without overwriting any methods and not being
singleton, as OjbPbDAO can be extended even being singleton, and configuring
Mandragora.properties to use it.

Anyway all that doesn't look very good.

I think the best could be the following.

to move all management of the broker from the ServiceLocator to the
OjbPbDAO, writing a protected method getBroker that do the same job of
ServiceLocator.findBroker().

I can introduce some method getBroker(some input parameter) for example to
specify the database to use or to lookup some pre-instanced PB by the user
(for example with an hashMap)

    modify all update/insert/delete methods so that they call the following
5 methods:
               broker=getBroker();
               manageBeginTransaction(broker);
               doTheSpecificMethodJob(broker);
               manageCommitTransaction(broker);
               manageCloseBroker(broker);

the method manageBeginTransaction(broker) do a broker.beginTransaction()
depending by some parameter in the Mandragora.proeprties,
doTheSpecificMethodJob(broker); do the same job between
broker.beginTransaction()   and
broker.commitTransaction() , manageCommitTransaction(broker);
manageCloseBroker(broker); do the commit and close the broker depending by
some parameter in the Mandragora.properties.

In this way a user can extend the OjbPbDAO and add a method that do
something like that:

 get the broker he wants,
 begin transaction (if he wants),
 doTheSpecificMethod_1_Job(broker);
 doTheSpecificMethod_2_Job(broker);

 doTheSpecificMethod_N_Job(broker);

 do other jobs

 commit (if he wants)
 closeBroker(if he wants).


So the extended DAO will can be kept singleton, as the user can use the PB
he wants and manage it as he wants.

I could write too the same insert/update/delete methods so that can be
passed the PB as parameter.

Well...
I know all these is a bit (or a lot) confused, but these problems have to be
solved, and these are the first very dirty ideas.

I will focus on this matter when I will have completed documentation of what
already exist a bit more.

Then the next job I will do will be about allowing a more flexible
management of the PB and transactions boundaries.

I hope to get help in cleaning up these ideas and following this (at least
for me ) interesting discussion.

Anyway it already exists an implementation of BD (
it.aco.mandragora.bd.ejbStateless.EjbStatelessManagerBD)
that put encapsulates DAO methods inside a transaction that is managed by
J2ee container.

Regards
Alessandro

















On 9/28/07, Armin Waibel <[EMAIL PROTECTED]> wrote:
>
> Alessandro Colantoni wrote:
> >
> > I think you are using the cache ObjectCachePerBrokerImpl.
> >
>
> Or the recommended two-level cache which has a session cache too.
>
>
> > In the method findbroker to put a condition that if the entry of
> > Mandragora.properties broker.useUserBroker is true, return the
> userbroker in
> > place of create a new broker.
> >
> > And in all methods of OjbPbDAO , when they close the broker, put a
> > condition  that if broker.useUserBroker = true don't close, else close.
> >
> > So it is user responsibility to create and close the broker.
> >
> > With all of this your code should work. Of course remember to close the
> > broker.
> >
> > Someone else (Armin? )agree with this?
> > I hope have been clear enough.
>
> If OjbPbDAO can differ between user-PB and new-PB this should work, else
> a user got problems when using both strategies - e.g. most times
> inject a user-PB, but from time to time using the ServiceLocator without
> injection of a user-PB (e.g. with default settings, based on the current
> PBKey, to perform a simple query).
>
> In general, I think implementing ServiceLocator and DAO as singletons
> cause some drawbacks, because singletons make it impossible to use
> different PBKey (e.g. different databases) in the same
> web-project/application or in a multi-threaded environment.
> If ServiceLocator isn't a singleton it can have a state (e.g. the user
> can specify a PBKey to force creation of specific PB instances).
>
> regards,
> Armin
>
>
> >
> > Anyway Hans, download the source, and have a look, so you can help. look
> at
> > the OjbDAO methods.
> > They just use Ojb so it is very easy and we can solve this together.
> >
> > if you and Armin agree I start as soon as possible, even if I'm going on
> > travel tomorrow until October the 3th
> >
> >
> > Thanks
> > and regards
> >
> > Alessandro
> >
> >
> >
> >
> >
> >
> >
> > On 9/26/07, Hans Novak <[EMAIL PROTECTED]> wrote:
> >> Hi Allesandro,
> >>
> >> i think im stupid - or - how we in germany say: i dont see the wood for
>
> >> the trees ... ;-)
> >> im my (ojb) dao class i use
> >>
> >>
> >> public class PartnerFactoryCore {
> >>    private PersistenceBroker broker = null;
> >>    static Logger logger = Logger.getLogger("osf");
> >>
> >>    public PartnerFactoryCore() {
> >>        try {
> >>            broker =
> >> PersistenceBrokerFactory.defaultPersistenceBroker();
> >>        } catch (Exception e) {
> >>            e.printStackTrace();
> >>            MsgBoxHn.msgBoxOK(e.getMessage().toString() +
> >> "\n\n\nProgrammende.");
> >>            System.exit(0);
> >>        }
> >>    }
> >>
> >>    ....
> >> }
> >>
> >>
> >> I use mandragora for example to store an object like this:
> >>
> >>
> >>
> >>    private void saveData(){
> >>        formPartner = getPartnerFromForm();
> >>        LOGGER.debug("Data Saving...");
> >>
> >>        //old way!!! - do not delete objects in the collection tree
> >>        //partnerFactoryCore.store(formPartner);  //from
> >>
> >>        // new Way with mandragora
> >>        try {
> >>            BD bd =
> >> ServiceLocator.getInstance
> >> ().getManagerBD("BDFactoryDefaultClass","StandardBDDefaultClass");
> >>            bd.updateCollectionReferences(formPartner);
> >>        } catch (Exception e) {
> >>             e.printStackTrace();
> >>        }
> >>
> >>        LOGGER.debug(formPartner.toString (0));
> >>    }
> >>
> >>
> >>
> >> how can i put this 2 things together ?
> >>
> >>
> >> Hans
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> For additional commands, e-mail: [EMAIL PROTECTED]
> >>
> >>
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to