From 41bb1776194fc41ffbb67091c8d5f710e64e8ed0 Mon Sep 17 00:00:00 2001 From: Emmanuel Bernard Date: Wed, 2 Jun 2010 13:17:23 +0000 Subject: [PATCH] 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. git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@19665 1b8cb986-b30d-0410-93ca-fae66ebed9b2 --- .../java/org/hibernate/ejb/Ejb3Configuration.java | 14 +++++++++----- .../hibernate/ejb/test/packaging/ScannerTest.java | 12 ++++++++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java b/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java index 645dff709a..615ab565b4 100644 --- a/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java +++ b/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java @@ -324,7 +324,7 @@ public class Ejb3Configuration implements Serializable, Referenceable { 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 @@ public class Ejb3Configuration implements Serializable, Referenceable { } 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 @@ public class Ejb3Configuration implements Serializable, Referenceable { } } - 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 @@ public class Ejb3Configuration implements Serializable, Referenceable { 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 diff --git a/entitymanager/src/test/java/org/hibernate/ejb/test/packaging/ScannerTest.java b/entitymanager/src/test/java/org/hibernate/ejb/test/packaging/ScannerTest.java index 3c5936e5f9..643d533fe5 100644 --- a/entitymanager/src/test/java/org/hibernate/ejb/test/packaging/ScannerTest.java +++ b/entitymanager/src/test/java/org/hibernate/ejb/test/packaging/ScannerTest.java @@ -35,6 +35,7 @@ import javax.persistence.EntityManagerFactory; 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,12 +83,19 @@ public class ScannerTest extends PackagingTestCase { 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(); }