EBean module for Guice
This is based on the ninja-ebean-ng module for Ninja Framework. EBean is a simple and powerful ORM tool. This module allows you to use EBean with Guice, and removes the Ninja dependencies of its predecessors.
Setup
-
This assumes you have a binding or provider for your implementation of EbeanProperties, which supplies the configuration for EBean.
-
There is a convenience in EBeanProperties that allows you to pass a java.util.Properties object conforming to the following property names:
ebean.ddl.generate = false ebean.ddl.run = false ebean.ddl.seedSql = ebean.ddl.initSql = ebean.models = com.company.models.*,org.otherorg.models.Foo ebean.datasource.name = dbname ebean.datasource.databaseUrl = jdbc:mysql://localhost:3306/dbname ebean.datasource.databaseDriver = com.mysql.jdbc.Driver ebean.datasource.username = root ebean.datasource.password = test ebean.datasource.minConnections = ebean.datasource.maxConnections = ebean.datasource.heartbeatsql = ebean.datasource.isolationlevel =
Please note that ebean.models
accepts a comma delimited list of both class names as well as packages (just make sure it ends with .*)
-
Add the ebean-guice dependency to your pom.xml:
<dependency> <groupId>com.brightback.oss</groupId> <artifactId>ebean-guice</artifactId> <version>0.0.1</version> </dependency>
-
Add ebean's enhancer plugin to your pom.xml:
<plugin> <groupId>io.ebean</groupId> <artifactId>ebean-maven-plugin</artifactId> <version>${ebean.version}</version> <executions> <execution> <id>ebean-enhancer</id> <phase>process-classes</phase> <configuration> <classSource>${project.build.outputDirectory}</classSource> <packages>models</packages> <transformArgs>debug=1</transformArgs> </configuration> <goals> <goal>enhance</goal> </goals> </execution> </executions> </plugin>
-
Install the module:
@Override public void configure() { install(new EbeanModule()); }
-
Specify a provider for EbeanProperties:
// Simple System.getProperties example: @Provides public EbeanProperties getEbeanProperties() { return EbeanProperties.fromProperties(System.getProperties()); } // Named Java Properties example: @Provides public EbeanProperties getEbeanProperties(@Named("ebean.properties") Properties props) { return EbeanProperties.fromProperties(props); } // Ninja example: @Provides public EbeanProperties getEbeanProperties(NinjaProperties props) { return EbeanProperties.fromProperties(props.getAllCurrentNinjaProperties()); } // Provide your own! @Provides public EbeanProperties getEbeanProperties() { return new MyEbeanProperties(); }