-
Notifications
You must be signed in to change notification settings - Fork 24
Configuration
To use Mirage-SQL as standalone library, you have to create a jdbc.properties file in the classpath root.
jdbc.driver=org.h2.Driver
jdbc.url=jdbc:h2:tcp://localhost:9092/test
jdbc.user=sa
jdbc.password=
With JDBC 4.0 driver, you can omit the jdbc.driver property.
Please note that Mirage-SQL does not provide connection pooling in it's default configuration. If you want to enable connection pooling, see DBCPSessionImpl or HikariCPSessionImpl for details.
You can get an instance of SqlManager from the Session. The Session is created by the SessionFactory by reading the properties from the jdbc.properties file.
Session session = SessionFactory.getSession();
SqlManager sqlManager = session.getSqlManager();As an alternative one can pass the connection (or connection pool) properties directly to the SessionFactory, without having the jdbc.properties file in the classpath:
Propeties props = ... // get connection settings elswhere than jdbc.properties
Session session = SessionFactory.getSession(props);
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>com.miragesql.miragesql.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().