01: package org.andromda.maven.plugin.andromdapp.hibernate;
02:
03: import java.io.File;
04: import java.net.MalformedURLException;
05: import java.net.URL;
06: import java.net.URLClassLoader;
07: import java.util.List;
08: import java.util.Map;
09: import java.util.Random;
10:
11: import org.andromda.core.common.Constants;
12: import org.andromda.core.common.ResourceWriter;
13: import org.apache.maven.artifact.DependencyResolutionRequiredException;
14:
15: /**
16: * Provides the ability to create a schema from Hibernate
17: * mapping files.
18: *
19: * @author Chad Brandon
20: */
21: public class HibernateUpdateSchema extends HibernateSchemaManagement {
22: /**
23: * The temporary directory.
24: */
25: private static final String HIBERNATE_PROPERTIES_TEMP_DIRECTORY = Constants.TEMPORARY_DIRECTORY
26: + "andromdapp/hibernate-schema-update";
27:
28: /**
29: * @see org.andromda.maven.plugin.andromdapp.hibernate.HibernateSchemaManagement#addArguments(java.util.Map, java.util.List)
30: */
31: protected void addArguments(final Map options, final List arguments)
32: throws Exception {
33: final String driverClass = this .getRequiredProperty(options,
34: "jdbcDriver");
35: final String connectionUrl = this .getRequiredProperty(options,
36: "jdbcConnectionUrl");
37: final String username = this .getRequiredProperty(options,
38: "jdbcUsername");
39: final String password = this .getRequiredProperty(options,
40: "jdbcPassword");
41: final StringBuffer contents = new StringBuffer();
42: contents.append("hibernate.connection.driver_class="
43: + driverClass + "\n");
44: contents.append("hibernate.connection.url=" + connectionUrl
45: + "\n");
46: contents.append("hibernate.connection.username=" + username
47: + "\n");
48: contents.append("hibernate.connection.password=" + password
49: + "\n");
50: final File temporaryProperitesFile = new File(
51: HIBERNATE_PROPERTIES_TEMP_DIRECTORY, new Random()
52: .nextDouble()
53: + "");
54: temporaryProperitesFile.deleteOnExit();
55: ResourceWriter.instance()
56: .writeStringToFile(contents.toString(),
57: temporaryProperitesFile.toString());
58: arguments.add("--properties=" + temporaryProperitesFile);
59: }
60:
61: /**
62: * The class loader containing the jdbc driver.
63: */
64: private ClassLoader jdbcDriverJarLoader = null;
65:
66: /**
67: * Sets the current context class loader from the given
68: * <code>jdbcDriverJar</code>
69: *
70: * @throws DependencyResolutionRequiredException
71: * @throws MalformedURLException
72: */
73: protected ClassLoader getJdbcDriverJarLoader(final Map options)
74: throws MalformedURLException {
75: final String jdbcDriverJar = this .getRequiredProperty(options,
76: "jdbcDriverJar");
77: if (jdbcDriverJarLoader == null) {
78: jdbcDriverJarLoader = new URLClassLoader(
79: new URL[] { new File(jdbcDriverJar).toURL() });
80: }
81: return jdbcDriverJarLoader;
82: }
83:
84: /**
85: * @see org.andromda.maven.plugin.andromdapp.hibernate.HibernateSchemaManagement#getExecutionOuputPath(java.util.Map)
86: */
87: protected String getExecutionOuputPath(final Map options) {
88: return null;
89: }
90:
91: /**
92: * @see org.andromda.maven.plugin.andromdapp.hibernate.HibernateSchemaManagement#getExecutionClassName()
93: */
94: protected String getExecutionClassName() {
95: return "SchemaUpdate";
96: }
97: }
|