001package org.andromda.maven.plugin.andromdapp.hibernate; 002 003import java.io.File; 004import java.util.List; 005import java.util.Map; 006import java.util.Random; 007import org.andromda.core.common.Constants; 008import org.andromda.core.common.ResourceWriter; 009 010/** 011 * Provides the ability to validate a schema from Hibernate 012 * mapping files. 013 * 014 * @author Wouter Zoons 015 */ 016public class HibernateValidateSchema 017 extends HibernateSchemaManagement 018{ 019 private static final String HIBERNATE_PROPERTIES_TEMP_DIRECTORY = 020 Constants.TEMPORARY_DIRECTORY + "andromdapp/hibernate-schema-validate"; 021 022 /** 023 * @see org.andromda.maven.plugin.andromdapp.hibernate.HibernateSchemaManagement#getExecutionClassName() 024 */ 025 protected String getExecutionClassName() 026 { 027 return "SchemaValidator"; 028 } 029 030 /** 031 * @see org.andromda.maven.plugin.andromdapp.hibernate.HibernateSchemaManagement#getExecutionOuputPath(java.util.Map) 032 */ 033 protected String getExecutionOuputPath(final Map options) 034 { 035 return null; 036 } 037 038 private static final Random random = new Random(); 039 /** 040 * @see org.andromda.maven.plugin.andromdapp.hibernate.HibernateSchemaManagement#addArguments(java.util.Map, java.util.List) 041 */ 042 protected void addArguments(final Map options, final List<String> arguments) throws Exception 043 { 044 final String driverClass = this.getRequiredProperty( 045 options, 046 "jdbcDriver"); 047 final String connectionUrl = this.getRequiredProperty( 048 options, 049 "jdbcConnectionUrl"); 050 final String username = this.getRequiredProperty( 051 options, 052 "jdbcUsername"); 053 final String password = this.getRequiredProperty( 054 options, 055 "jdbcPassword"); 056 final StringBuilder contents = new StringBuilder(); 057 contents.append("hibernate.connection.driver_class=").append(driverClass).append('\n'); 058 contents.append("hibernate.connection.url=").append(connectionUrl).append('\n'); 059 contents.append("hibernate.connection.username=").append(username).append('\n'); 060 contents.append("hibernate.connection.password=").append(password).append('\n'); 061 final File temporaryProperitesFile = 062 new File(HIBERNATE_PROPERTIES_TEMP_DIRECTORY, String.valueOf(random.nextDouble())); 063 temporaryProperitesFile.deleteOnExit(); 064 ResourceWriter.instance().writeStringToFile( 065 contents.toString(), 066 temporaryProperitesFile.toString()); 067 arguments.add("--properties=" + temporaryProperitesFile); 068 } 069}