Author: max.andersen(a)jboss.com
Date: 2006-08-31 10:22:05 -0400 (Thu, 31 Aug 2006)
New Revision: 10387
Added:
trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/JPAConfigurationTask.java
Removed:
trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/EJB3ConfigurationTask.java
Modified:
trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HibernateToolTask.java
trunk/HibernateExt/tools/src/testsupport/anttest-build.xml
Log:
HBX-743 avoid creating a sessionfactory when doing ejb3configuration
HBX-744 rename ejb3configuration to jpaconfiguration
Deleted:
trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/EJB3ConfigurationTask.java
===================================================================
---
trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/EJB3ConfigurationTask.java 2006-08-31
13:46:39 UTC (rev 10386)
+++
trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/EJB3ConfigurationTask.java 2006-08-31
14:22:05 UTC (rev 10387)
@@ -1,62 +0,0 @@
-package org.hibernate.tool.ant;
-
-import java.io.File;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.tools.ant.BuildException;
-import org.hibernate.HibernateException;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.util.ReflectHelper;
-
-public class EJB3ConfigurationTask extends ConfigurationTask {
-
- public EJB3ConfigurationTask() {
- setDescription("EJB3 Configuration");
- }
-
- protected Configuration createConfiguration() {
- try {
- Map overrides = new HashMap();
- // set to avoid complain: "The chosen transaction strategy requires access to the
JTA TransactionManager "
- //overrides.put("javax.persistence.transactionType",
"RESOURCE_LOCAL");
-
- Class clazz =
ReflectHelper.classForName("org.hibernate.ejb.Ejb3Configuration",
EJB3ConfigurationTask.class);
- Object ejb3cfg = clazz.newInstance();
- Method method = clazz.getMethod("createEntityManagerFactory", new Class[] {
String.class, Map.class });
- method.invoke(ejb3cfg, new Object[] { null, overrides } );
-
- method = clazz.getMethod("getHibernateConfiguration", new Class[0]);
- return (Configuration) method.invoke(ejb3cfg, null);
- }
- catch(HibernateException he) {
- throw new BuildException(he);
- }
- catch(Throwable t) {
- throw new BuildException("Problems in creating a Ejb3Configuration. Have you
remembered to add it to the classpath ?",t);
- }
-
- }
-
- protected void doConfiguration(Configuration configuration) {
- }
-
- protected void validateParameters() throws BuildException {
-
- }
-
- public void setConfigurationFile(File configurationFile) {
- complain("configurationfile");
- }
-
- public void setEntityResolver(String entityResolverName) {
- complain("entityresolver");
- }
-
- private void complain(String param) {
- throw new BuildException("ejb3configuration currently only support autodiscovery
from META-INF/persistence.xml. Thus setting the " + param + " attribute is not
allowed");
- }
-
-
-}
Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HibernateToolTask.java
===================================================================
---
trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HibernateToolTask.java 2006-08-31
13:46:39 UTC (rev 10386)
+++
trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HibernateToolTask.java 2006-08-31
14:22:05 UTC (rev 10387)
@@ -60,12 +60,18 @@
return (AnnotationConfigurationTask) configurationTask;
}
- public EJB3ConfigurationTask createEjb3Configuration() {
+ public JPAConfigurationTask createEjb3Configuration() {
checkConfiguration();
- configurationTask = new EJB3ConfigurationTask();
- return (EJB3ConfigurationTask) configurationTask;
+ configurationTask = new JPAConfigurationTask();
+ return (JPAConfigurationTask) configurationTask;
}
+ public JPAConfigurationTask createJpaConfiguration() {
+ checkConfiguration();
+ configurationTask = new JPAConfigurationTask();
+ return (JPAConfigurationTask) configurationTask;
+ }
+
public ExporterTask createHbm2DDL() {
ExporterTask generator = new Hbm2DDLExporterTask(this);
generators.add(generator);
Added: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/JPAConfigurationTask.java
===================================================================
---
trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/JPAConfigurationTask.java 2006-08-31
13:46:39 UTC (rev 10386)
+++
trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/JPAConfigurationTask.java 2006-08-31
14:22:05 UTC (rev 10387)
@@ -0,0 +1,60 @@
+package org.hibernate.tool.ant;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tools.ant.BuildException;
+import org.hibernate.HibernateException;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.util.ReflectHelper;
+
+public class JPAConfigurationTask extends ConfigurationTask {
+
+ public JPAConfigurationTask() {
+ setDescription("JPA Configuration");
+ }
+
+ protected Configuration createConfiguration() {
+ try {
+ Map overrides = new HashMap();
+
+ Class clazz =
ReflectHelper.classForName("org.hibernate.ejb.Ejb3Configuration",
JPAConfigurationTask.class);
+ Object ejb3cfg = clazz.newInstance();
+ Method method = clazz.getMethod("configure", new Class[] { String.class,
Map.class });
+ method.invoke(ejb3cfg, new Object[] { null, overrides } );
+
+ method = clazz.getMethod("getHibernateConfiguration", new Class[0]);
+ return (Configuration) method.invoke(ejb3cfg, null);
+ }
+ catch(HibernateException he) {
+ throw new BuildException(he);
+ }
+ catch(Throwable t) {
+ throw new BuildException("Problems in creating a configuration for JPA. Have you
remembered to add hibernate EntityManager jars to the classpath ?",t);
+ }
+
+ }
+
+ protected void doConfiguration(Configuration configuration) {
+ }
+
+ protected void validateParameters() throws BuildException {
+
+ }
+
+ public void setConfigurationFile(File configurationFile) {
+ complain("configurationfile");
+ }
+
+ public void setEntityResolver(String entityResolverName) {
+ complain("entityresolver");
+ }
+
+ private void complain(String param) {
+ throw new BuildException("<" + getTaskName() + "> currently only
support autodiscovery from META-INF/persistence.xml. Thus setting the " + param +
" attribute is not allowed");
+ }
+
+
+}
Modified: trunk/HibernateExt/tools/src/testsupport/anttest-build.xml
===================================================================
--- trunk/HibernateExt/tools/src/testsupport/anttest-build.xml 2006-08-31 13:46:39 UTC
(rev 10386)
+++ trunk/HibernateExt/tools/src/testsupport/anttest-build.xml 2006-08-31 14:22:05 UTC
(rev 10387)
@@ -210,7 +210,7 @@
<copy file="ejb3test-hibernate.cfg.xml"
tofile="${build.dir}/ejb3/classes/ejb3test-hibernate.cfg.xml" />
<hibernatetool destdir="${build.dir}">
- <ejb3configuration />
+ <jpaconfiguration configurationfile="blah"/>
<classpath>
<path location="${build.dir}/ejb3/classes" />
</classpath>
Show replies by date