Skip to content
Naoki Takezoe edited this page Nov 8, 2013 · 13 revisions

Maven

You can get Mirage from the Maven central repository. Add the following fragment into your pom.xml.

<dependencies>
  <dependency>
    <groupId>jp.sf.amateras</groupId>
    <artifactId>mirage</artifactId>
    <version>1.2.1</version>
  </dependency>
</dependencies>

jdbc.properties

To use Mirage as standalone library, you have to create jdbc.properties in classpath root. With JDBC 4.0 driver, you can omit jdbc.driver property.

jdbc.driver=org.h2.Driver
jdbc.url=jdbc:h2:tcp://localhost:9092/test
jdbc.user=sa
jdbc.password=

Please note that Mirage does not provide connection pooling in default configuration. If you want to enable connection pooling, see DBCPSessionImpl.

You can get SqlManager from Session. Session is created by SessionFactory. SessionFactory read jdbc.properties and initializes Session using this information.

Session session = SessionFactory.getSession();
SqlManager sqlManager = session.getSqlManager();

If you want to use Mirage with DI container such as Spring Framework or Google Guice, you have to configure Mirage for these container. See details in Integration.

OpenSessionInViewFilter

Mirage can control transaction automatically using OpenSessionInViewFilter. Register it in your web.xml as follows:

<filter>
  <filter-name>OpenSessionInViewFilter</filter-name>
  <filter-class>jp.sf.amateras.mirage.filter.OpenSessionInViewFilter</filter-class>
</filter>

<filter-mapping>
  <filter-name>OpenSessionInViewFilter</filter-name>
  <url-pattern>*</url-pattern>
  <dispatcher>REQUEST</dispatcher>
</filter-mapping>

This filter begins transaction at the head of request processing. If no exception in request processing, this filter commit transaction by invoking Session#commit(). However if exception is caused, this filter catches it and rollback transaction by invoking Session#rollback().

Clone this wiki locally