Author: epbernard
Date: 2010-06-02 09:17:23 -0400 (Wed, 02 Jun 2010)
New Revision: 19665
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/packaging/ScannerTest.java
Log:
HHH-5286 Scanner instances can now be passed in the integration map
The Scanner builder was only considering the scanner key from the properties
not the integration map and hence never handled instances. Now fixed.
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java 2010-06-02
13:15:29 UTC (rev 19664)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java 2010-06-02
13:17:23 UTC (rev 19665)
@@ -324,7 +324,7 @@
Scanner scanner = null;
URL jarURL = null;
if ( metadata.getName() == null ) {
- scanner = buildScanner( metadata.getProps() );
+ scanner = buildScanner( metadata.getProps(), integration );
jarURL = JarVisitorFactory.getJarURLFromURLEntry( url,
"/META-INF/persistence.xml" );
metadata.setName( scanner.getUnqualifiedJarName(jarURL) );
}
@@ -333,7 +333,7 @@
}
else if ( persistenceUnitName == null || metadata.getName().equals(
persistenceUnitName ) ) {
if (scanner == null) {
- scanner = buildScanner( metadata.getProps() );
+ scanner = buildScanner( metadata.getProps(), integration );
jarURL = JarVisitorFactory.getJarURLFromURLEntry( url,
"/META-INF/persistence.xml" );
}
//scan main JAR
@@ -373,8 +373,12 @@
}
}
- private Scanner buildScanner(Properties properties) {
- final Object scanner = properties.getProperty( AvailableSettings.SCANNER );
+ private Scanner buildScanner(Properties properties, Map<?,?> integration) {
+ //read the String or Instance from the integration map first and use the properties as
a backup.
+ Object scanner = integration.get( AvailableSettings.SCANNER );
+ if (scanner == null) {
+ scanner = properties.getProperty( AvailableSettings.SCANNER );
+ }
if (scanner != null) {
Class<?> scannerClass;
if ( scanner instanceof String ) {
@@ -565,7 +569,7 @@
ScanningContext context = new ScanningContext();
final Properties copyOfProperties = (Properties) info.getProperties().clone();
ConfigurationHelper.overrideProperties( copyOfProperties, integration );
- context.scanner( buildScanner( copyOfProperties ) )
+ context.scanner( buildScanner( copyOfProperties, integration ) )
.searchOrm( searchForORMFiles )
.explicitMappingFiles( null ); //URLs provided by the container already
Modified:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/packaging/ScannerTest.java
===================================================================
---
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/packaging/ScannerTest.java 2010-06-02
13:15:29 UTC (rev 19664)
+++
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/packaging/ScannerTest.java 2010-06-02
13:17:23 UTC (rev 19665)
@@ -35,6 +35,7 @@
import javax.persistence.MappedSuperclass;
import javax.persistence.Persistence;
+import org.hibernate.ejb.AvailableSettings;
import org.hibernate.ejb.packaging.NamedInputStream;
import org.hibernate.ejb.packaging.NativeScanner;
import org.hibernate.ejb.packaging.Scanner;
@@ -82,13 +83,20 @@
EntityManagerFactory emf;
CustomScanner.resetUsed();
- emf = Persistence.createEntityManagerFactory( "defaultpar", new HashMap() );
+ final HashMap integration = new HashMap();
+ emf = Persistence.createEntityManagerFactory( "defaultpar", integration );
assertTrue( ! CustomScanner.isUsed() );
emf.close();
CustomScanner.resetUsed();
- emf = Persistence.createEntityManagerFactory( "manager1", new HashMap() );
+ emf = Persistence.createEntityManagerFactory( "manager1", integration );
assertTrue( CustomScanner.isUsed() );
emf.close();
+
+ CustomScanner.resetUsed();
+ integration.put( AvailableSettings.SCANNER, new CustomScanner() );
+ emf = Persistence.createEntityManagerFactory( "defaultpar", integration );
+ assertTrue( CustomScanner.isUsed() );
+ emf.close();
}
}