            ------
            Using Mirage with other Frameworks
            ------
            Naoki Takezoe
            ------
            2010-04-18

Using Mirage with other Frameworks

 You can use Mirage with other frameworks such as Spring Framework or Google Guice.

* Spring Framework

 Mirage can work with Spring Framework using <<SpringConnectionProvider>> instead of DefaultConnectionProvider.

--------
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  <property name="driverClassName" value="org.h2.Driver" />
  <property name="url" value="jdbc:h2:tcp://localhost:9092/test" />
  <property name="username" value="sa" />
  <property name="password" value="" />
</bean>

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="dataSource"/>
</bean>

<bean id="connectionProvider" class="jp.sf.amateras.mirage.integration.spring.SpringConnectionProvider">
  <property name="transactionManager" ref="transactionManager" />
</bean>

<bean id="sqlManager" class="jp.sf.amateras.mirage.SqlManagerImpl">
  <property name="connectionProvider" ref="connectionProvider" />
</bean>
--------

 You can use SqlManager as follow in your code:

--------
private SqlManager sqlManager;


public void setSqlManager(SqlManager sqlManager){
  this.sqlManager = sqlManager;
}

@Transactional
public void execute(){
  // Database access using SqlManager
  ...
}
--------

 In Spring Framework, JDBC connection informations are defined in Spring bean desfinition file, and transaction
 is controlled by AOP. So you don't need to make jdbc.properties and don't need to use Session and SessionFactory.

* Google Guice

 TODO