Skip to content

Commit 099e7db

Browse files
committed
HBX-2869: Create a GenerateHBM Mojo in the Maven plugin - Test the Mojo
Signed-off-by: Koen Aers <[email protected]>
1 parent a89a47d commit 099e7db

File tree

8 files changed

+115
-0
lines changed

8 files changed

+115
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
invoker.java.version = 1.8+
2+
invoker.goals = generate-resources
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.hibernate.tool.test</groupId>
8+
<artifactId>hbm2ddl</artifactId>
9+
<version>0.0.1-SNAPSHOT</version>
10+
11+
<properties>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
14+
15+
<java.version>1.8</java.version>
16+
<h2.version>1.4.195</h2.version>
17+
</properties>
18+
19+
<build>
20+
<plugins>
21+
<plugin>
22+
<groupId>org.hibernate</groupId>
23+
<artifactId>hibernate-tools-maven-plugin</artifactId>
24+
<version>@project.version@</version>
25+
<executions>
26+
<execution>
27+
<id>HBM generation</id>
28+
<phase>generate-resources</phase>
29+
<goals>
30+
<goal>generateHbm</goal>
31+
</goals>
32+
<configuration>
33+
<outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
34+
<templatePath>${project.basedir}/src/main/resources/templates/</templatePath>
35+
</configuration>
36+
</execution>
37+
</executions>
38+
<configuration>
39+
<revengFile>${project.basedir}/src/main/resources/hibernate.reveng.xml</revengFile>
40+
</configuration>
41+
<dependencies>
42+
<dependency>
43+
<!-- DB Driver of your choice -->
44+
<groupId>com.h2database</groupId>
45+
<artifactId>h2</artifactId>
46+
<version>${h2.version}</version>
47+
</dependency>
48+
</dependencies>
49+
</plugin>
50+
</plugins>
51+
</build>
52+
53+
</project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
hibernate.dialect=org.hibernate.dialect.H2Dialect
2+
hibernate.connection.driver_class=org.h2.Driver
3+
hibernate.connection.url=jdbc:h2:./test;DB_CLOSE_ON_EXIT=FALSE
4+
hibernate.connection.username=sa
5+
hibernate.connection.password=
6+
hibernate.connection.pool_size=1
7+
hibernate.show_sql=true
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE hibernate-reverse-engineering SYSTEM "http://hibernate.org/dtd/hibernate-reverse-engineering-3.0.dtd" >
3+
4+
<hibernate-reverse-engineering>
5+
6+
<type-mapping>
7+
<sql-type jdbc-type="DATE" hibernate-type="java.time.LocalDate"/>
8+
<sql-type jdbc-type="TIMESTAMP" hibernate-type="java.time.LocalDateTime"/>
9+
</type-mapping>
10+
11+
</hibernate-reverse-engineering>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
${pojo.getPackageDeclaration()}
2+
// Generated ${date} by Hibernate Tools ${version}
3+
4+
<#assign classbody>
5+
<#include "PojoTypeDeclaration.ftl"/> {
6+
7+
<#if !pojo.isInterface()>
8+
<#include "PojoFields.ftl"/>
9+
10+
<#include "PojoConstructors.ftl"/>
11+
12+
<#include "PojoPropertyAccessors.ftl"/>
13+
14+
<#include "PojoToString.ftl"/>
15+
16+
<#include "PojoEqualsHashcode.ftl"/>
17+
18+
<#else>
19+
<#include "PojoInterfacePropertyAccessors.ftl"/>
20+
21+
</#if>
22+
<#include "PojoExtraClassCode.ftl"/>
23+
24+
}
25+
</#assign>
26+
27+
${pojo.generateImports()}
28+
${classbody}
29+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<#-- // Fields -->
2+
<#list pojo.getAllPropertiesIterator() as field><#if pojo.getMetaAttribAsBool(field, "gen-property", true)><#if pojo.hasMetaAttribute(field, "field-description")> /**
3+
${pojo.getFieldJavaDoc(field, 0)}
4+
*/
5+
</#if> ${pojo.getFieldModifiers(field)} ${pojo.getJavaTypeName(field, jdk5)} ${c2j.keyWordCheck(field.name)}<#if pojo.hasFieldInitializor(field, jdk5)> = ${pojo.getFieldInitialization(field, jdk5)}</#if>;
6+
</#if>
7+
</#list>
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import java.io.*;
2+
3+
File file = new File(basedir, "target/generated-sources/Person.hbm.xml");
4+
if (!file.isFile()) {
5+
throw new FileNotFoundException("Could not find generated HBM file: " + file);
6+
}

0 commit comments

Comments
 (0)