1 package org
.argeo
.slc
.hibernate
.unit
;
3 import java
.sql
.Connection
;
5 import java
.util
.Properties
;
7 import org
.hibernate
.cfg
.Configuration
;
8 import org
.hibernate
.cfg
.Environment
;
9 import org
.hibernate
.tool
.hbm2ddl
.SchemaExport
;
12 * Creates a relational data model from Hibernate mapping files. The benefit of
13 * this class is to be able to use Hibernate to have test data which are
14 * independent from the type of database used.
16 public class DbModel
{
17 private String dialect
;
18 private List
<String
> mappings
;
20 /** Sets the Hibernate dialect to use. */
21 public void setDialect(String dialect
) {
22 this.dialect
= dialect
;
25 /** Sets the list of mappings to consider. */
26 public void setMappings(List
<String
> mappings
) {
27 this.mappings
= mappings
;
31 * Creates an Hibernate schema export tool, in order to create the
32 * underlying datamodel.
34 public SchemaExport
createSchemaExport(Connection connection
) {
35 Configuration configuration
= new Configuration();
36 Properties properties
= new Properties();
37 properties
.setProperty(Environment
.DIALECT
, dialect
);
38 properties
.setProperty(Environment
.HBM2DDL_AUTO
, "create");
39 configuration
.setProperties(properties
);
41 for (String mapping
: mappings
) {
42 configuration
.addResource(mapping
.trim());
45 return new SchemaExport(configuration
, connection
);