ibatis-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ron Grabowski (JIRA)" <ibatis-...@incubator.apache.org>
Subject [jira] Created: (IBATISNET-262) Refactor duplicate code for opening session into DataMapperLocalSessionScope
Date Sat, 17 May 2008 19:03:55 GMT
Refactor duplicate code for opening session into DataMapperLocalSessionScope

                 Key: IBATISNET-262
                 URL: https://issues.apache.org/jira/browse/IBATISNET-262
             Project: iBatis for .NET
          Issue Type: Improvement
    Affects Versions: DataMapper 2.0
            Reporter: Ron Grabowski
            Assignee: Gilles Bayon
            Priority: Minor

Move duplicate code for creating the local session into a class level scope that has access
to the private members of DataMapper:

private class DataMapperLocalSessionScope : IDisposable
    private readonly ISession session;
    private readonly bool isSessionLocal = false;

    public DataMapperLocalSessionScope(DataMapper dataMapper)
        isSessionLocal = false;
        session = dataMapper.sessionStore.CurrentSession;

        if (session == null)
            session = dataMapper.sessionFactory.OpenSession();
            isSessionLocal = true;

    public ISession Session
        get { return session; }

    public void Dispose()
        if (isSessionLocal)

to avoid duplicating code across 22 methods. The code in each of the Query... methods is now
much shorter:

public IList QueryForList(string statementId, object parameterObject)
    using (DataMapperLocalSessionScope sessionScope = new DataMapperLocalSessionScope(this))
        IMappedStatement statement = modelStore.GetMappedStatement(statementId);
        return statement.ExecuteQueryForList(sessionScope.Session, parameterObject);

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message