01: package org.andromda.maven.plugin.andromdapp.hibernate;
02:
03: import org.andromda.core.common.ResourceWriter;
04: import org.andromda.core.common.Constants;
05:
06: import java.util.Map;
07: import java.util.List;
08: import java.util.Random;
09: import java.io.File;
10:
11: /**
12: * Provides the ability to validate a schema from Hibernate
13: * mapping files.
14: *
15: * @author Wouter Zoons
16: */
17: public class HibernateValidateSchema extends HibernateSchemaManagement {
18: private static final String HIBERNATE_PROPERTIES_TEMP_DIRECTORY = Constants.TEMPORARY_DIRECTORY
19: + "andromdapp/hibernate-schema-validate";
20:
21: /**
22: * @see org.andromda.maven.plugin.andromdapp.hibernate.HibernateSchemaManagement#getExecutionClassName()
23: */
24: protected String getExecutionClassName() {
25: return "SchemaValidator";
26: }
27:
28: /**
29: * @see org.andromda.maven.plugin.andromdapp.hibernate.HibernateSchemaManagement#getExecutionOuputPath(java.util.Map)
30: */
31: protected String getExecutionOuputPath(final Map options) {
32: return null;
33: }
34:
35: /**
36: * @see org.andromda.maven.plugin.andromdapp.hibernate.HibernateSchemaManagement#addArguments(java.util.Map, java.util.List)
37: */
38: protected void addArguments(final Map options, final List arguments)
39: throws Exception {
40: final String driverClass = this .getRequiredProperty(options,
41: "jdbcDriver");
42: final String connectionUrl = this .getRequiredProperty(options,
43: "jdbcConnectionUrl");
44: final String username = this .getRequiredProperty(options,
45: "jdbcUsername");
46: final String password = this .getRequiredProperty(options,
47: "jdbcPassword");
48: final StringBuffer contents = new StringBuffer();
49: contents.append("hibernate.connection.driver_class=").append(
50: driverClass).append("\n");
51: contents.append("hibernate.connection.url=").append(
52: connectionUrl).append("\n");
53: contents.append("hibernate.connection.username=").append(
54: username).append("\n");
55: contents.append("hibernate.connection.password=").append(
56: password).append("\n");
57: final File temporaryProperitesFile = new File(
58: HIBERNATE_PROPERTIES_TEMP_DIRECTORY, new Random()
59: .nextDouble()
60: + "");
61: temporaryProperitesFile.deleteOnExit();
62: ResourceWriter.instance()
63: .writeStringToFile(contents.toString(),
64: temporaryProperitesFile.toString());
65: arguments.add("--properties=" + temporaryProperitesFile);
66: }
67: }
|