The steps to define multiple DAOs in a Manager class are relatively
simple. Note though, that you'll have to roll your own a Manager class
and not extend GenericManagerImpl (since this only excepts one DAO as
a constructor argumernt).

You can create one Manager with multiple DAOs. You don't have to have
one manager for each DAO. In some cases, this may be better style. I
tend to create a Manager for each "aggregate root" of a model. **

I have done the same think -
  - create a Manager Implementation with either multiple constructor
arguments, or setters for each DAO (I tend to prefer the latter when
they're multiple, but I won't get into which is the better style).
Create an instance variable for each instance variable.

class GameManagerImpl implements GameManager
{
   private GameDao gameDao;
   private MoveDao moveDao;

   public void setGameDao(GameDao dao) { this.gameDao = dao; }
   public void setMoveDao(MoveDao dao { this.moveDao = dao; }
}

Wire it up in your applicationContext.xml file:

  * define your gameDao and moveDao.
  * define gameManager:
    <bean id="gameManager"
class="com.mycompany.app.manager.impl.GameManagerImpl">
        <property name="gameDao" ref="gameDao"/>
        <property name="moveDao" ref="moveDao"/>
    </bean>

In your tests, your ManagerImpl should be using mocks, so you
shouldn't have to worry about wiring up anything, just make sure you
create  Mock class for each of the relevant Daos:

public class GameManagerImplTest extends BaseManagerMockTestCase {
    private GameManagerImpl gameManager = new GameManagerImpl();
    private Mock gameDao = null;
    private Mock moveDao = null;

    @Override
    protected void setUp() throws Exception
    {
        super.setUp();
        gameDao = new Mock(GameDao.class);
        gameManager.setGameDao((GameDao) dao.proxy());
        moveDao = new Mock(moveDao.class);
        gameManager.setMoveDao((MoveDao) dao.proxy());
    }

   ... your tests ...
}


Hope that helps and answers some questions!

Alex

[1] Also see this article -
http://debasishg.blogspot.com/2007/02/domain-driven-design-use-orm-backed.html
- for an alternative to using DAOs altogether, and instead using a
Repository pattern. Worth taking a look, but not necessarily trivial.

On Dec 16, 2007 4:59 PM, Struts2 Fan <[EMAIL PROTECTED]> wrote:
>
> Hi all again,
>
> I want to reask the question in a different way. What I want to do is to
> define another dao in the manager class. What are the steps to define it in
> the manager and test classes?
>
> Thanks fo replies.
> --
> View this message in context: 
> http://www.nabble.com/-Appfuse2.0--Best-Practise-Design-Pattern-for-Multiple-Dao-Access-from-managers-tp14116309s2369p14362898.html
>
>
>
> Sent from the AppFuse - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



-- 

Alex Coles
FR: +33 (0) 6.42.43.15.96 - mobile
       +33 (0) 1.42.55.36.54
US: +1 917.573.0135  (US)
www.alexcolesportfolio.com

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

Reply via email to