Joey Samonte | 1 Feb 05:32
Picon
Favicon
Gravatar

A RepositoryManager?

Good day to all!
From my current understanding of repository, you usually would have one repository for each entity you have in your domain model. But how do you manage database connection, transaction between all your repositories? Do you need to create a RepositoryManager to handle connections, transactions, and all your repositories? Any code samples?
 
Thank you very much.

Looking for last minute shopping deals? Find them fast with Yahoo! Search. __._,_.___

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___
Sam | 1 Feb 06:28
Picon

Re: A RepositoryManager

My opinion is that Repositories should support transaction but not
initialize transactions. Transaction should be initialized and
controlled from the upper/facade level.

For example:

public class CustomerRepository
{
    IDatabase database; //can be passed in from constructor

    public Customer Find(int customerID) {
        DataSet customerData =
database.ExecuteProcedure("FindCustomer", customerID);
        return BuildCustomerFormDataSet(customerData);
    }

    public void Update(Customer customer) {
        database.ExecuteProcedure("UpdateCustomer",
customer.ID,customer.Name, customer.etc...);

    }
     //....
}

At facade (service level, method is called from client apps):

public void UpdateCustomerAddress(int customerID, Address address)
{
    CustomerRepository repository = new
CustomerRepository(MySQLDatabase); 

    Customer customer = repository.Find(customerID);
    customer.Address = address;

    using (TransactionScope transactionScope = new TransactionScope())
    {
         repository.Update(customer);

         transactionScope.SetComplete(); //commit, otherwise roll back
which is handled by "using"
    }
} 

--- In domaindrivendesign <at> yahoogroups.com, Joey Samonte <dyowee23@...>
wrote:
>
> Good day to all!
>   From my current understanding of repository, you usually would
have one repository for each entity you have in your domain model. But
how do you manage database connection, transaction between all your
repositories? Do you need to create a RepositoryManager to handle
connections, transactions, and all your repositories? Any code samples?
>    
>   Thank you very much.
> 
>        
> ---------------------------------
> Looking for last minute shopping deals?  Find them fast with Yahoo!
Search.
>

 
Chris Beams | 1 Feb 06:48
Picon
Gravatar

Re: A RepositoryManager?

Joey,

Ideally you'll want to use declarative transaction management.  Take a look at Spring's support:


- Chris Beams



On Jan 31, 2008, at 10:32 PM, Joey Samonte wrote:


Good day to all!
From my current understanding of repository, you usually would have one repository for each entity you have in your domain model. But how do you manage database connection, transaction between all your repositories? Do you need to create a RepositoryManager to handle connections, transactions, and all your repositories? Any code samples?
 
Thank you very much.

Looking for last minute shopping deals? Find them fast with Yahoo! Search.


__._,_.___


Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___
Luis Abreu | 1 Feb 11:16
Picon
Gravatar

Re: Re: A RepositoryManager

Hello.

I agree with Sam and that is what I've been doing in my applications. Now, if I could only get some free time to add castle to it...

On 2/1/08, Sam <sam.s.peng <at> gmail.com> wrote:

My opinion is that Repositories should support transaction but not
initialize transactions. Transaction should be initialized and
controlled from the upper/facade level.

For example:

public class CustomerRepository
{
IDatabase database; //can be passed in from constructor

public Customer Find(int customerID) {
DataSet customerData =
database.ExecuteProcedure("FindCustomer", customerID);
return BuildCustomerFormDataSet(customerData);
}

public void Update(Customer customer) {
database.ExecuteProcedure("UpdateCustomer",
customer.ID,customer.Name, customer.etc...);

}
//....
}

At facade (service level, method is called from client apps):

public void UpdateCustomerAddress(int customerID, Address address)
{
CustomerRepository repository = new
CustomerRepository(MySQLDatabase);

Customer customer = repository.Find(customerID);
customer.Address = address;

using (TransactionScope transactionScope = new TransactionScope())
{
repository.Update(customer);

transactionScope.SetComplete(); //commit, otherwise roll back
which is handled by "using"
}
}

--- In domaindrivendesign <at> yahoogroups.com, Joey Samonte <dyowee23 <at> ...>
wrote:
>
> Good day to all!
> From my current understanding of repository, you usually would
have one repository for each entity you have in your domain model. But
how do you manage database connection, transaction between all your
repositories? Do you need to create a RepositoryManager to handle
connections, transactions, and all your repositories? Any code samples?
>
> Thank you very much.
>
>
> ---------------------------------
> Looking for last minute shopping deals? Find them fast with Yahoo!
Search.
>




--
Regards,
Luis Abreu
email: labreu_at_gmail.com
PT Blog: http://weblogs.pontonetpt.com/luisabreu
EN Blog:http://msmvps.com/blogs/luisabreu/default.aspx
http://www.pontonetpt.com
MVP profile: http://mvp.support.microsoft.com/profile/luis.abreu __._,_.___

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___
Ben Scheirman | 1 Feb 13:20
Picon
Gravatar

Re: A RepositoryManager?

I use the Unit Of Work pattern generally to control my transaction boundaries.

using(UnitOfWork.Start)
{
     _customerRepository.Save(customer);
     _accountRepository.Save(account);
     UnitOfWork.Complete();
}

depending on the environment, this is a thread-scoped class that controls the transaction boundary for me.

If you're using NHibernate, check out RhinoCommons:
http://www.ayende.com/Blog/archive/2007/06/08/Rhino-Commons-RepositoryltTgt-and-Unit-Of-Work.aspx


On Jan 31, 2008 11:48 PM, Chris Beams <cbeams <at> gmail.com> wrote:

Joey,


Ideally you'll want to use declarative transaction management.  Take a look at Spring's support:


- Chris Beams



On Jan 31, 2008, at 10:32 PM, Joey Samonte wrote:


Good day to all!
From my current understanding of repository, you usually would have one repository for each entity you have in your domain model. But how do you manage database connection, transaction between all your repositories? Do you need to create a RepositoryManager to handle connections, transactions, and all your repositories? Any code samples?
 
Thank you very much.

Looking for last minute shopping deals? Find them fast with Yahoo! Search.



__._,_.___

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___
Picon

Re: A RepositoryManager?

Just to remember,

Repositories are like collections of objects and not DAOs. Sometimes some repository implementation has some iteraction with database, but I preffer write a separated DAO and use that through a repository implementation.

Like collections, doesn't make sense put lot of business rules inside a repository. All that you repository have to do is to manage the instances of domains. The business rules MUST be in the domain objects, so, the most part of transactions should be controled in domain objects (if really really necessary).

DDD is about simplicity.

Best,


Felipe Rodrigues
Fratech


Ben Scheirman escreveu:

I use the Unit Of Work pattern generally to control my transaction boundaries.

using(UnitOfWork.Start)
{
     _customerRepository.Save(customer);
     _accountRepository.Save(account);
     UnitOfWork.Complete();
}

depending on the environment, this is a thread-scoped class that controls the transaction boundary for me.

If you're using NHibernate, check out RhinoCommons:
http://www.ayende.com/Blog/archive/2007/06/08/Rhino-Commons-RepositoryltTgt-and-Unit-Of-Work.aspx


On Jan 31, 2008 11:48 PM, Chris Beams <cbeams <at> gmail.com> wrote:

Joey,


Ideally you'll want to use declarative transaction management.  Take a look at Spring's support:


- Chris Beams



On Jan 31, 2008, at 10:32 PM, Joey Samonte wrote:


Good day to all!
From my current understanding of repository, you usually would have one repository for each entity you have in your domain model. But how do you manage database connection, transaction between all your repositories? Do you need to create a RepositoryManager to handle connections, transactions, and all your repositories? Any code samples?
 
Thank you very much.

Looking for last minute shopping deals? Find them fast with Yahoo! Search.





--
Felipe Rodrigues de Almeida
Fratech - Tecnologia da informação

+55 19 3119-6880 / +55 19 8125-4977
Rua Pedro Álvarez Cabral, 227 - Sta. Cruz
Sta. Bárbara D'Oeste - SP
__._,_.___

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___
rwallace1979 | 2 Feb 22:23
Gravatar

Re:Changing identifiers

I understand what you mean by having the update() method in the
repository check for uniqueness.  That's kind of what I was hoping for.

I'm less clear on what you mean by distinguishing between change the
values in the domain object versus saving the object into the repository.

I mean, in theory I understand what you mean.  I'm just not sure
exactly how to implement it in my scenario.  Right now, I'm at the
very beginnings of the project and haven't implemented any kind of
persistent backend, so I've just been creating repositories that store
objects in-memory - some collection, like a set or map, depending on
the situation.

So I think part of my problem is that updating a domain object causes
the object in the repository to be changed directly.  And the plan is
to eventually move to something like Hibernate, where the persistence
will be transparently done.  So there isn't really a _need_ for an
update() method.  I could change the behaviour of my in-memory
repository to return a copy of the actual object and create an update
method that has to be called for any changes to be persisted.

Another problem is that I haven't added any surrogate IDs at this
point because I was thinking of them as purely backend issues.  Now
I'm starting to think that I'll need a surrogate ID as part of the
domain model so that in the repository I can find any object with the
same natural identifier as the object passed into the update() method
and check to see if the surrogate IDs match.  If there is an object
with the same natural identifier and the surrogate IDs are the same,
the the natural identifier isn't changing.  If they don't match, then
I can't do the update because an object with the natural identifier
already exists.  If there is no object with that same natural
identifier then I can go ahead and perform the update. 

Does all this sound reasonable/workable?  Is there anything I'm
forgetting?

Thanks for the input, I really appreciate it.
Rich

--- In domaindrivendesign <at> yahoogroups.com, "Bill Hamaker"
<BillHamaker@...> wrote:
>
> I think the normal approach would be to have Update be a method in your
> repository so uniqueness is always checked by the repository.     You
> need to distinguish between changing the unique values in the domain
> object versus saving the domain object into the repository.
> 
>  
> 
> If you wanted to check for uniqueness ahead of time I would have a
> CheckForUniqueness methods in the repository also.
> 
>  
> 
> Bill Hamaker
> 
> 
> 
> CONFIDENTIALITY NOTICE:
> 
> The information contained in this message may be privileged and
confidential. It may also be protected from disclosure or be a
> privileged work product or proprietary information. This information
is intended for the exclusive use of the addressee(s). If you are not
the intended recipient, please notify the sender immediately by
replying to this message and you are hereby notified that any use,
disclosure,
> dissemination, distribution (other than to the addressee[s]),
copying or taking of any action because of this information is
strictly prohibited.
> 
> Thank you,
> 
> Marvin F. Poer and Company
>

 
Joey Samonte | 3 Feb 00:59
Picon
Favicon
Gravatar

Re: A RepositoryManager?

Good day!
So a repository is not just a DAO? Can you give an example of how it manages instances of domain objects? In my mind, I thought that a repository commonly has interaction with the database, but the methods it has usually are related to the functionalities that the application has.
 
Thanks!

Felipe Rodrigues de Almeida <felipero.maillist <at> gmail.com> wrote:
Just to remember,

Repositories are like collections of objects and not DAOs. Sometimes some repository implementation has some iteraction with database, but I preffer write a separated DAO and use that through a repository implementation.

Like collections, doesn't make sense put lot of business rules inside a repository. All that you repository have to do is to manage the instances of domains. The business rules MUST be in the domain objects, so, the most part of transactions should be controled in domain objects (if really really necessary).

DDD is about simplicity.

Best,


Felipe Rodrigues
Fratech


Ben Scheirman escreveu:
I use the Unit Of Work pattern generally to control my transaction boundaries.

using(UnitOfWork.Start)
{
 & nbsp;   _customerRepository.Save(customer);
     _accountRepository.Save(account);
     UnitOfWork.Complete();
}

depending on the environment, this is a thread-scoped class that controls the transaction boundary for me.

If you're using NHibernate, check out RhinoCommons:
http://www.ayende.com/Blog/archive/2007/06/08/Rhino-Commons-RepositoryltTgt-and-Unit-Of-Work.aspx


On Jan 31, 2008 11:48 PM, Chris Beams <cbeams <at> gmail.com> wrote:
Joey, div>

Ideally you'll want to use declarative transaction management.  Take a look at Spring's support:


- Chris Beams



On Jan 31, 2008, at 10:32 PM, Joey Samonte wrote:


Good day to all!
From my current understanding of repository, you usually would have one repository for each entity you have in your domain model. But how do you manage database connection, transaction between all your repositories? Do you need to create a RepositoryManager to handle connections, transactions, and all your repositories? Any code samples?
 
Thank you very much.

Looking for last minute shopping deals? Find them fast with Yahoo! Search.




--
Felipe Rodrigues de Almeida
Fratech - Tecnologia da informação

+55 19 3119-6880 / +55 19 8125-4977
Rua Pedro Álvarez Cabral, 227 - Sta. Cruz
Sta. Bárbara D'Oeste - SP

Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. __._,_.___

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___
Rafael Ponte | 1 Feb 13:36
Picon
Gravatar

Re: A RepositoryManager?

You may use Spring Transactional Management that is excelent, or you may implement a custom transaction management
using AOP.

On Feb 1, 2008 10:20 AM, Ben Scheirman <subdigital <at> gmail.com> wrote:

I use the Unit Of Work pattern generally to control my transaction boundaries.

using(UnitOfWork.Start)
{
     _customerRepository.Save(customer);
     _accountRepository.Save(account);
     UnitOfWork.Complete();
}

depending on the environment, this is a thread-scoped class that controls the transaction boundary for me.

If you're using NHibernate, check out RhinoCommons:
http://www.ayende.com/Blog/archive/2007/06/08/Rhino-Commons-RepositoryltTgt-and-Unit-Of-Work.aspx




On Jan 31, 2008 11:48 PM, Chris Beams <cbeams <at> gmail.com> wrote:

Joey,


Ideally you'll want to use declarative transaction management.  Take a look at Spring's support:


- Chris Beams



On Jan 31, 2008, at 10:32 PM, Joey Samonte wrote:


Good day to all!
From my current understanding of repository, you usually would have one repository for each entity you have in your domain model. But how do you manage database connection, transaction between all your repositories? Do you need to create a RepositoryManager to handle connections, transactions, and all your repositories? Any code samples?
 
Thank you very much.

Looking for last minute shopping deals? Find them fast with Yahoo! Search.






--
Rafael Ponte __._,_.___

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___
Daniel Yokomizo | 3 Feb 04:15
Picon
Gravatar

Re: Best way to orchestrate methods when using DDD

On Thu, Jan 31, 2008 at 9:01 AM, kaushik_spock <kaushik.spock <at> gmail.com> wrote:
> We are trying out DDD in our project and have been stuck with some
>  issues on the best way of orchestrating method calls across multiple
>  domain objects.
>
>  We have 3 domain objects - Order, Ticket and Block. The relationship
>  between them is as follows
>
>  - Order can have one to many Tickets
>  - Block can have one to many Tickets
>
>  We are using hibernate as our ORM tool. So we can navigate between
>  any entity. So to go from order to block (or vice versa), we
>  navigate from order to ticket and from ticket to its owning block.
>
>  From the GUI we can call operations like cancel on any of the domain
>  objects. If Cancel is called on any one entity, it requires all
>  other entities to be cancelled as well.
>  - If cancel on order/ticket is called, ticket/order will be
>  cancelled and block may be cancelled based on some conditions.
>
>  Options tried
>
>  - Cancel methods in each object which would also call cancel on one
>  other entity. So the block's cancel method would be responsible for
>  calling cancel on both ticket and ticket will call order's cancel
>  method. This seems to be messy and leads to circular calls.

It's easy to break the cycle by introducing some temporary variables
to signal methods in progress:

Order.cancel() {
    if (this.cancelling) return;
    this.cancelling = true;
    doCancel();
    cancelAll(ticket);
    this.cancelling = false;
}

Ticket.cancel() {
    if (this.cancelling) return;
    this.cancelling = true;
    doCancel();
    this.order.cancel();
    this.cancelling = false;
}

This stuff is plain boilerplate but may become too messy. OTOH if
you're modelling these as explicit state transitions then the
infrastructure code can deal with this current transition issue and
avoid infinite cycles.

>  - Distinct methods for each flow possible, cancelFromBlock ,
>  cancelFromTicket but this seems to lead to method explosion as
>  methods for all possible calls need to be present in all 3 objects
>
>  We are now thinking the best way is to have cancel methods on each
>  object that will just cancel itself. Some orchestrator method/object
>  somewhere would calls these methods in proper sequence. We are not
>  sure where this method belongs.
>
>  - Where do such orchestrator methods belong ? Should this be present
>  in a service or should it be part of the domain object itself as a
>  value object.
>  - If we use services, how should the service get a reference to the
>  domain object from hibernate? Should it talk to the DAO directly to

>  load the domain object directly ?
>
>  Thanks in Advance for the help.

Best regards,
Daniel Yokomizo

 

Gmane