Hi Sylvain,

In the tutorial1 I followed a very simply scheme.
The application is considered to be single threaded. Thus there is only one broker instance created for the whole application.


This single instance is passed to the use case objects that are reponsible for implementing the business logic.
This is done in the registration of use cases phase. SHoudn't be too difficult to find in the code.


Of course you will follow different approaches in multi threaded code.
Say you have a method myThreadSafeCode() than be executed by multiple threads (e.g. within a Servlet or SessionBean component).
You would handle the broker as follows:


public void myThreadSafeCode()
{
    // obtain broker instance from pool
    PersistenceBroker broker =
                    PersistenceBrokerFactory.defaultPersistenceBroker();

// do some persistance work with the broker here

    // close broker and return it to the pool
    broker.close();

// do not work with a broker instance after closing!

}

It obviously depends on your application if it is appropriate to store a broker instance in a variable and pass it to other components.

I hope the single- and multithread example given above makes things clearer for you.

cheers,
Thomas


[EMAIL PROTECTED] wrote:
(repost)
Hello,

In the PB tutorial (tutorial1) the author explains how to obtain a Broker instance:

You put the code below in the constructor of your class.

----code----
public MyClass()
{
    PersistenceBroker broker = null;
    try
    {
        broker = PersistenceBrokerFactory.
                    defaultPersistenceBroker();
    }
    catch (Throwable t)
    {
        t.printStackTrace();
    }
}
----code----

I don't understand how the PB instance is passed to the constructor of other classes in this example.

My situation is: a class (the controller) creates an instance of a JavaBean. I want to create the PB instance in this JavaBean. How to store the PB instance?


Someone could give me advices about that?


Thanks
Sylvain

---------------------------------------------------------------------
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]





--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to