I'm working on project whose core framework is built using IBatisNet.
It also supports pluggable modules via IBatisNet. This is one of our
example module dao classes. BaseSqlMapDao comes from here:

http://tinyurl.com/8uks6
http://svn.apache.org/repos/asf/ibatis/trunk/cs/npetshop/NPetshop.Persistence/MapperDao/BaseSqlMapDao.cs

public class ModuleNewsArticleSqlMapDao : BaseSqlMapDao
{
 private static SqlMapper moduleSqlMapper = null;

 protected override SqlMapper GetSystemSqlMap()
 {
  // TODO: add double-check
  if (moduleSqlMapper == null)
  {
   // warning: Configure is depreciated
   moduleSqlMapper = SqlMapper.Configure(GetModuleSqlMapConfigPath());

   moduleSqlMapper.DataSource = base.GetSystemSqlMap().DataSource;
  }
  return moduleSqlMapper;
 }

 public IList GetMany()
 {
  return ExecuteQueryForList("GetMany", null);
 }

 // snip

}

Modules are placed in their own directory and are required to have
their own ModuleSqlMap.config file. A ModuleSqlMap.config file looks
something like this:

<sqlMapConfig>
 <database>
  <provider name="sqlServer1.1"/>
  <dataSource 
    name="Dynamically Filled in at runtime" 
    connectionString="Dynamically Filled in at runtime" />
 </database>
 <sqlMaps>
  <sqlMap embedded="Resources.NewsArticle.xml, Foo.Bar.NewsArticle" />
 </sqlMaps>
</sqlMapConfig>

We have providers.config at the root of the application so it does not
need to be specified.

That code was originally written for an older version of IBatisNet.
There are overloads now that allow you build a SqlMapper instance from
an XmlDocument, embedded resource, etc. You might be able to do away
with a ModuleSqlMap.config file. I like having the external file
becuase I can turn caching on or off on a per module basis without
recompiling the application.

While this exact code doesn't exist yet:

 DomSqlMapBuilder builder = new DomSqlMapBuilder();
 builder.AppProperty("SELECT_KEY", "SELECT @@IDENTITIY");
 builder.AddSqlMap("newsModelSqlMap.xml");
 builder.CacheModelsEnabled = true;
 _mapper = builder.Configure();

It could be implemented by building a sqlMap.config xml document in
memory and passing that in to the existing Configure method.

- Ron

--- Tuncay Baskan <[EMAIL PROTECTED]> wrote:

> 1) I want my developers (specifically module owners) to write only
> SqlMap files. Because there is no need to declare same "provider",
> same "settings", same "database" options in each module. To do this I
> think I need a different configuration API than the current one. I
> tried to analyze IBatisNet.DataMapper.Configuration.DomSqlMapBuilder.
> It simply reads file references from sqlMapConfig/sqlMaps and
> constructs internal data structures. Is there any way that I can
> programmatically specify which SqlMap files will be parsed and
> loaded?
> 
> 2) Since the application is multithreaded I wonder if having multiple
> SqlMappers cause problems?
> 
> I know I wrote too much in this email. :-) I tried my best to explain
> the situation well..
> 
> -- 
> /tb.
> 

Reply via email to