ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Clinton Begin <clinton.be...@gmail.com>
Subject Re: Best practice to configure SQL Map for a web application
Date Sun, 24 May 2009 03:28:09 GMT
You can use a factory, a singleton, or a dependency injection container such
as Spring or Guice.

Cheers,
Clinton

On Sat, May 23, 2009 at 9:08 PM, Anoop kumar V <anoopkumarv@gmail.com>wrote:

> I was reading the example that ships with Ibatis and the initializer block
> has this comment before configuring the SQL Map. I was just curious what is
> the best practice of configuring one if not in the class initializer / a
> constructor? I was hoping to call the class as part of the servlet init.
>
>   /**
>    * It's not a good idea to put code that can fail in a class initializer,
>    * but for sake of argument, here's how you configure an SQL Map.
>    */
>   static {
>     try {
>       Reader reader =
> Resources.getResourceAsReader("com/mydomain/data/SqlMapConfig.xml");
>       sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
>       reader.close();
>     } catch (IOException e) {
>       // Fail fast.
>       throw new RuntimeException("Something bad happened while building the
> SqlMapClient instance." + e, e);
>     }
>
>
> Thanks,
> Anoop
>

Mime
View raw message