BAEL-2169 Guide to Ebean

This commit is contained in:
Josephine Barboza 2018-10-07 13:14:31 +05:30
parent 5022d3fbf9
commit 62d677ed30
7 changed files with 162 additions and 101 deletions

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>libraries-data</artifactId> <artifactId>libraries-data</artifactId>
@ -13,6 +14,7 @@
</parent> </parent>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.esotericsoftware</groupId> <groupId>com.esotericsoftware</groupId>
<artifactId>kryo</artifactId> <artifactId>kryo</artifactId>
@ -99,36 +101,49 @@
<groupId>org.datanucleus</groupId> <groupId>org.datanucleus</groupId>
<artifactId>javax.jdo</artifactId> <artifactId>javax.jdo</artifactId>
<version>${javax.jdo.version}</version> <version>${javax.jdo.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.datanucleus</groupId> <groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId> <artifactId>datanucleus-core</artifactId>
<version>${datanucleus.version}</version> <version>${datanucleus.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.datanucleus</groupId> <groupId>org.datanucleus</groupId>
<artifactId>datanucleus-api-jdo</artifactId> <artifactId>datanucleus-api-jdo</artifactId>
<version>${datanucleus.version}</version> <version>${datanucleus.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.datanucleus</groupId> <groupId>org.datanucleus</groupId>
<artifactId>datanucleus-rdbms</artifactId> <artifactId>datanucleus-rdbms</artifactId>
<version>${datanucleus.version}</version> <version>${datanucleus.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.datanucleus</groupId> <groupId>org.datanucleus</groupId>
<artifactId>datanucleus-maven-plugin</artifactId> <artifactId>datanucleus-maven-plugin</artifactId>
<version>${datanucleus-maven-plugin.version}</version> <version>${datanucleus-maven-plugin.version}</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.datanucleus</groupId> <groupId>org.datanucleus</groupId>
<artifactId>datanucleus-xml</artifactId> <artifactId>datanucleus-xml</artifactId>
<version>${datanucleus-xml.version}</version> <version>${datanucleus-xml.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.datanucleus</groupId> <groupId>org.datanucleus</groupId>
<artifactId>datanucleus-jdo-query</artifactId> <artifactId>datanucleus-jdo-query</artifactId>
<version>${datanucleus-jdo-query.version}</version> <version>${datanucleus-jdo-query.version}</version>
</dependency> </dependency>
<!-- Jcache --> <!-- Jcache -->
<dependency> <dependency>
@ -141,49 +156,55 @@
<artifactId>hazelcast</artifactId> <artifactId>hazelcast</artifactId>
<version>${hazelcast.version}</version> <version>${hazelcast.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.googlecode.jmapper-framework</groupId> <groupId>com.googlecode.jmapper-framework</groupId>
<artifactId>jmapper-core</artifactId> <artifactId>jmapper-core</artifactId>
<version>${jmapper.version}</version> <version>${jmapper.version}</version>
</dependency> </dependency>
<!-- crunch project --> <!-- crunch project -->
<dependency> <dependency>
<groupId>org.apache.crunch</groupId> <groupId>org.apache.crunch</groupId>
<artifactId>crunch-core</artifactId> <artifactId>crunch-core</artifactId>
<version>${org.apache.crunch.crunch-core.version}</version> <version>${org.apache.crunch.crunch-core.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.hadoop</groupId> <groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId> <artifactId>hadoop-client</artifactId>
<version>${org.apache.hadoop.hadoop-client}</version> <version>${org.apache.hadoop.hadoop-client}</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> <exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency> <dependency>
<groupId>commons-cli</groupId> <groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId> <artifactId>commons-cli</artifactId>
<version>1.2</version> <version>1.2</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-io</groupId> <groupId>commons-io</groupId>
<artifactId>commons-io</artifactId> <artifactId>commons-io</artifactId>
<version>2.1</version> <version>2.1</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-httpclient</groupId> <groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId> <artifactId>commons-httpclient</artifactId>
<version>3.0.1</version> <version>3.0.1</version>
<scope>provided</scope> <scope>provided</scope>
<exclusions> <exclusions>
<exclusion> <exclusion>
<groupId>commons-codec</groupId> <groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId> <artifactId>commons-codec</artifactId>
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.flink</groupId> <groupId>org.apache.flink</groupId>
<artifactId>flink-connector-kafka-0.11_2.11</artifactId> <artifactId>flink-connector-kafka-0.11_2.11</artifactId>
@ -249,19 +270,32 @@
<version>${awaitility.version}</version> <version>${awaitility.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<dependency>
<groupId>io.ebean</groupId> <groupId>io.ebean</groupId>
<artifactId>ebean</artifactId> <artifactId>ebean</artifactId>
<version>11.22.4</version> <version>${ebean.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency> <dependency>
<groupId>ch.qos.logback</groupId> <groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId> <artifactId>logback-classic</artifactId>
<version>1.2.3</version> <version>${logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
@ -280,16 +314,28 @@
</goals> </goals>
<configuration> <configuration>
<tasks> <tasks>
<property name="plugin_classpath" refid="maven.plugin.classpath" /> <property
<taskdef name="gen-reladomo" classpath="plugin_classpath" classname="com.gs.fw.common.mithra.generator.MithraGenerator" /> name="plugin_classpath"
<gen-reladomo xml="${project.basedir}/src/main/resources/reladomo/ReladomoClassList.xml" generateGscListMethod="true" refid="maven.plugin.classpath" />
generatedDir="${project.build.directory}/generated-sources/reladomo" nonGeneratedDir="${project.basedir}/src/main/java" /> <taskdef name="gen-reladomo"
classpath="plugin_classpath"
classname="com.gs.fw.common.mithra.generator.MithraGenerator" />
<gen-reladomo
xml="${project.basedir}/src/main/resources/reladomo/ReladomoClassList.xml"
generateGscListMethod="true"
generatedDir="${project.build.directory}/generated-sources/reladomo"
nonGeneratedDir="${project.basedir}/src/main/java" />
<taskdef name="gen-ddl" classname="com.gs.fw.common.mithra.generator.dbgenerator.MithraDbDefinitionGenerator" loaderRef="reladomoGenerator"> <taskdef name="gen-ddl"
<classpath refid="maven.plugin.classpath" /> classname="com.gs.fw.common.mithra.generator.dbgenerator.MithraDbDefinitionGenerator"
loaderRef="reladomoGenerator">
<classpath
refid="maven.plugin.classpath" />
</taskdef> </taskdef>
<gen-ddl xml="${project.basedir}/src/main/resources/reladomo/ReladomoClassList.xml" <gen-ddl
generatedDir="${project.build.directory}/generated-db/sql" databaseType="postgres" /> xml="${project.basedir}/src/main/resources/reladomo/ReladomoClassList.xml"
generatedDir="${project.build.directory}/generated-db/sql"
databaseType="postgres" />
</tasks> </tasks>
</configuration> </configuration>
</execution> </execution>
@ -344,35 +390,35 @@
<!-- /Reladomo --> <!-- /Reladomo -->
<!-- JDO Plugin --> <!-- JDO Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId> <plugin>
<artifactId>maven-assembly-plugin</artifactId> <groupId>org.apache.maven.plugins</groupId>
<version>2.3</version> <artifactId>maven-assembly-plugin</artifactId>
<configuration> <version>2.3</version>
<descriptors> <configuration>
<descriptor>src/main/assembly/hadoop-job.xml</descriptor> <descriptors>
</descriptors> <descriptor>src/main/assembly/hadoop-job.xml</descriptor>
<archive> </descriptors>
<manifest> <archive>
<mainClass>com.baeldung.crunch.WordCount</mainClass> <manifest>
</manifest> <mainClass>com.baeldung.crunch.WordCount</mainClass>
</archive> </manifest>
</configuration> </archive>
<executions> </configuration>
<execution> <executions>
<id>make-assembly</id> <execution>
<phase>package</phase> <id>make-assembly</id>
<goals> <phase>package</phase>
<goal>single</goal> <goals>
</goals> <goal>single</goal>
</execution> </goals>
</executions> </execution>
</plugin> </executions>
</plugin>
</plugins> </plugins>
<pluginManagement> <pluginManagement>
<plugins> <plugins>
<plugin> <plugin>
<groupId>io.ebean</groupId> <groupId>io.ebean</groupId>
@ -429,7 +475,10 @@
<datanucleus-jdo-query.version>5.0.4</datanucleus-jdo-query.version> <datanucleus-jdo-query.version>5.0.4</datanucleus-jdo-query.version>
<jmapper.version>1.6.0.1</jmapper.version> <jmapper.version>1.6.0.1</jmapper.version>
<org.apache.crunch.crunch-core.version>0.15.0</org.apache.crunch.crunch-core.version> <org.apache.crunch.crunch-core.version>0.15.0</org.apache.crunch.crunch-core.version>
<org.apache.hadoop.hadoop-client>2.2.0</org.apache.hadoop.hadoop-client> <org.apache.hadoop.hadoop-client>2.2.0</org.apache.hadoop.hadoop-client>
<ebean.version>11.22.4</ebean.version>
<slf4j.version>1.7.25</slf4j.version>
<logback.version>1.0.1</logback.version>
</properties> </properties>
</project> </project>

View File

@ -28,7 +28,7 @@ public class App {
} }
public static void crudOperations() { public static void crudOperations() {
Address a1 = new Address("5, Wide Street", null, "New York"); Address a1 = new Address("5, Wide Street", null, "New York");
Customer c1 = new Customer("John Wide", a1); Customer c1 = new Customer("John Wide", a1);

View File

@ -3,7 +3,7 @@ package com.baeldung.ebean.model;
import javax.persistence.Entity; import javax.persistence.Entity;
@Entity @Entity
public class Address extends BaseModel{ public class Address extends BaseModel {
public Address(String addressLine1, String addressLine2, String city) { public Address(String addressLine1, String addressLine2, String city) {
super(); super();
@ -11,32 +11,38 @@ public class Address extends BaseModel{
this.addressLine2 = addressLine2; this.addressLine2 = addressLine2;
this.city = city; this.city = city;
} }
private String addressLine1; private String addressLine1;
private String addressLine2; private String addressLine2;
private String city; private String city;
public String getAddressLine1() { public String getAddressLine1() {
return addressLine1; return addressLine1;
} }
public void setAddressLine1(String addressLine1) { public void setAddressLine1(String addressLine1) {
this.addressLine1 = addressLine1; this.addressLine1 = addressLine1;
} }
public String getAddressLine2() { public String getAddressLine2() {
return addressLine2; return addressLine2;
} }
public void setAddressLine2(String addressLine2) { public void setAddressLine2(String addressLine2) {
this.addressLine2 = addressLine2; this.addressLine2 = addressLine2;
} }
public String getCity() { public String getCity() {
return city; return city;
} }
public void setCity(String city) { public void setCity(String city) {
this.city = city; this.city = city;
} }
@Override @Override
public String toString() { public String toString() {
return "Address [id=" + id + ", addressLine1=" + addressLine1 + ", addressLine2=" + addressLine2 + ", city=" + city + "]"; return "Address [id=" + id + ", addressLine1=" + addressLine1 + ", addressLine2=" + addressLine2 + ", city=" + city + "]";
} }
} }

View File

@ -14,13 +14,13 @@ public abstract class BaseModel {
@Id @Id
protected long id; protected long id;
@Version @Version
protected long version; protected long version;
@WhenCreated @WhenCreated
protected Instant createdOn; protected Instant createdOn;
@WhenModified @WhenModified
protected Instant modifiedOn; protected Instant modifiedOn;
@ -55,5 +55,5 @@ public abstract class BaseModel {
public void setVersion(long version) { public void setVersion(long version) {
this.version = version; this.version = version;
} }
} }

View File

@ -1,13 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<configuration> <configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <appender name="STDOUT"
<encoder> class="ch.qos.logback.core.ConsoleAppender">
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n <encoder>
</pattern> <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</encoder> </pattern>
</appender> </encoder>
</appender>
<root level="INFO"> <logger name="io.ebean.DDL" level="TRACE">
<appender-ref ref="STDOUT" /> <appender-ref ref="STDOUT" />
</root> </logger>
<logger name="io.ebean.SQL" level="TRACE">
<appender-ref ref="STDOUT" />
</logger>
<logger name="io.ebean.TXN" level="TRACE">
<appender-ref ref="STDOUT" />
</logger>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration> </configuration>

View File

@ -1,3 +0,0 @@
<logger name="io.ebean.DDL" level="TRACE"/>
<logger name="io.ebean.SQL" level="TRACE"/>
<logger name="io.ebean.TXN" level="TRACE"/>