Author: epbernard Date: 2006-04-26 02:24:20 -0400 (Wed, 26 Apr 2006) New Revision: 9794 Added: trunk/HibernateExt/ejb/src/test-resources/defaultpar/META-INF/orm.xml trunk/HibernateExt/ejb/src/test-resources/explicitpar/orm2.xml trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/pack/defaultpar/Lighter.java trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/xml/ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/xml/Light.java trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/xml/XmlTest.java trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/xml/orm.xml trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/xml/orm2.xml Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/HibernatePersistence.java trunk/HibernateExt/ejb/src/resources/org/hibernate/ejb/persistence_1_0.xsd trunk/HibernateExt/ejb/src/test-resources/defaultpar/META-INF/persistence.xml trunk/HibernateExt/ejb/src/test-resources/explicitpar/META-INF/persistence.xml trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/PackagedEntityManagerTest.java trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/connection/DataSourceInjectionTest.java trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/connection/PersistenceUnitInfoImpl.java trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/packaging/JarVisitorTest.java Log: EJB-164 Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java =================================================================== --- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java 2006-04-26 06:20:18 UTC (rev 9793) +++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java 2006-04-26 06:24:20 UTC (rev 9794) @@ -104,7 +104,6 @@ private EntityManagerFactory createFactory(PersistenceMetadata metadata, Map overrides) { log.debug( "Creating Factory: " + metadata.getName() ); - if ( metadata.getMappingFiles().size() > 0 ) throw new RuntimeException( "<mapping-file not supported yet" ); if ( StringHelper.isNotEmpty( metadata.getJtaDatasource() ) ) { this.setProperty( Environment.DATASOURCE, metadata.getJtaDatasource() ); } @@ -121,6 +120,9 @@ if ( metadata.getPackages().size() > 0 ) { workingVars.put( HibernatePersistence.PACKAGE_NAMES, metadata.getPackages() ); } + if ( metadata.getMappingFiles().size() > 0 ) { + workingVars.put( HibernatePersistence.XML_FILE_NAMES, metadata.getMappingFiles() ); + } if ( metadata.getHbmfiles().size() > 0 ) { workingVars.put( HibernatePersistence.HBXML_FILES, metadata.getHbmfiles() ); } @@ -254,6 +256,8 @@ if ( info.getManagedClassNames() != null ) entities.addAll( info.getManagedClassNames() ); List<InputStream> hbmFiles = new ArrayList<InputStream>(); List<String> packages = new ArrayList<String>(); + List<String> xmlFiles = new ArrayList<String>( 50 ); + if ( info.getMappingFileNames() != null ) xmlFiles.addAll( info.getMappingFileNames() ); // Object overridenTxType = integration.get( HibernatePersistence.TRANSACTION_TYPE ); // if (overridenTxType != null) { // defineTransactionType( overridenTxType, info.getPersistenceUnitName() ); @@ -284,6 +288,7 @@ workingVars.put( HibernatePersistence.CLASS_NAMES, entities ); workingVars.put( HibernatePersistence.PACKAGE_NAMES, packages ); + workingVars.put( HibernatePersistence.XML_FILE_NAMES, xmlFiles ); if ( hbmFiles.size() > 0 ) workingVars.put( HibernatePersistence.HBXML_FILES, hbmFiles ); //datasources @@ -366,7 +371,7 @@ private JarVisitor.Filter[] getFilters(Properties properties, Map overridenProperties) { boolean[] result = getDetectedArtifacts( properties, overridenProperties ); - int size = ( result[0] ? 2 : 0 ) + ( result[1] ? 1 : 0 ); + int size = ( result[0] ? 2 : 0 ) + 1; //( result[1] ? 1 : 0 ); JarVisitor.Filter[] filters = new JarVisitor.Filter[size]; if ( result[0] ) { filters[0] = new JarVisitor.PackageFilter( false, null ) { @@ -388,10 +393,17 @@ if ( result[1] ) { filters[size - 1] = new JarVisitor.FileFilter( true ) { public boolean accept(String javaElementName) { - return javaElementName.endsWith( "hbm.xml" ); + return javaElementName.endsWith( "hbm.xml" ) || javaElementName.endsWith("META-INF/orm.xml"); } }; } + else { + filters[size - 1] = new JarVisitor.FileFilter( true ) { + public boolean accept(String javaElementName) { + return javaElementName.endsWith( "META-INF/orm.xml" ); + } + }; + } return filters; } @@ -651,10 +663,17 @@ HibernatePersistence.PACKAGE_NAMES ); for ( String pkg : packages ) { - //FIXME classloader cfg.addPackage( pkg ); } } + if ( workingVars.containsKey( HibernatePersistence.XML_FILE_NAMES ) ) { + Collection<String> xmlFiles = (Collection<String>) workingVars.get( + HibernatePersistence.XML_FILE_NAMES + ); + for ( String xmlFile : xmlFiles ) { + cfg.addResource( xmlFile ); + } + } if ( workingVars.containsKey( HibernatePersistence.HBXML_FILES ) ) { Collection<InputStream> hbmXmlFiles = (Collection<InputStream>) workingVars.get( HibernatePersistence.HBXML_FILES @@ -927,4 +946,19 @@ //TODO make it really read only (maybe through proxying) return cfg; } + + public Ejb3Configuration addInputStream(InputStream xmlInputStream) throws MappingException { + cfg.addInputStream( xmlInputStream ); + return this; + } + + public Ejb3Configuration addResource(String path) throws MappingException { + cfg.addResource( path ); + return this; + } + + public Ejb3Configuration addResource(String path, ClassLoader classLoader) throws MappingException { + cfg.addResource( path, classLoader ); + return this; + } } Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/HibernatePersistence.java =================================================================== --- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/HibernatePersistence.java 2006-04-26 06:20:18 UTC (rev 9793) +++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/HibernatePersistence.java 2006-04-26 06:24:20 UTC (rev 9794) @@ -35,7 +35,7 @@ public static final String AUTODETECTION = "hibernate.archive.autodetection"; /** * List of classes names - * Don't use it + * Internal use only */ public static final String CLASS_NAMES = "hibernate.ejb.classes"; /** @@ -44,6 +44,11 @@ */ public static final String PACKAGE_NAMES = "hibernate.ejb.packages"; /** + * List of classes names + * Internal use only + */ + public static final String XML_FILE_NAMES = "hibernate.ejb.xml_files"; + /** * cfg.xml configuration file used */ public static final String CFG_FILE = "hibernate.ejb.cfgfile"; @@ -95,7 +100,6 @@ public static final String PERSISTENCE_UNIT_NAME = "hibernate.ejb.persistenceUnitName"; - /** * Get an entity manager factory by its entity manager name and given the * appropriate extra properties. Those proeprties override the one get through Modified: trunk/HibernateExt/ejb/src/resources/org/hibernate/ejb/persistence_1_0.xsd =================================================================== --- trunk/HibernateExt/ejb/src/resources/org/hibernate/ejb/persistence_1_0.xsd 2006-04-26 06:20:18 UTC (rev 9793) +++ trunk/HibernateExt/ejb/src/resources/org/hibernate/ejb/persistence_1_0.xsd 2006-04-26 06:24:20 UTC (rev 9794) @@ -1,195 +1,260 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- persistence.xml schema --> -<xsd:schema targetNamespace="http://java.sun.com/xml/ns/persistence" - xmlns:xsd="http://www.w3.org/2001/XMLSchema" - xmlns:persistence="http://java.sun.com/xml/ns/persistence" - elementFormDefault="qualified" - attributeFormDefault="unqualified" - version="1.0"> +<xsd:schema targetNamespace="http://java.sun.com/xml/ns/persistence" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns:persistence="http://java.sun.com/xml/ns/persistence" + elementFormDefault="qualified" + attributeFormDefault="unqualified" + version="1.0"> + + <xsd:annotation> + <xsd:documentation> + @(#)persistence_1_0.xsd 1.0 Feb 9 2006 + </xsd:documentation> + </xsd:annotation> + <xsd:annotation> + <xsd:documentation><![CDATA[ + + This is the XML Schema for the persistence configuration file. + The file must be named "META-INF/persistence.xml" in the + persistence archive. + Persistence configuration files must indicate + the persistence schema by using the persistence namespace: + + http://java.sun.com/xml/ns/persistence + + and indicate the version of the schema by + using the version element as shown below: + + <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> + + ]]></xsd:documentation> + </xsd:annotation> + + <xsd:simpleType name="versionType"> + <xsd:restriction base="xsd:token"> + <xsd:pattern value="[0-9]+(\.[0-9]+)*"/> + </xsd:restriction> + </xsd:simpleType> + + <!-- **************************************************** --> + + <xsd:element name="persistence"> + <xsd:complexType> + <xsd:sequence> + + <!-- **************************************************** --> + + <xsd:element name="persistence-unit" + minOccurs="0" maxOccurs="unbounded"> + <xsd:complexType> + <xsd:annotation> + <xsd:documentation> + + Configuration of a persistence unit. + + </xsd:documentation> + </xsd:annotation> + <xsd:sequence> + + <!-- **************************************************** --> + + <xsd:element name="description" type="xsd:string" + minOccurs="0"> + <xsd:annotation> + <xsd:documentation> + + Textual description of this persistence unit. + + </xsd:documentation> + </xsd:annotation> + </xsd:element> + + <!-- **************************************************** --> + + <xsd:element name="provider" type="xsd:string" + minOccurs="0"> + <xsd:annotation> + <xsd:documentation> + + Provider class that supplies EntityManagers for this + persistence unit. + + </xsd:documentation> + </xsd:annotation> + </xsd:element> + + <!-- **************************************************** --> + + <xsd:element name="jta-data-source" type="xsd:string" + minOccurs="0"> + <xsd:annotation> + <xsd:documentation> + + The container-specific name of the JTA datasource to use. + + </xsd:documentation> + </xsd:annotation> + </xsd:element> + + <!-- **************************************************** --> + + <xsd:element name="non-jta-data-source" type="xsd:string" + minOccurs="0"> + <xsd:annotation> + <xsd:documentation> + + The container-specific name of a non-JTA datasource to use. + + </xsd:documentation> + </xsd:annotation> + </xsd:element> + + <!-- **************************************************** --> + + <xsd:element name="mapping-file" type="xsd:string" + minOccurs="0" maxOccurs="unbounded"> + <xsd:annotation> + <xsd:documentation> + + File containing mapping information. Loaded as a resource + by the persistence provider. + + </xsd:documentation> + </xsd:annotation> + </xsd:element> + + <!-- **************************************************** --> + + <xsd:element name="jar-file" type="xsd:string" + minOccurs="0" maxOccurs="unbounded"> + <xsd:annotation> + <xsd:documentation> + + Jar file that should be scanned for entities. + Not applicable to Java SE persistence units. + + </xsd:documentation> + </xsd:annotation> + </xsd:element> + + <!-- **************************************************** --> + + <xsd:element name="class" type="xsd:string" + minOccurs="0" maxOccurs="unbounded"> + <xsd:annotation> + <xsd:documentation> + + Class to scan for annotations. It should be annotated + with either @Entity, @Embeddable or @MappedSuperclass. + + </xsd:documentation> + </xsd:annotation> + </xsd:element> + + <!-- **************************************************** --> + + <xsd:element name="exclude-unlisted-classes" type="xsd:boolean" + default="false" minOccurs="0"> + <xsd:annotation> + <xsd:documentation> + + When set to true then only listed classes and jars will + be scanned for persistent classes, otherwise the enclosing + jar or directory will also be scanned. Not applicable to + Java SE persistence units. + + </xsd:documentation> + </xsd:annotation> + </xsd:element> + + <!-- **************************************************** --> + + <xsd:element name="properties" minOccurs="0"> + <xsd:annotation> + <xsd:documentation> + + A list of vendor-specific properties. + + </xsd:documentation> + </xsd:annotation> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="property" + minOccurs="0" maxOccurs="unbounded"> + <xsd:annotation> + <xsd:documentation> + A name-value pair. + </xsd:documentation> + </xsd:annotation> + <xsd:complexType> + <xsd:attribute name="name" type="xsd:string" + use="required"/> + <xsd:attribute name="value" type="xsd:string" + use="required"/> + </xsd:complexType> + </xsd:element> + </xsd:sequence> + </xsd:complexType> + </xsd:element> + + </xsd:sequence> + + <!-- **************************************************** --> + + <xsd:attribute name="name" type="xsd:string" use="required"> + <xsd:annotation> + <xsd:documentation> + + Name used in code to reference this persistence unit. + + </xsd:documentation> + </xsd:annotation> + </xsd:attribute> + + <!-- **************************************************** --> + + <xsd:attribute name="transaction-type" + type="persistence:persistence-unit-transaction-type"> + <xsd:annotation> + <xsd:documentation> + + Type of transactions used by EntityManagers from this + persistence unit. + + </xsd:documentation> + </xsd:annotation> + </xsd:attribute> + + </xsd:complexType> + </xsd:element> + </xsd:sequence> + <xsd:attribute name="version" type="persistence:versionType" + fixed="1.0" use="required"/> + </xsd:complexType> + </xsd:element> + + <!-- **************************************************** --> + + <xsd:simpleType name="persistence-unit-transaction-type"> <xsd:annotation> - <xsd:documentation> - @(#)persistence_1_0.xsd 1.0 Feb 9 2006 - </xsd:documentation> + <xsd:documentation> + + public enum TransactionType { JTA, RESOURCE_LOCAL }; + + </xsd:documentation> </xsd:annotation> - <xsd:annotation> - <xsd:documentation><![CDATA[ -This is the XML Schema for the persistence configuration file. -The file must be named "META-INF/persistence.xml" in the -persistence archive. -Persistence configuration files must indicate -the persistence schema by using the persistence namespace: -http://java.sun.com/xml/ns/persistence -and indicate the version of the schema by -using the version element as shown below: -<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> -]]></xsd:documentation> - </xsd:annotation> - <xsd:simpleType name="versionType"> - <xsd:restriction base="xsd:token"> - <xsd:pattern value="[0-9]+(\.[0-9]+)*"/> - </xsd:restriction> - </xsd:simpleType> - <!-- **************************************************** --> - <xsd:element name="persistence"> - <xsd:complexType> - <xsd:sequence> - <!-- **************************************************** --> - <xsd:element name="persistence-unit" - minOccurs="0" maxOccurs="unbounded"> - <xsd:complexType> - <xsd:annotation> - <xsd:documentation> - Configuration of a persistence unit. - </xsd:documentation> - </xsd:annotation> - <xsd:sequence> - <!-- **************************************************** --> - <xsd:element name="description" type="xsd:string" - minOccurs="0"> - <xsd:annotation> - <xsd:documentation> - Textual description of this persistence unit. - </xsd:documentation> - </xsd:annotation> - </xsd:element> - <!-- **************************************************** --> - <xsd:element name="provider" type="xsd:string" - minOccurs="0"> - <xsd:annotation> - <xsd:documentation> - Provider class that supplies EntityManagers for this - persistence unit. - </xsd:documentation> - </xsd:annotation> - </xsd:element> - <!-- **************************************************** --> - <xsd:element name="jta-data-source" type="xsd:string" - minOccurs="0"> - <xsd:annotation> - <xsd:documentation> - The container-specific name of the JTA datasource to use. - </xsd:documentation> - </xsd:annotation> - </xsd:element> - <!-- **************************************************** --> - <xsd:element name="non-jta-data-source" type="xsd:string" - minOccurs="0"> - <xsd:annotation> - <xsd:documentation> - The container-specific name of a non-JTA datasource to use. - </xsd:documentation> - </xsd:annotation> - </xsd:element> - <!-- **************************************************** --> - <xsd:element name="mapping-file" type="xsd:string" - minOccurs="0" maxOccurs="unbounded"> - <xsd:annotation> - <xsd:documentation> - File containing mapping information. Loaded as a resource - by the persistence provider. - </xsd:documentation> - </xsd:annotation> - </xsd:element> - <!-- **************************************************** --> - <xsd:element name="jar-file" type="xsd:string" - minOccurs="0" maxOccurs="unbounded"> - <xsd:annotation> - <xsd:documentation> - Jar file that should be scanned for entities. - Not applicable to Java SE persistence units. - </xsd:documentation> - </xsd:annotation> - </xsd:element> - <!-- **************************************************** --> - <xsd:element name="class" type="xsd:string" - minOccurs="0" maxOccurs="unbounded"> - <xsd:annotation> - <xsd:documentation> - Class to scan for annotations. It should be annotated - with either @Entity, @Embeddable or @MappedSuperclass. - </xsd:documentation> - </xsd:annotation> - </xsd:element> - <!-- **************************************************** --> - <xsd:element name="exclude-unlisted-classes" type="xsd:boolean" - default="false" minOccurs="0"> - <xsd:annotation> - <xsd:documentation> - When set to true then only listed classes and jars will - be scanned for persistent classes, otherwise the enclosing - jar or directory will also be scanned. Not applicable to - Java SE persistence units. - </xsd:documentation> - </xsd:annotation> - </xsd:element> - <!-- **************************************************** --> - <xsd:element name="properties" minOccurs="0"> - <xsd:annotation> - <xsd:documentation> - A list of vendor-specific properties. - </xsd:documentation> - </xsd:annotation> - <xsd:complexType> - <xsd:sequence> - <xsd:element name="property" - minOccurs="0" maxOccurs="unbounded"> - <xsd:annotation> - <xsd:documentation> - A name-value pair. - </xsd:documentation> - </xsd:annotation> - <xsd:complexType> - <xsd:attribute name="name" type="xsd:string" - use="required"/> - <xsd:attribute name="value" type="xsd:string" - use="required"/> - </xsd:complexType> - </xsd:element> - </xsd:sequence> - </xsd:complexType> - </xsd:element> - </xsd:sequence> - <!-- **************************************************** --> - <xsd:attribute name="name" type="xsd:string" use="required"> - <xsd:annotation> - <xsd:documentation> - Name used in code to reference this persistence unit. - </xsd:documentation> - </xsd:annotation> - </xsd:attribute> - <!-- **************************************************** --> - <xsd:attribute name="transaction-type" - type="persistence:persistence-unit-transaction-type"> - <xsd:annotation> - <xsd:documentation> - Type of transactions used by EntityManagers from this - persistence unit. - </xsd:documentation> - </xsd:annotation> - </xsd:attribute> - </xsd:complexType> - </xsd:element> - </xsd:sequence> - <xsd:attribute name="version" type="persistence:versionType" - fixed="1.0" use="required"/> - </xsd:complexType> - </xsd:element> - <!-- **************************************************** --> - <xsd:simpleType name="persistence-unit-transaction-type"> - <xsd:annotation> - <xsd:documentation> - public enum TransactionType { JTA, RESOURCE_LOCAL }; - </xsd:documentation> - </xsd:annotation> - <xsd:restriction base="xsd:token"> - <xsd:enumeration value="JTA"/> - <xsd:enumeration value="RESOURCE_LOCAL"/> - </xsd:restriction> - </xsd:simpleType> -</xsd:schema> \ No newline at end of file + <xsd:restriction base="xsd:token"> + <xsd:enumeration value="JTA"/> + <xsd:enumeration value="RESOURCE_LOCAL"/> + </xsd:restriction> + </xsd:simpleType> + +</xsd:schema> + Modified: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/PackagedEntityManagerTest.java =================================================================== --- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/PackagedEntityManagerTest.java 2006-04-26 06:20:18 UTC (rev 9793) +++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/PackagedEntityManagerTest.java 2006-04-26 06:24:20 UTC (rev 9794) @@ -12,6 +12,7 @@ import org.hibernate.ejb.test.pack.defaultpar.ApplicationServer; import org.hibernate.ejb.test.pack.defaultpar.Mouse; import org.hibernate.ejb.test.pack.defaultpar.Version; +import org.hibernate.ejb.test.pack.defaultpar.Lighter; import org.hibernate.ejb.test.pack.excludehbmpar.Caipirinha; import org.hibernate.ejb.test.pack.explodedpar.Carpet; import org.hibernate.ejb.test.pack.explodedpar.Elephant; @@ -50,6 +51,12 @@ em.persist( as ); em.persist( mouse ); assertEquals( 1, em.createNamedQuery( "allMouse" ).getResultList().size() ); + Lighter lighter = new Lighter(); + lighter.name = "main"; + lighter.power = " 250 W"; + em.persist( lighter ); + em.flush(); + em.remove( lighter ); em.remove(mouse); assertNotNull( as.getId() ); em.remove(as); Modified: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/connection/DataSourceInjectionTest.java =================================================================== --- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/connection/DataSourceInjectionTest.java 2006-04-26 06:20:18 UTC (rev 9793) +++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/connection/DataSourceInjectionTest.java 2006-04-26 06:24:20 UTC (rev 9794) @@ -11,7 +11,7 @@ */ public class DataSourceInjectionTest extends TestCase { public void testDatasourceInjection() { - PersistenceUnitInfoImpl info = new PersistenceUnitInfoImpl(); + PersistenceUnitInfoImpl info = new PersistenceUnitInfoImpl( new String[] {} ); try { EntityManagerFactory emf = ( new HibernatePersistence() ).createContainerEntityManagerFactory( info, null ); fail("FakeDatasource should have been used"); Modified: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/connection/PersistenceUnitInfoImpl.java =================================================================== --- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/connection/PersistenceUnitInfoImpl.java 2006-04-26 06:20:18 UTC (rev 9793) +++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/connection/PersistenceUnitInfoImpl.java 2006-04-26 06:24:20 UTC (rev 9794) @@ -14,13 +14,23 @@ import org.hibernate.ejb.HibernatePersistence; import org.hibernate.ejb.test.Distributor; import org.hibernate.ejb.test.Item; +import org.hibernate.ejb.test.xml.Light; +import org.hibernate.ejb.test.xml.Lighter; /** * @author Emmanuel Bernard */ public class PersistenceUnitInfoImpl implements PersistenceUnitInfo { private Properties properties = new Properties(); + private List<String> mappingFiles; + public PersistenceUnitInfoImpl(String[] mappingFiles) { + this.mappingFiles = new ArrayList<String>(mappingFiles.length); + for(String mappingFile : mappingFiles) { + this.mappingFiles.add(mappingFile); + } + } + public String getPersistenceUnitName() { return "persistenceinfo"; } @@ -38,7 +48,7 @@ } public List<String> getMappingFileNames() { - return new ArrayList<String>(); + return mappingFiles; } public List<URL> getJarFileUrls() { @@ -49,6 +59,8 @@ List<String> classes = new ArrayList<String>(); classes.add( Item.class.getName() ); classes.add( Distributor.class.getName() ); + classes.add( Light.class.getName() ); + classes.add( Lighter.class.getName() ); return classes; } Added: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/pack/defaultpar/Lighter.java =================================================================== --- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/pack/defaultpar/Lighter.java 2006-04-26 06:20:18 UTC (rev 9793) +++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/pack/defaultpar/Lighter.java 2006-04-26 06:24:20 UTC (rev 9794) @@ -0,0 +1,10 @@ +//$Id: $ +package org.hibernate.ejb.test.pack.defaultpar; + +/** + * @author Emmanuel Bernard + */ +public class Lighter { + public String name; + public String power; +} Modified: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/packaging/JarVisitorTest.java =================================================================== --- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/packaging/JarVisitorTest.java 2006-04-26 06:20:18 UTC (rev 9793) +++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/packaging/JarVisitorTest.java 2006-04-26 06:24:20 UTC (rev 9794) @@ -5,6 +5,7 @@ import java.net.URL; import java.net.URLConnection; import java.io.IOException; +import java.io.InputStream; import javax.persistence.Embeddable; import javax.persistence.MappedSuperclass; import javax.persistence.Entity; @@ -51,6 +52,7 @@ entry = new JarVisitor.Entry(org.hibernate.ejb.test.pack.defaultpar.Version.class.getName(), null); assertTrue( entries.contains( entry ) ); assertNull( ( (JarVisitor.Entry) entries.iterator().next() ).getInputStream() ); + assertEquals( 2, jarVisitor.getMatchingEntries()[2].size() ); // Set<String> classes = jarVisitor.getClassNames(); // assertEquals( 3, classes.size() ); @@ -80,6 +82,44 @@ // assertTrue( classes.contains( Carpet.class.getName() ) ); } + public void testDuplicateFilterExplodedJar() throws Exception { + String jarFileName = "./build/testresources/explodedpar.par"; + //JarVisitor jarVisitor = new ExplodedJarVisitor( jarFileName, true, true ); + JarVisitor.Filter[] filters = getFilters(); + JarVisitor.Filter[] dupeFilters = new JarVisitor.Filter[filters.length * 2]; + int index = 0; + for (JarVisitor.Filter filter : filters) { + dupeFilters[index++] = filter; + } + filters = getFilters(); + for (JarVisitor.Filter filter : filters) { + dupeFilters[index++] = filter; + } + JarVisitor jarVisitor = new ExplodedJarVisitor( jarFileName, filters ); + assertEquals( "explodedpar", jarVisitor.getUnqualifiedJarName() ); + Set[] entries = jarVisitor.getMatchingEntries(); + assertEquals( 1, entries[1].size() ); + assertEquals( 1, entries[0].size() ); + assertEquals( 1, entries[2].size() ); + for (JarVisitor.Entry entry : (Set<JarVisitor.Entry>) entries[2]) { + InputStream is = entry.getInputStream(); + if (is != null) { + assertTrue( 0 < is.available() ); + is.close(); + } + } + for (JarVisitor.Entry entry : (Set<JarVisitor.Entry>) entries[5]) { + InputStream is = entry.getInputStream(); + if (is != null) { + assertTrue( 0 < is.available() ); + is.close(); + } + } + + JarVisitor.Entry entry = new JarVisitor.Entry(Carpet.class.getName(), null); + assertTrue( entries[1].contains( entry ) ); + } + private JarVisitor.Filter[] getFilters() { return new JarVisitor.Filter[] { new JarVisitor.PackageFilter(false, null) { @@ -97,7 +137,7 @@ }, new JarVisitor.FileFilter(true) { public boolean accept(String javaElementName) { - return javaElementName.endsWith( "hbm.xml" ); + return javaElementName.endsWith( "hbm.xml" ) || javaElementName.endsWith( "META-INF/orm.xml"); } } }; Added: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/xml/Light.java =================================================================== --- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/xml/Light.java 2006-04-26 06:20:18 UTC (rev 9793) +++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/xml/Light.java 2006-04-26 06:24:20 UTC (rev 9794) @@ -0,0 +1,10 @@ +//$Id: $ +package org.hibernate.ejb.test.xml; + +/** + * @author Emmanuel Bernard + */ +public class Light { + public String name; + public String power; +} Added: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/xml/XmlTest.java =================================================================== --- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/xml/XmlTest.java 2006-04-26 06:20:18 UTC (rev 9793) +++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/xml/XmlTest.java 2006-04-26 06:24:20 UTC (rev 9794) @@ -0,0 +1,27 @@ +//$Id: $ +package org.hibernate.ejb.test.xml; + +import javax.persistence.EntityManagerFactory; + +import org.hibernate.ejb.test.connection.PersistenceUnitInfoImpl; +import org.hibernate.ejb.test.connection.FakeDataSourceException; +import org.hibernate.ejb.HibernatePersistence; +import junit.framework.TestCase; + +/** + * @author Emmanuel Bernard + */ +public class XmlTest extends TestCase { + public void testPersistenceInfo() throws Exception { + PersistenceUnitInfoImpl info = new PersistenceUnitInfoImpl( new String[] { + "org/hibernate/ejb/test/xml/orm.xml", + "org/hibernate/ejb/test/xml/orm2.xml" + } ); + try { + EntityManagerFactory emf = ( new HibernatePersistence() ).createContainerEntityManagerFactory( info, null ); + fail("FakeDatasource should have been used"); + } catch (FakeDataSourceException fde) { + //success + } + } +} Added: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/xml/orm.xml =================================================================== --- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/xml/orm.xml 2006-04-26 06:20:18 UTC (rev 9793) +++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/xml/orm.xml 2006-04-26 06:24:20 UTC (rev 9794) @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd" + version="1.0" +> + <package>org.hibernate.ejb.test.xml</package> + <entity class="Light" metadata-complete="true" access="FIELD"> + <attributes> + <id name="name"> + <column name="fld_id"/> + </id> + <basic name="power"></basic> + </attributes> + </entity> +</entity-mappings> \ No newline at end of file Added: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/xml/orm2.xml =================================================================== --- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/xml/orm2.xml 2006-04-26 06:20:18 UTC (rev 9793) +++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/xml/orm2.xml 2006-04-26 06:24:20 UTC (rev 9794) @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd" + version="1.0" +> + <package>org.hibernate.ejb.test.pack.defaultpar</package> + <entity class="Lighter" access="FIELD" metadata-complete="true"> + <attributes> + <id name="name"> + <column name="fld_id"/> + </id> + <basic name="power"></basic> + </attributes> + </entity> +</entity-mappings> \ No newline at end of file Added: trunk/HibernateExt/ejb/src/test-resources/defaultpar/META-INF/orm.xml =================================================================== --- trunk/HibernateExt/ejb/src/test-resources/defaultpar/META-INF/orm.xml 2006-04-26 06:20:18 UTC (rev 9793) +++ trunk/HibernateExt/ejb/src/test-resources/defaultpar/META-INF/orm.xml 2006-04-26 06:24:20 UTC (rev 9794) @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd" + version="1.0" +> + <package>org.hibernate.ejb.test.pack.defaultpar</package> + <entity class="Lighter" access="FIELD" metadata-complete="true"> + <attributes> + <id name="name"> + <column name="fld_id"/> + </id> + <basic name="power"></basic> + </attributes> + </entity> +</entity-mappings> \ No newline at end of file Modified: trunk/HibernateExt/ejb/src/test-resources/defaultpar/META-INF/persistence.xml =================================================================== --- trunk/HibernateExt/ejb/src/test-resources/defaultpar/META-INF/persistence.xml 2006-04-26 06:20:18 UTC (rev 9793) +++ trunk/HibernateExt/ejb/src/test-resources/defaultpar/META-INF/persistence.xml 2006-04-26 06:24:20 UTC (rev 9794) @@ -5,6 +5,7 @@ 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="defaultpar" transaction-type="RESOURCE_LOCAL"> + <class>org.hibernate.ejb.test.pack.defaultpar.Lighter</class> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/> <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/> Modified: trunk/HibernateExt/ejb/src/test-resources/explicitpar/META-INF/persistence.xml =================================================================== --- trunk/HibernateExt/ejb/src/test-resources/explicitpar/META-INF/persistence.xml 2006-04-26 06:20:18 UTC (rev 9793) +++ trunk/HibernateExt/ejb/src/test-resources/explicitpar/META-INF/persistence.xml 2006-04-26 06:24:20 UTC (rev 9794) @@ -4,11 +4,13 @@ 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="manager1" transaction-type="RESOURCE_LOCAL"> + <mapping-file>orm2.xml</mapping-file> <jar-file>./build/testresources/externaljar.jar</jar-file> <class>org.hibernate.ejb.test.Cat</class> <class>org.hibernate.ejb.test.Distributor</class> <class>org.hibernate.ejb.test.Item</class> <class>org.hibernate.ejb.test</class> + <class>org.hibernate.ejb.test.xml.Light</class> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/> <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/> Added: trunk/HibernateExt/ejb/src/test-resources/explicitpar/orm2.xml =================================================================== --- trunk/HibernateExt/ejb/src/test-resources/explicitpar/orm2.xml 2006-04-26 06:20:18 UTC (rev 9793) +++ trunk/HibernateExt/ejb/src/test-resources/explicitpar/orm2.xml 2006-04-26 06:24:20 UTC (rev 9794) @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd" + version="1.0" +> + <package>org.hibernate.test.annotations.xml.ejb3</package> + <entity class="Light" access="FIELD" metadata-complete="true"> + <attributes> + <id name="name"> + <column name="fld_id"/> + </id> + <basic name="power"></basic> + </attributes> + </entity> +</entity-mappings> \ No newline at end of file |