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:
parent
5af328cb4a
commit
41bb177619
|
@ -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
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue