Note that there are some explanatory texts on larger screens.

plurals
  1. POHandling Transactions in DAO with an Injected iBATIS.NET SQL Mapper
    primarykey
    data
    text
    <p>I am currently using iBATIS.NET for a small application I am building. I like to create concrete Classes for my DAOs instead of using ISqlMapper directly and invoking named SQL statements. I am not using a Dependency Injection container of any sort, so ideally I have my DAOs set up as follows:</p> <pre><code>public abstract class AbstractDAO { /// &lt;summary&gt; /// SQL Mapper. /// &lt;/summary&gt; ISqlMapper mapper; /// &lt;summary&gt; /// Default Constructor. /// &lt;/summary&gt; /// &lt;param name="mapper"&gt;&lt;/param&gt; public AbstractDAO(ISqlMapper mapper) { this.mapper = mapper; } } public class NodeDAO : AbstractDAO { /// &lt;summary&gt; /// Default Constructor. /// &lt;/summary&gt; /// &lt;param name="mapper"&gt;&lt;/param&gt; public NodeDAO(ISqlMapper mapper) : base(mapper) { } /// &lt;summary&gt; /// Insert Node. /// &lt;/summary&gt; /// &lt;param name="node"&gt;&lt;/param&gt; public void InsertNode(Node node) { // ... Assume Some Pretty Code. } } public class NodeRevisionDAO : AbstractDAO { /// &lt;summary&gt; /// Default Constructor. /// &lt;/summary&gt; /// &lt;param name="mapper"&gt;&lt;/param&gt; public NodeRevisionDAO (ISqlMapper mapper) : base(mapper) { } /// &lt;summary&gt; /// Insert Node Revision. /// &lt;/summary&gt; /// &lt;param name="nodeRevision"&gt;&lt;/param&gt; public void InsertNodeRevision(NodeRevision nodeRevision) { // ... Assume Some Pretty Code. } } </code></pre> <p>From my main application code, let's say in some form of Business Layer, I would ideally call two insert Methods on the DAOs:</p> <pre><code>// ... Assume DAOs are Initialized. nodeDAO.InsertNode(node); nodeRevisionDAO.InsertNodeRevision(nodeRevision); </code></pre> <p>I want to make sure both statements are executed as an atomic operation in a transaction so that if either fails, both will be rolled back. But because the ISqlMapper is injected in both DAOs I have no control over the transactions.</p> <p>What would be the best approach to this problem? Putting it in another way, how can I handle transactions without exposing the ISqlMapper?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload