From: <hib...@li...> - 2006-03-29 16:07:28
|
Author: max...@jb... Date: 2006-03-29 11:07:12 -0500 (Wed, 29 Mar 2006) New Revision: 9716 Added: trunk/HibernateExt/tools/lib/testlibs/hibernate-entitymanager.jar trunk/HibernateExt/tools/lib/testlibs/javassist.jar trunk/HibernateExt/tools/lib/testlibs/jboss-archive-browsing.jar trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/EJB3ConfigurationTask.java trunk/HibernateExt/tools/src/testsupport/ejb3test-hibernate.cfg.xml trunk/HibernateExt/tools/src/testsupport/ejb3test-persistence.xml Log: HBX-632 Provide <ejb3configuration> support in Ant Added: trunk/HibernateExt/tools/lib/testlibs/hibernate-entitymanager.jar =================================================================== (Binary files differ) Property changes on: trunk/HibernateExt/tools/lib/testlibs/hibernate-entitymanager.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/HibernateExt/tools/lib/testlibs/javassist.jar =================================================================== (Binary files differ) Property changes on: trunk/HibernateExt/tools/lib/testlibs/javassist.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/HibernateExt/tools/lib/testlibs/jboss-archive-browsing.jar =================================================================== (Binary files differ) Property changes on: trunk/HibernateExt/tools/lib/testlibs/jboss-archive-browsing.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/EJB3ConfigurationTask.java =================================================================== --- trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/EJB3ConfigurationTask.java 2006-03-29 15:58:38 UTC (rev 9715) +++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/EJB3ConfigurationTask.java 2006-03-29 16:07:12 UTC (rev 9716) @@ -0,0 +1,62 @@ +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"); + } + + +} Added: trunk/HibernateExt/tools/src/testsupport/ejb3test-hibernate.cfg.xml =================================================================== --- trunk/HibernateExt/tools/src/testsupport/ejb3test-hibernate.cfg.xml 2006-03-29 15:58:38 UTC (rev 9715) +++ trunk/HibernateExt/tools/src/testsupport/ejb3test-hibernate.cfg.xml 2006-03-29 16:07:12 UTC (rev 9716) @@ -0,0 +1,9 @@ +<!DOCTYPE hibernate-configuration PUBLIC + "-//Hibernate/Hibernate Configuration DTD 3.0//EN" + "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> + +<hibernate-configuration> + <session-factory> + <property name="show_sql">true</property> + </session-factory> +</hibernate-configuration> \ No newline at end of file Added: trunk/HibernateExt/tools/src/testsupport/ejb3test-persistence.xml =================================================================== --- trunk/HibernateExt/tools/src/testsupport/ejb3test-persistence.xml 2006-03-29 15:58:38 UTC (rev 9715) +++ trunk/HibernateExt/tools/src/testsupport/ejb3test-persistence.xml 2006-03-29 16:07:12 UTC (rev 9716) @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- example of reference to a cfg.xml file --> +<persistence xmlns="http://java.sun.com/xml/ns/persistence" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" + version="1.0"> + <persistence-unit name="ejb3test" transaction-type="RESOURCE_LOCAL"> + <provider>org.hibernate.ejb.HibernatePersistence</provider> + <properties> + <property name="hibernate.ejb.cfgfile" value="/ejb3test-hibernate.cfg.xml"/> + <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/> + </properties> + </persistence-unit> +</persistence> \ No newline at end of file |