From: Kai Moritz Date: Sat, 16 May 2015 09:04:36 +0000 (+0200) Subject: JPA-jdbc-properties are used, if appropriate hibernate-properties are missing X-Git-Tag: hibernate4-maven-plugin-1.1.0~5 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=7e3e9b90d61b077e48b59fc0eb63059886c68cf5;p=hibernate-maven-plugin JPA-jdbc-properties are used, if appropriate hibernate-properties are missing --- diff --git a/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java b/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java index 48fd5683..f8c06344 100644 --- a/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java +++ b/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java @@ -97,6 +97,11 @@ public class Hbm2DdlMojo extends AbstractMojo public final static String NAMING_STRATEGY="hibernate.ejb.naming_strategy"; public final static String ENVERS = "hibernate.export.envers"; + public final static String JPA_DRIVER = "javax.persistence.jdbc.driver"; + public final static String JPA_URL = "javax.persistence.jdbc.url"; + public final static String JPA_USERNAME = "javax.persistence.jdbc.user"; + public final static String JPA_PASSWORD = "javax.persistence.jdbc.password"; + public final static String MD5S = "hibernate4-generatedschema.md5s"; private final static Pattern split = Pattern.compile("[^,\\s]+"); @@ -661,7 +666,9 @@ public class Hbm2DdlMojo extends AbstractMojo if (persistenceUnitDescriptor != null) config.setProperties(persistenceUnitDescriptor.getProperties()); + /** Overwrite values from properties-file or set, if given */ + if (driverClassName != null) { if (config.getProperties().containsKey(DRIVER_CLASS)) @@ -674,6 +681,21 @@ public class Hbm2DdlMojo extends AbstractMojo getLog().debug("Using the value " + driverClassName); config.setProperty(DRIVER_CLASS, driverClassName); } + if (config.getProperty(DRIVER_CLASS) == null) + { + String driver = config.getProperty(JPA_DRIVER); + if (driver != null) + { + getLog().info( + DRIVER_CLASS + + " is not set. Borrow setting from " + + JPA_DRIVER + + ": " + + driver); + config.setProperty(DRIVER_CLASS, driver); + } + } + if (url != null) { if (config.getProperties().containsKey(URL)) @@ -686,6 +708,21 @@ public class Hbm2DdlMojo extends AbstractMojo getLog().debug("Using the value " + url); config.setProperty(URL, url); } + if (config.getProperty(URL) == null) + { + String url = config.getProperty(JPA_URL); + if (url != null) + { + getLog().info( + URL + + " is not set. Borrow setting from " + + JPA_URL + + ": " + + url); + config.setProperty(URL, url); + } + } + if (username != null) { if (config.getProperties().containsKey(USERNAME)) @@ -698,6 +735,21 @@ public class Hbm2DdlMojo extends AbstractMojo getLog().debug("Using the value " + username); config.setProperty(USERNAME, username); } + if (config.getProperty(USERNAME) == null) + { + String username = config.getProperty(JPA_USERNAME); + if (username != null) + { + getLog().info( + USERNAME + + " is not set. Borrow setting from " + + JPA_USERNAME + + ": " + + username); + config.setProperty(USERNAME, username); + } + } + if (password != null) { if (config.getProperties().containsKey(PASSWORD)) @@ -710,6 +762,21 @@ public class Hbm2DdlMojo extends AbstractMojo getLog().debug("Using value " + password + " for property " + PASSWORD); config.setProperty(PASSWORD, password); } + if (config.getProperty(PASSWORD) == null) + { + String password = config.getProperty(JPA_PASSWORD); + if (password != null) + { + getLog().info( + PASSWORD + + " is not set. Borrow setting from " + + JPA_PASSWORD + + ": " + + password); + config.setProperty(PASSWORD, password); + } + } + if (hibernateDialect != null) { if (config.getProperties().containsKey(DIALECT)) @@ -724,6 +791,7 @@ public class Hbm2DdlMojo extends AbstractMojo ); config.setProperty(DIALECT, hibernateDialect); } + if ( hibernateNamingStrategy != null ) { if ( config.getProperties().contains(NAMING_STRATEGY))