]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/hibernate/unit/DbModelHibernate.java
Remove unused class
[gpl/argeo-slc.git] / runtime / org.argeo.slc.unit / src / main / java / org / argeo / slc / hibernate / unit / DbModelHibernate.java
1 /*
2 * Copyright (C) 2007-2012 Mathieu Baudier
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.slc.hibernate.unit;
17
18 import java.sql.Connection;
19 import java.util.List;
20 import java.util.Properties;
21
22 import org.argeo.slc.support.deploy.db.DbModel;
23 import org.hibernate.cfg.Configuration;
24 import org.hibernate.cfg.Environment;
25 import org.hibernate.tool.hbm2ddl.SchemaExport;
26
27 /**
28 * Creates a relational data model from Hibernate mapping files. The benefit of
29 * this class is to be able to use Hibernate to have test data which are
30 * independent from the type of database used.
31 */
32 public class DbModelHibernate implements DbModel {
33 private String dialect;
34 private List<String> mappings;
35
36 /** Sets the Hibernate dialect to use. */
37 public void setDialect(String dialect) {
38 this.dialect = dialect;
39 }
40
41 /** Sets the list of mappings to consider. */
42 public void setMappings(List<String> mappings) {
43 this.mappings = mappings;
44 }
45
46 /**
47 * Creates an Hibernate schema export tool, in order to create the
48 * underlying datamodel.
49 */
50 protected SchemaExport createSchemaExport(Connection connection) {
51 Configuration configuration = new Configuration();
52 Properties properties = new Properties();
53 properties.setProperty(Environment.DIALECT, dialect);
54 properties.setProperty(Environment.HBM2DDL_AUTO, "create");
55 configuration.setProperties(properties);
56
57 for (String mapping : mappings) {
58 configuration.addResource(mapping.trim());
59 }
60
61 return new SchemaExport(configuration, connection);
62 }
63
64 public void createSchema(Connection connection) {
65 SchemaExport schemaExport = createSchemaExport(connection);
66 schemaExport.create(true, true);
67 }
68
69 }