-
Notifications
You must be signed in to change notification settings - Fork 24
Configuration
You can get Mirage-SQL 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.3</version>
</dependency>
</dependencies>To use Mirage-SQL 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-SQL 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-SQL with DI container such as Spring Framework or Google Guice, you have to configure Mirage for these container. See details at Integration.
Mirage-SQL 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().