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
This commit is contained in:
Emmanuel Bernard 2010-06-02 13:17:23 +00:00
parent 5af328cb4a
commit 41bb177619
2 changed files with 19 additions and 7 deletions

View File

@ -324,7 +324,7 @@ public class Ejb3Configuration implements Serializable, Referenceable {
Scanner scanner = null; Scanner scanner = null;
URL jarURL = null; URL jarURL = null;
if ( metadata.getName() == null ) { if ( metadata.getName() == null ) {
scanner = buildScanner( metadata.getProps() ); scanner = buildScanner( metadata.getProps(), integration );
jarURL = JarVisitorFactory.getJarURLFromURLEntry( url, "/META-INF/persistence.xml" ); jarURL = JarVisitorFactory.getJarURLFromURLEntry( url, "/META-INF/persistence.xml" );
metadata.setName( scanner.getUnqualifiedJarName(jarURL) ); metadata.setName( scanner.getUnqualifiedJarName(jarURL) );
} }
@ -333,7 +333,7 @@ public class Ejb3Configuration implements Serializable, Referenceable {
} }
else if ( persistenceUnitName == null || metadata.getName().equals( persistenceUnitName ) ) { else if ( persistenceUnitName == null || metadata.getName().equals( persistenceUnitName ) ) {
if (scanner == null) { if (scanner == null) {
scanner = buildScanner( metadata.getProps() ); scanner = buildScanner( metadata.getProps(), integration );
jarURL = JarVisitorFactory.getJarURLFromURLEntry( url, "/META-INF/persistence.xml" ); jarURL = JarVisitorFactory.getJarURLFromURLEntry( url, "/META-INF/persistence.xml" );
} }
//scan main JAR //scan main JAR
@ -373,8 +373,12 @@ public class Ejb3Configuration implements Serializable, Referenceable {
} }
} }
private Scanner buildScanner(Properties properties) { private Scanner buildScanner(Properties properties, Map<?,?> integration) {
final Object scanner = properties.getProperty( AvailableSettings.SCANNER ); //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) { if (scanner != null) {
Class<?> scannerClass; Class<?> scannerClass;
if ( scanner instanceof String ) { if ( scanner instanceof String ) {
@ -565,7 +569,7 @@ public class Ejb3Configuration implements Serializable, Referenceable {
ScanningContext context = new ScanningContext(); ScanningContext context = new ScanningContext();
final Properties copyOfProperties = (Properties) info.getProperties().clone(); final Properties copyOfProperties = (Properties) info.getProperties().clone();
ConfigurationHelper.overrideProperties( copyOfProperties, integration ); ConfigurationHelper.overrideProperties( copyOfProperties, integration );
context.scanner( buildScanner( copyOfProperties ) ) context.scanner( buildScanner( copyOfProperties, integration ) )
.searchOrm( searchForORMFiles ) .searchOrm( searchForORMFiles )
.explicitMappingFiles( null ); //URLs provided by the container already .explicitMappingFiles( null ); //URLs provided by the container already

View File

@ -35,6 +35,7 @@ import javax.persistence.EntityManagerFactory;
import javax.persistence.MappedSuperclass; import javax.persistence.MappedSuperclass;
import javax.persistence.Persistence; import javax.persistence.Persistence;
import org.hibernate.ejb.AvailableSettings;
import org.hibernate.ejb.packaging.NamedInputStream; import org.hibernate.ejb.packaging.NamedInputStream;
import org.hibernate.ejb.packaging.NativeScanner; import org.hibernate.ejb.packaging.NativeScanner;
import org.hibernate.ejb.packaging.Scanner; import org.hibernate.ejb.packaging.Scanner;
@ -82,12 +83,19 @@ public class ScannerTest extends PackagingTestCase {
EntityManagerFactory emf; EntityManagerFactory emf;
CustomScanner.resetUsed(); CustomScanner.resetUsed();
emf = Persistence.createEntityManagerFactory( "defaultpar", new HashMap() ); final HashMap integration = new HashMap();
emf = Persistence.createEntityManagerFactory( "defaultpar", integration );
assertTrue( ! CustomScanner.isUsed() ); assertTrue( ! CustomScanner.isUsed() );
emf.close(); emf.close();
CustomScanner.resetUsed(); 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() ); assertTrue( CustomScanner.isUsed() );
emf.close(); emf.close();
} }